From cd98a29a4bae02b6b733db290cb76070bae61439 Mon Sep 17 00:00:00 2001 From: John Poole Date: Mon, 23 Apr 2012 16:00:07 -0700 Subject: [PATCH] Fix 32-bit samples on Mac OS X. On Mac OS X and Linux rdtsc() didn't save and restore 32-bit registers. This patch fixes issue #87. --- examples/timing.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/timing.h b/examples/timing.h index f61fbce8..7d746d45 100644 --- a/examples/timing.h +++ b/examples/timing.h @@ -43,9 +43,15 @@ extern "C" { #endif /* __cplusplus */ __inline__ uint64_t rdtsc() { uint32_t low, high; +#ifdef __x86_64 __asm__ __volatile__ ( "xorl %%eax,%%eax \n cpuid" ::: "%rax", "%rbx", "%rcx", "%rdx" ); +#else + __asm__ __volatile__ ( + "xorl %%eax,%%eax \n cpuid" + ::: "%eax", "%ebx", "%ecx", "%edx" ); +#endif __asm__ __volatile__ ( "rdtsc" : "=a" (low), "=d" (high)); return (uint64_t)high << 32 | low;