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