torsava / rpms / python3

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