churchyard / rpms / python2

Forked from rpms/python2 2 years ago
Clone
92ed49
diff -up Python-2.7.2/Python/ceval.c.tsc-on-ppc Python-2.7.2/Python/ceval.c
92ed49
--- Python-2.7.2/Python/ceval.c.tsc-on-ppc	2011-08-23 14:59:48.051300849 -0400
92ed49
+++ Python-2.7.2/Python/ceval.c	2011-08-23 15:33:25.412162902 -0400
92ed49
@@ -37,24 +37,42 @@ typedef unsigned long long uint64;
92ed49
 */
92ed49
 #if defined(__ppc__) || defined (__powerpc__)
92ed49
 
92ed49
-#define READ_TIMESTAMP(var) ppc_getcounter(&var)
92ed49
+#if defined( __powerpc64__) || defined(__LP64__)
92ed49
+/* 64-bit PowerPC */
92ed49
+#define READ_TIMESTAMP(var) ppc64_getcounter(&var)
92ed49
+static void
92ed49
+ppc64_getcounter(uint64 *v)
92ed49
+{
92ed49
+    /* On 64-bit PowerPC we can read the 64-bit timebase directly into a
92ed49
+       64-bit register */
92ed49
+    uint64 timebase;
92ed49
+#ifdef _ARCH_PWR4
92ed49
+    asm volatile ("mfspr %0,268" : "=r" (timebase));
92ed49
+#else
92ed49
+    asm volatile ("mftb %0" : "=r" (timebase));
92ed49
+#endif
92ed49
+    *v = timebase;
92ed49
+}
92ed49
+
92ed49
+#else
92ed49
+/* 32-bit PowerPC */
92ed49
+#define READ_TIMESTAMP(var) ppc32_getcounter(&var)
92ed49
 
92ed49
 static void
92ed49
-ppc_getcounter(uint64 *v)
92ed49
+ppc32_getcounter(uint64 *v)
92ed49
 {
92ed49
-    register unsigned long tbu, tb, tbu2;
92ed49
+    union { long long ll; long ii[2]; } u;
92ed49
+    long tmp;
92ed49
 
92ed49
   loop:
92ed49
-    asm volatile ("mftbu %0" : "=r" (tbu) );
92ed49
-    asm volatile ("mftb  %0" : "=r" (tb)  );
92ed49
-    asm volatile ("mftbu %0" : "=r" (tbu2));
92ed49
-    if (__builtin_expect(tbu != tbu2, 0)) goto loop;
92ed49
-
92ed49
-    /* The slightly peculiar way of writing the next lines is
92ed49
-       compiled better by GCC than any other way I tried. */
92ed49
-    ((long*)(v))[0] = tbu;
92ed49
-    ((long*)(v))[1] = tb;
92ed49
+    asm volatile ("mftbu %0" : "=r" (u.ii[0]) );
92ed49
+    asm volatile ("mftb  %0" : "=r" (u.ii[1]) );
92ed49
+    asm volatile ("mftbu %0" : "=r" (tmp));
92ed49
+    if (__builtin_expect(u.ii[0] != tmp, 0)) goto loop;
92ed49
+
92ed49
+    *v = u.ll;
92ed49
 }
92ed49
+#endif /* powerpc 32/64 bit */
92ed49
 
92ed49
 #elif defined(__i386__)
92ed49