churchyard / rpms / python3

Forked from rpms/python3 3 years ago
Clone

Blame 00143-tsc-on-ppc.patch

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