[pypy-svn] pypy jit-longlong: Support long long constants of more than 32 bits.

arigo commits-noreply at bitbucket.org
Fri Jan 7 16:09:35 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: jit-longlong
Changeset: r40455:278fe175c7a2
Date: 2011-01-07 16:09 +0100
http://bitbucket.org/pypy/pypy/changeset/278fe175c7a2/

Log:	Support long long constants of more than 32 bits.

diff --git a/pypy/jit/codewriter/test/test_longlong.py b/pypy/jit/codewriter/test/test_longlong.py
--- a/pypy/jit/codewriter/test/test_longlong.py
+++ b/pypy/jit/codewriter/test/test_longlong.py
@@ -1,6 +1,6 @@
 import py, sys
 
-from pypy.rlib.rarithmetic import r_longlong
+from pypy.rlib.rarithmetic import r_longlong, intmask
 from pypy.objspace.flow.model import SpaceOperation, Variable, Constant
 from pypy.translator.unsimplify import varoftype
 from pypy.rpython.lltypesystem import lltype
@@ -165,11 +165,28 @@
         assert oplist[1].result == v_z
 
     def test_prebuilt_constant_64(self):
-        py.test.skip("in-progress")
-        c_x = const(r_longlong(3000000000))
-        v_y = varoftype(lltype.SignedLongLong)
-        v_z = varoftype(lltype.SignedLongLong)
-        op = SpaceOperation('llong_add', [c_x, v_y], v_z)
-        tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
-        oplist = tr.rewrite_operation(op)
-        xxx
+        for value in [3000000000, -3000000000, 12345678987654321]:
+            v_hi = intmask(value >> 32)
+            v_lo = intmask(value)
+            c_x = const(r_longlong(value))
+            v_y = varoftype(lltype.SignedLongLong)
+            v_z = varoftype(lltype.SignedLongLong)
+            op = SpaceOperation('llong_add', [c_x, v_y], v_z)
+            tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
+            oplist = tr.rewrite_operation(op)
+            assert len(oplist) == 2
+            assert oplist[0].opname == 'residual_call_irf_f'
+            assert oplist[0].args[0].value == 'llong_from_two_ints'
+            assert oplist[0].args[1] == 'calldescr-93'
+            assert list(oplist[0].args[2]) == [const(v_hi), const(v_lo)]
+            assert list(oplist[0].args[3]) == []
+            assert list(oplist[0].args[4]) == []
+            v_x = oplist[0].result
+            assert isinstance(v_x, Variable)
+            assert oplist[1].opname == 'residual_call_irf_f'
+            assert oplist[1].args[0].value == 'llong_add'
+            assert oplist[1].args[1] == 'calldescr-70'
+            assert list(oplist[1].args[2]) == []
+            assert list(oplist[1].args[3]) == []
+            assert list(oplist[1].args[4]) == [v_x, v_y]
+            assert oplist[1].result == v_z

diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py
--- a/pypy/jit/codewriter/support.py
+++ b/pypy/jit/codewriter/support.py
@@ -295,6 +295,9 @@
 def _ll_1_llong_from_int(x):
     return r_longlong(x)
 
+def _ll_2_llong_from_two_ints(x_lo, x_hi):
+    return (r_longlong(x_hi) << 32) | r_longlong(r_uint(x_lo))
+
 def _ll_1_llong_to_int(xll):
     return intmask(xll)
 

diff --git a/pypy/jit/codewriter/effectinfo.py b/pypy/jit/codewriter/effectinfo.py
--- a/pypy/jit/codewriter/effectinfo.py
+++ b/pypy/jit/codewriter/effectinfo.py
@@ -73,6 +73,7 @@
     OS_LLONG_UGT                = 90
     OS_LLONG_UGE                = 91
     OS_LLONG_URSHIFT            = 92
+    OS_LLONG_FROM_TWO_INTS      = 93
 
     def __new__(cls, readonly_descrs_fields,
                 write_descrs_fields, write_descrs_arrays,

diff --git a/pypy/jit/codewriter/jtransform.py b/pypy/jit/codewriter/jtransform.py
--- a/pypy/jit/codewriter/jtransform.py
+++ b/pypy/jit/codewriter/jtransform.py
@@ -800,14 +800,27 @@
         for i in range(len(args)):
             if (isinstance(args[i], Constant) and
                     self._is_longlong(args[i].concretetype)):
+                from pypy.rlib.rarithmetic import intmask
                 v_x = varoftype(args[i].concretetype)
                 value = int(args[i].value)
-                assert type(value) is int     # XXX!
-                c_x = Constant(value, lltype.Signed)
-                op0 = SpaceOperation('llong_from_int', [c_x], v_x)
-                op1 = self.prepare_builtin_call(op0, "llong_from_int", [c_x])
-                op2 = self._handle_oopspec_call(op1, [c_x],
-                                                EffectInfo.OS_LLONG_FROM_INT)
+                if value == intmask(value):
+                    # a long long constant, but it fits in 32 bits
+                    c_x = Constant(value, lltype.Signed)
+                    op0 = SpaceOperation('llong_from_int', [c_x], v_x)
+                    op1 = self.prepare_builtin_call(op0, "llong_from_int",
+                                                    [c_x])
+                    op2 = self._handle_oopspec_call(op1, [c_x],
+                                                  EffectInfo.OS_LLONG_FROM_INT)
+                else:
+                    # a long long constant, requires two ints
+                    c_hi = Constant(intmask(value >> 32), lltype.Signed)
+                    c_lo = Constant(intmask(value), lltype.Signed)
+                    op0 = SpaceOperation('llong_from_two_ints', [c_hi, c_lo],
+                                         v_x)
+                    op1 = self.prepare_builtin_call(op0, "llong_from_two_ints",
+                                                    [c_hi, c_lo])
+                    op2 = self._handle_oopspec_call(op1, [c_hi, c_lo],
+                                             EffectInfo.OS_LLONG_FROM_TWO_INTS)
                 oplist.append(op2)
                 args = args[:]
                 args[i] = v_x


More information about the Pypy-commit mailing list