
9 Jun
2008
9 Jun
'08
7:31 p.m.
dherring@ll.mit.edu wrote:
The CPU timestamp counter is a high-resolution clock source useful for profiling code or controlling tight timing loops. AMD/Intel CPUs support this via the RDTSC opcode, and other CPUs often provide similar functionality.
Apparently MS compilers support an __rdtsc() intrinsic, but I couldn't find one for gcc.
MSVS 8.0 and higher have the __rdtsc intrinsic. Om earlier versions of MSVC you can use the following inline assembler: inline uint64_t clockCycleCount() { uint64_t ccc; __asm { cpuid // serialize processor rdtsc // read time stamp counter mov dword ptr [ccc + 0], eax mov dword ptr [ccc + 4], edx } return ccc; } I agree that a platform independent version would be useful. --Johan Råde