[pypy-commit] pypy improve-rbigint: Special case invert of 0, and save one creation when inverting. This makes floordiv quicker

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


Author: stian
Branch: improve-rbigint
Changeset: r56351:1f3529e0e23b
Date: 2012-07-06 07:02 +0200
http://bitbucket.org/pypy/pypy/changeset/1f3529e0e23b/

Log:	Special case invert of 0, and save one creation when inverting. This
	makes floordiv quicker

diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -435,7 +435,6 @@
         else:
             result = _x_add(self, other)
         result.sign *= self.sign
-        result._normalize()
         return result
 
     @jit.elidable
@@ -684,10 +683,17 @@
         return rbigint(self._digits, -self.sign)
 
     def abs(self):
+        if self.sign != -1:
+            return self
         return rbigint(self._digits, abs(self.sign))
 
     def invert(self): #Implement ~x as -(x + 1)
-        return self.add(ONERBIGINT).neg()
+        if self.sign == 0:
+            return ONENEGATIVERBIGINT
+        
+        ret = self.add(ONERBIGINT)
+        ret.sign = -ret.sign
+        return ret
 
     @jit.elidable
     def lshift(self, int_other):
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
@@ -29,21 +29,21 @@
         Sum: 901.7231250000001
         
         Pypy with improvements:
-        2.892875
-        2.263349
-        2.425365
-        1.579653
-        4.005316
-        9.579625
-        1.774452
-        4.021076
-        4.844961
-        6.432300
-        0.038368
-        3.624531
-        8.156838
-        4.990594
-        Sum:  56.629303
+        2.887265
+        2.253981
+        2.480497
+        1.572440
+        3.941691
+        9.530685
+        1.786801
+        4.046154
+        4.844644
+        6.412511
+        0.038662
+        3.629173
+        8.155449
+        4.997199
+        Sum:  56.577152
 
         A pure python form of those tests where also run
         Improved pypy           | Pypy                  | CPython 2.7.3


More information about the pypy-commit mailing list