21 #ifndef SRC_INCLUDE_SMASH_TSC_H_
22 #define SRC_INCLUDE_SMASH_TSC_H_
24 #ifndef USE_NANOBENCHMARKING_CODE
25 #error "Nanobenchmark code tried to be used without enabling it via CMake."
33 #pragma intrinsic(__rdtsc)
44 class TimeStampCounter {
53 uint64_t cycles()
const;
69 inline void TimeStampCounter::start() {
71 asm volatile(
"xor %%eax,%%eax\n\tcpuid\n\trdtsc"
72 :
"=a"(m_start.b[0]),
"=d"(m_start.b[1])::
"ebx",
"ecx");
73 #elif defined _MSC_VER
75 m_start.a = __rdtscp(&tmp);
77 asm volatile(
"rdtscp" :
"=a"(m_start.b[0]),
"=d"(m_start.b[1])::
"ecx");
81 inline void TimeStampCounter::stop() {
83 asm volatile(
"xor %%eax,%%eax\n\tcpuid\n\trdtsc"
84 :
"=a"(m_end.b[0]),
"=d"(m_end.b[1])::
"ebx",
"ecx");
85 #elif defined _MSC_VER
87 m_end.a = __rdtscp(&tmp);
89 asm volatile(
"rdtscp" :
"=a"(m_end.b[0]),
"=d"(m_end.b[1])::
"ecx");
93 inline uint64_t TimeStampCounter::cycles()
const {
return m_end.a - m_start.a; }
95 std::ostream &
operator<<(std::ostream &out,
const TimeStampCounter &tsc);
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.