[pypy-commit] pypy improve-rbigint: Add some jit hooks and remove the shift len check from int.h (because rbigint is the only place we use longlonglong, and probably ever gonna use it)

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


Author: stian
Branch: improve-rbigint
Changeset: r56340:89890e8a28a8
Date: 2012-06-27 05:17 +0200
http://bitbucket.org/pypy/pypy/changeset/89890e8a28a8/

Log:	Add some jit hooks and remove the shift len check from int.h
	(because rbigint is the only place we use longlonglong, and probably
	ever gonna use it)

diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -232,6 +232,7 @@
         return rbigint(*args_from_long(l))
 
     @staticmethod
+    @jit.elidable
     def fromfloat(dval):
         """ Create a new bigint object from a float """
         # This function is not marked as pure because it can raise
@@ -328,20 +329,25 @@
         """Return r_ulonglong(self), truncating."""
         return _AsULonglong_mask(self)
 
+    @jit.elidable
     def tofloat(self):
         return _AsDouble(self)
 
+    @jit.elidable
     def format(self, digits, prefix='', suffix=''):
         # 'digits' is a string whose length is the base to use,
         # and where each character is the corresponding digit.
         return _format(self, digits, prefix, suffix)
 
+    @jit.elidable
     def repr(self):
         return _format(self, BASE10, '', 'L')
 
+    @jit.elidable
     def str(self):
         return _format(self, BASE10)
 
+    @jit.elidable
     def eq(self, other):
         if (self.sign != other.sign or
             self.numdigits() != other.numdigits()):
@@ -401,9 +407,11 @@
     def ge(self, other):
         return not self.lt(other)
 
+    @jit.elidable
     def hash(self):
         return _hash(self)
 
+    @jit.elidable
     def add(self, other):
         if self.sign == 0:
             return other
@@ -416,6 +424,7 @@
         result.sign *= other.sign
         return result
 
+    @jit.elidable
     def sub(self, other):
         if other.sign == 0:
             return self
@@ -429,6 +438,7 @@
         result._normalize()
         return result
 
+    @jit.elidable
     def mul(self, b):
         asize = self.numdigits()
         bsize = b.numdigits()
@@ -477,11 +487,13 @@
 
         result.sign = a.sign * b.sign
         return result
-    
+
+    @jit.elidable
     def truediv(self, other):
         div = _bigint_true_divide(self, other)
         return div
 
+    @jit.elidable
     def floordiv(self, other):
         if other.numdigits() == 1 and other.sign == 1:
             digit = other.digit(0)
@@ -495,15 +507,18 @@
             div = div.sub(ONERBIGINT)
         return div
 
+    @jit.elidable
     def div(self, other):
         return self.floordiv(other)
 
+    @jit.elidable
     def mod(self, other):
         div, mod = _divrem(self, other)
         if mod.sign * other.sign == -1:
             mod = mod.add(other)
         return mod
 
+    @jit.elidable
     def divmod(v, w):
         """
         The / and % operators are now defined in terms of divmod().
@@ -527,6 +542,7 @@
             div = div.sub(ONERBIGINT)
         return div, mod
 
+    @jit.elidable
     def pow(a, b, c=None):
         negativeOutput = False  # if x<0 return negative output
 
@@ -663,6 +679,7 @@
     def invert(self): #Implement ~x as -(x + 1)
         return self.add(ONERBIGINT).neg()
 
+    @jit.elidable
     def lshift(self, int_other):
         if int_other < 0:
             raise ValueError("negative shift count")
@@ -696,6 +713,7 @@
         z._normalize()
         return z
 
+    @jit.elidable
     def lqshift(self, int_other):
         " A quicker one with much less checks, int_other is valid and for the most part constant."
         assert int_other > 0
@@ -714,6 +732,7 @@
         z._normalize()
         return z
     
+    @jit.elidable
     def rshift(self, int_other, dont_invert=False):
         if int_other < 0:
             raise ValueError("negative shift count")
@@ -747,12 +766,15 @@
         z._normalize()
         return z
 
+    @jit.elidable
     def and_(self, other):
         return _bitwise(self, '&', other)
 
+    @jit.elidable
     def xor(self, other):
         return _bitwise(self, '^', other)
 
+    @jit.elidable
     def or_(self, other):
         return _bitwise(self, '|', other)
 
@@ -765,6 +787,7 @@
     def hex(self):
         return _format(self, BASE16, '0x', 'L')
 
+    @jit.elidable
     def log(self, base):
         # base is supposed to be positive or 0.0, which means we use e
         if base == 10.0:
diff --git a/pypy/translator/c/src/int.h b/pypy/translator/c/src/int.h
--- a/pypy/translator/c/src/int.h
+++ b/pypy/translator/c/src/int.h
@@ -98,8 +98,7 @@
 						r = Py_ARITHMETIC_RIGHT_SHIFT(PY_LONG_LONG,x, (y))
 #define OP_ULLONG_RSHIFT(x,y,r) CHECK_SHIFT_RANGE(y, PYPY_LONGLONG_BIT); \
 						r = (x) >> (y)
-#define OP_LLLONG_RSHIFT(x,y,r)  CHECK_SHIFT_RANGE(y, PYPY_LONGLONGLONG_BIT); \
-                                                r = Py_ARITHMETIC_RIGHT_SHIFT(PY_LONG_LONG_LONG,x, (y))
+#define OP_LLLONG_RSHIFT(x,y,r)  r = Py_ARITHMETIC_RIGHT_SHIFT(PY_LONG_LONG_LONG,x, (y))
 
 #define OP_INT_LSHIFT(x,y,r)    CHECK_SHIFT_RANGE(y, PYPY_LONG_BIT); \
 							r = (x) << (y)
@@ -107,8 +106,7 @@
 							r = (x) << (y)
 #define OP_LLONG_LSHIFT(x,y,r)  CHECK_SHIFT_RANGE(y, PYPY_LONGLONG_BIT); \
 							r = (x) << (y)
-#define OP_LLLONG_LSHIFT(x,y,r)  CHECK_SHIFT_RANGE(y, PYPY_LONGLONGLONG_BIT); \
-                                                        r = (x) << (y)
+#define OP_LLLONG_LSHIFT(x,y,r)  r = (x) << (y)
 #define OP_ULLONG_LSHIFT(x,y,r) CHECK_SHIFT_RANGE(y, PYPY_LONGLONG_BIT); \
 							r = (x) << (y)
 


More information about the pypy-commit mailing list