[pypy-svn] pypy default: Merge the jit-longlong branch. Adds the type W_SmallLongObject,

arigo commits-noreply at bitbucket.org
Fri Jan 28 14:41:25 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r41429:e4a105a01214
Date: 2011-01-28 14:41 +0100
http://bitbucket.org/pypy/pypy/changeset/e4a105a01214/

Log:	Merge the jit-longlong branch. Adds the type W_SmallLongObject,
	which is an app-level 'long' implemented as a C 'long long'; and add
	some support in the jit for the SignedLongLong type. Only useful on
	32 bits.

diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py
--- a/pypy/rlib/test/test_rbigint.py
+++ b/pypy/rlib/test/test_rbigint.py
@@ -86,15 +86,18 @@
 
     def test_args_from_int(self):
         BASE = 1 << SHIFT
+        MAX = int(BASE-1)
         assert rbigint.fromrarith_int(0).eq(rbigint([0], 0))
         assert rbigint.fromrarith_int(17).eq(rbigint([17], 1))
-        assert rbigint.fromrarith_int(BASE-1).eq(rbigint([intmask(BASE-1)], 1))
-        assert rbigint.fromrarith_int(BASE).eq(rbigint([0, 1], 1))
-        assert rbigint.fromrarith_int(BASE**2).eq(rbigint([0, 0, 1], 1))
+        assert rbigint.fromrarith_int(MAX).eq(rbigint([MAX], 1))
+        assert rbigint.fromrarith_int(r_longlong(BASE)).eq(rbigint([0, 1], 1))
+        assert rbigint.fromrarith_int(r_longlong(BASE**2)).eq(
+            rbigint([0, 0, 1], 1))
         assert rbigint.fromrarith_int(-17).eq(rbigint([17], -1))
-        assert rbigint.fromrarith_int(-(BASE-1)).eq(rbigint([intmask(BASE-1)], -1))
-        assert rbigint.fromrarith_int(-BASE).eq(rbigint([0, 1], -1))
-        assert rbigint.fromrarith_int(-(BASE**2)).eq(rbigint([0, 0, 1], -1))
+        assert rbigint.fromrarith_int(-MAX).eq(rbigint([MAX], -1))
+        assert rbigint.fromrarith_int(-MAX-1).eq(rbigint([0, 1], -1))
+        assert rbigint.fromrarith_int(r_longlong(-(BASE**2))).eq(
+            rbigint([0, 0, 1], -1))
 #        assert rbigint.fromrarith_int(-sys.maxint-1).eq((
 #            rbigint.digits_for_most_neg_long(-sys.maxint-1), -1)
 

diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -1,5 +1,6 @@
 from pypy.rlib.rarithmetic import LONG_BIT, intmask, r_uint, r_ulonglong
 from pypy.rlib.rarithmetic import ovfcheck, r_longlong, widen, isinf, isnan
+from pypy.rlib.rarithmetic import most_neg_value_of_same_type
 from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib.objectmodel import we_are_translated
 
@@ -630,19 +631,12 @@
         return digits_from_nonneg_long(x), 1
     elif x == 0:
         return [0], 0
+    elif x != most_neg_value_of_same_type(x):
+        # normal case
+        return digits_from_nonneg_long(-x), -1
     else:
-        try:
-            y = ovfcheck(-x)
-        except OverflowError:
-            y = -1
-        # be conservative and check again if the result is >= 0, even
-        # if no OverflowError was raised (e.g. broken CPython/GCC4.2)
-        if y >= 0:
-            # normal case
-            return digits_from_nonneg_long(y), -1
-        else:
-            # the most negative integer! hacks needed...
-            return digits_for_most_neg_long(x), -1
+        # the most negative integer! hacks needed...
+        return digits_for_most_neg_long(x), -1
 args_from_rarith_int1._annspecialcase_ = "specialize:argtype(0)"
 
 def args_from_rarith_int(x):


More information about the Pypy-commit mailing list