[cairo] Reading rdtsc on x86_64

M Joonas Pihlaja jpihlaja at cc.helsinki.fi
Thu Sep 11 11:10:15 PDT 2008


The oil_profile_stamp_rdtsc() function uses the =A mode to read
the 64 bit result of rdtsc on both x86 and x86_64.  This doesn't
work on x86_64 reliably as we want to be reading eax:edx, but
with =A we're reading a single 64 bit register instead.

I've been using the attached patch at home.  Someone look it


-------------- next part --------------
diff --git a/perf/cairo-perf-posix.c b/perf/cairo-perf-posix.c
index b1b1a2a..f7b8658 100644
--- a/perf/cairo-perf-posix.c
+++ b/perf/cairo-perf-posix.c
@@ -64,7 +64,7 @@
 /* timers */
-#if defined(__i386__) || defined(__amd64__)
+#if defined(__i386__)
 static inline cairo_perf_ticks_t
 oil_profile_stamp_rdtsc (void)
@@ -75,6 +75,17 @@ oil_profile_stamp_rdtsc (void)
 #define OIL_STAMP oil_profile_stamp_rdtsc
+#if defined(__amd64__)
+static inline cairo_perf_ticks_t
+oil_profile_stamp_rdtsc (void)
+    unsigned a, d; 
+    __asm__ __volatile__("rdtsc" : "=a" (a), "=d" (d)); 
+    return ((uint64_t)a) | (((uint64_t)d) << 32); 
+#define OIL_STAMP oil_profile_stamp_rdtsc
 #if defined(__powerpc__) || defined(__PPC__) || defined(__ppc__)
 static inline cairo_perf_ticks_t

More information about the cairo mailing list