churchyard / rpms / python2

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