32 #ifndef VSMC_UTILITY_RDTSC_HPP
33 #define VSMC_UTILITY_RDTSC_HPP
51 return static_cast<uint64_t
>(__rdtsc());
58 :
"=a" (eax),
"=d" (edx)
61 return (static_cast<uint64_t>(edx) << 32) + static_cast<uint64_t>(eax);
67 inline uint64_t
rdtscp (
unsigned *aux)
70 return static_cast<uint64_t
>(__rdtscp(aux));
78 :
"=a" (eax),
"=c" (ecx),
"=d" (edx)
82 return static_cast<uint64_t
>(eax) + (static_cast<uint64_t>(edx) << 32);
136 elapsed_ += stop - start_;
150 uint64_t
cycles ()
const {
return elapsed_;}
194 start_ =
rdtscp(&start_id_);
215 unsigned stop_id = 0;
217 if (stop_id != start_id_ || stop < start_)
220 elapsed_ += stop - start_;
234 uint64_t
cycles ()
const {
return elapsed_;}
246 #endif // VSMC_UTILITY_RDTSC_HPP
bool running() const
If the counter is running.
void reset()
Stop and reset the elapsed cycle count to zero.
bool running() const
If the counter is running.
CPU clock cycle counter using rdtsc
uint64_t cycles() const
Return the accumulated elapsed cycle count.
bool stop()
Stop the counter, no effect if already stopped.
bool start()
Start the counter, no effect if already started.
uint64_t rdtsc()
Return the TSC value using RDTSC instruction.
bool stop()
Stop the counter, no effect if already stopped.
uint64_t cycles() const
Return the accumulated elapsed cycle count.
bool start()
Start the counter, no effect if already started.
CPU clock cycle counter using rdtscp
uint64_t rdtscp(unsigned *aux)
Return the TSC and TSC_AUX values using RDTSCP instruction.
void reset()
Stop and reset the elapsed cycle count to zero.