[pypy-commit] pypy improve-rbigint: Power of two improvements?

stian noreply at buildbot.pypy.org
Sat Jul 21 18:41:09 CEST 2012


Author: stian
Branch: improve-rbigint
Changeset: r56323:255c21cf7d24
Date: 2012-06-24 07:49 +0200
http://bitbucket.org/pypy/pypy/changeset/255c21cf7d24/

Log:	Power of two improvements?

diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -484,7 +484,20 @@
                 a = temp
                 
         size_b = b.numdigits()
-            
+        
+        if not c and size_b == 1 and a.sign == 1:
+            digit = b.digit(0)
+            if digit == 0:
+                return rbigint([ONEDIGIT], 1)
+            elif digit == 1:
+                return a
+            elif a.numdigits() == 1:
+                adigit = a.digit(0)
+                if adigit == 1:
+                    return rbigint([ONEDIGIT], 1)
+                elif adigit == 2:
+                    return a.lshift(digit-1)
+                
         # At this point a, b, and c are guaranteed non-negative UNLESS
         # c is NULL, in which case a may be negative. */
 
diff --git a/pypy/translator/goal/targetbigintbenchmark.py b/pypy/translator/goal/targetbigintbenchmark.py
--- a/pypy/translator/goal/targetbigintbenchmark.py
+++ b/pypy/translator/goal/targetbigintbenchmark.py
@@ -19,6 +19,7 @@
         6.647562
 
         Pypy with improvements:
+        9.474363
         5.797121
         10.068798
         14.770187
@@ -28,6 +29,14 @@
         6.440351
 
     """
+    
+    t = time()
+    num = rbigint.fromint(10000000)
+    for n in xrange(10000):
+        rbigint.pow(rbigint.fromint(2), num)
+        
+
+    print time() - t
 
     t = time()
     num = rbigint.pow(rbigint.fromint(10000), rbigint.fromint(2 ** 8))


More information about the pypy-commit mailing list