[pypy-svn] pypy jit-longlong: Generalize a bit the logic.

arigo commits-noreply at bitbucket.org
Fri Jan 7 11:00:37 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: jit-longlong
Changeset: r40439:ee33cbd1c492
Date: 2011-01-07 10:33 +0100
http://bitbucket.org/pypy/pypy/changeset/ee33cbd1c492/

Log:	Generalize a bit the logic.

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
@@ -32,33 +32,140 @@
         if sys.maxint > 2147483647:
             py.test.skip("only for 32-bit platforms")
 
-    def test_unsupported_binary_op(self):
+    def do_check(self, opname, oopspecindex, ARGS, RESULT):
+        vlist = [varoftype(ARG) for ARG in ARGS]
+        v_result = varoftype(RESULT)
+        op = SpaceOperation(opname, vlist, v_result)
         tr = Transformer(FakeCPU([]), FakeBuiltinCallControl())
-        for opname, oopspecindex in [
-                ('llong_add', EffectInfo.OS_LLONG_ADD),
-                ('ullong_add', EffectInfo.OS_LLONG_ADD),
-            ]:
-            v1 = varoftype(lltype.SignedLongLong)
-            v2 = varoftype(lltype.SignedLongLong)
-            v3 = varoftype(lltype.SignedLongLong)
-            op = SpaceOperation(opname, [v1, v2], v3)
-            op1 = tr.rewrite_operation(op)
+        op1 = tr.rewrite_operation(op)
+        #
+        def is_ll(TYPE):
+            return (TYPE == lltype.SignedLongLong or
+                    TYPE == lltype.UnsignedLongLong)
+        assert [ARG for ARG in ARGS if is_ll(ARG)]
+        if is_ll(RESULT):
             assert op1.opname == 'residual_call_irf_f'
-            assert op1.args[0].value == opname.lstrip('u')
-            assert op1.args[1] == 'calldescr-%d' % oopspecindex
-            assert list(op1.args[2]) == []
-            assert list(op1.args[3]) == []
-            assert list(op1.args[4]) == [v1, v2]
-            assert op1.result == v3
+        else:
+            assert op1.opname == 'residual_call_irf_i'
+        assert op1.args[0].value == opname.lstrip('u')
+        assert op1.args[1] == 'calldescr-%d' % oopspecindex
+        assert list(op1.args[2]) == []
+        assert list(op1.args[3]) == []
+        assert list(op1.args[4]) == vlist
+        assert op1.result == v_result
 
-    def test_prebuilt_constant_32(self):
-        c_x = const(r_longlong(-171))
-        op = SpaceOperation('foobar', [c_x], None)
-        oplist = Transformer(FakeCPU(['foobar'])).rewrite_operation(op)
-        assert len(oplist) == 2
-        assert oplist[0].opname == 'cast_int_to_longlong'
-        assert oplist[0].args == [c_x]
-        v = oplist[0].result
-        assert isinstance(v, Variable)
-        assert oplist[1].opname == 'foobar'
-        assert oplist[1].args == [v]
+    def test_is_true(self):
+        self.do_check('llong_is_true', EffectInfo.OS_LLONG_IS_TRUE,
+                      [lltype.SignedLongLong], lltype.Bool)
+        self.do_check('ullong_is_true', EffectInfo.OS_LLONG_IS_TRUE,
+                      [lltype.SignedLongLong], lltype.Bool)
+
+##    def test_unary_op(self):
+##        tr = Transformer(FakeCPU([]), FakeBuiltinCallControl())
+##        for opname, oopspecindex in [
+##                ('llong_neg',     EffectInfo.OS_LLONG_NEG),
+##                ('llong_invert',  EffectInfo.OS_LLONG_INVERT),
+                
+##                ('ullong_is_true', EffectInfo.OS_LLONG_IS_TRUE),
+##                ('ullong_neg', EffectInfo.OS_LLONG_NEG),
+
+##                ('llong_lt', EffectInfo.OS_LLONG_LT),
+##                ('llong_le', EffectInfo.OS_LLONG_LE),
+##                ('llong_eq', EffectInfo.OS_LLONG_EQ),
+##                ('llong_ne', EffectInfo.OS_LLONG_NE),
+##                ('llong_gt', EffectInfo.OS_LLONG_GT),
+##                ('llong_ge', EffectInfo.OS_LLONG_GE),
+
+    def test_binary_op(self):
+        self.do_check('llong_add', EffectInfo.OS_LLONG_ADD,
+                      [lltype.SignedLongLong, lltype.SignedLongLong],
+                      lltype.SignedLongLong)
+        self.do_check('ullong_add', EffectInfo.OS_LLONG_ADD,
+                      [lltype.UnsignedLongLong, lltype.UnsignedLongLong],
+                      lltype.UnsignedLongLong)
+
+##        tr = Transformer(FakeCPU([]), FakeBuiltinCallControl())
+##        for opname, oopspecindex in [
+##                ('llong_add',    EffectInfo.OS_LLONG_ADD),
+##                ('llong_sub',    EffectInfo.OS_LLONG_SUB),
+##                ('llong_mul',    EffectInfo.OS_LLONG_MUL),
+##                ('llong_and',    EffectInfo.OS_LLONG_AND),
+##                ('llong_or',     EffectInfo.OS_LLONG_OR),
+##                ('llong_xor',    EffectInfo.OS_LLONG_XOR),
+
+
+
+
+##                ('llong_lshift', EffectInfo.OS_LLONG_LSHIFT),
+##                ('', EffectInfo.OS_LLONG_RSHIFT),
+
+
+##    'llong_is_true':        LLOp(canfold=True),
+##    'llong_neg':            LLOp(canfold=True),
+##    'llong_neg_ovf':        LLOp(canraise=(OverflowError,), tryfold=True),
+##    'llong_abs':            LLOp(canfold=True),
+##    'llong_abs_ovf':        LLOp(canraise=(OverflowError,), tryfold=True),
+##    'llong_invert':         LLOp(canfold=True),
+
+##    'llong_add':            LLOp(canfold=True),
+##    'llong_sub':            LLOp(canfold=True),
+##    'llong_mul':            LLOp(canfold=True),
+##    'llong_floordiv':       LLOp(canfold=True),
+##    'llong_floordiv_zer':   LLOp(canraise=(ZeroDivisionError,), tryfold=True),
+##    'llong_mod':            LLOp(canfold=True),
+##    'llong_mod_zer':        LLOp(canraise=(ZeroDivisionError,), tryfold=True),
+##    'llong_lt':             LLOp(canfold=True),
+##    'llong_le':             LLOp(canfold=True),
+##    'llong_eq':             LLOp(canfold=True),
+##    'llong_ne':             LLOp(canfold=True),
+##    'llong_gt':             LLOp(canfold=True),
+##    'llong_ge':             LLOp(canfold=True),
+##    'llong_and':            LLOp(canfold=True),
+##    'llong_or':             LLOp(canfold=True),
+##    'llong_lshift':         LLOp(canfold=True),
+##    'llong_rshift':         LLOp(canfold=True),
+##    'llong_xor':            LLOp(canfold=True),
+
+##    'ullong_is_true':       LLOp(canfold=True),
+##    'ullong_invert':        LLOp(canfold=True),
+
+##    'ullong_add':           LLOp(canfold=True),
+##    'ullong_sub':           LLOp(canfold=True),
+##    'ullong_mul':           LLOp(canfold=True),
+##    'ullong_floordiv':      LLOp(canfold=True),
+##    'ullong_floordiv_zer':  LLOp(canraise=(ZeroDivisionError,), tryfold=True),
+##    'ullong_mod':           LLOp(canfold=True),
+##    'ullong_mod_zer':       LLOp(canraise=(ZeroDivisionError,), tryfold=True),
+##    'ullong_lt':            LLOp(canfold=True),
+##    'ullong_le':            LLOp(canfold=True),
+##    'ullong_eq':            LLOp(canfold=True),
+##    'ullong_ne':            LLOp(canfold=True),
+##    'ullong_gt':            LLOp(canfold=True),
+##    'ullong_ge':            LLOp(canfold=True),
+##    'ullong_and':           LLOp(canfold=True),
+##    'ullong_or':            LLOp(canfold=True),
+##    'ullong_lshift':        LLOp(canfold=True),
+##    'ullong_rshift':        LLOp(canfold=True),
+##    'ullong_xor':           LLOp(canfold=True),
+
+##            ]:
+
+
+
+##                ('', EffectInfo.OS_LLONG_FROM_INT),
+##                ('', EffectInfo.OS_LLONG_TO_INT),
+##                ('', EffectInfo.OS_LLONG_FROM_FLOAT),
+##                ('', EffectInfo.OS_LLONG_TO_FLOAT),
+
+
+##    def test_prebuilt_constant_32(self):
+##        c_x = const(r_longlong(-171))
+##        op = SpaceOperation('foobar', [c_x], None)
+##        oplist = Transformer(FakeCPU(['foobar'])).rewrite_operation(op)
+##        assert len(oplist) == 2
+##        assert oplist[0].opname == 'cast_int_to_longlong'
+##        assert oplist[0].args == [c_x]
+##        v = oplist[0].result
+##        assert isinstance(v, Variable)
+##        assert oplist[1].opname == 'foobar'
+##        assert oplist[1].args == [v]

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
@@ -227,6 +227,10 @@
 # long long support
 # -----------------
 
+def _ll_1_llong_is_true(xf):
+    x = float2longlong(xf)
+    return bool(x)
+
 def _ll_2_llong_add(xf, yf):
     x = float2longlong(xf)
     y = float2longlong(yf)

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
@@ -47,7 +47,27 @@
     OS_LIBFFI_PUSH_ARG          = 61
     OS_LIBFFI_CALL              = 62
     #
+    OS_LLONG_IS_TRUE            = 67
+    OS_LLONG_NEG                = 68
+    OS_LLONG_INVERT             = 69
     OS_LLONG_ADD                = 70
+    OS_LLONG_SUB                = 71
+    OS_LLONG_MUL                = 72
+    OS_LLONG_LT                 = 73
+    OS_LLONG_LE                 = 74
+    OS_LLONG_EQ                 = 75
+    OS_LLONG_NE                 = 76
+    OS_LLONG_GT                 = 77
+    OS_LLONG_GE                 = 78
+    OS_LLONG_AND                = 79
+    OS_LLONG_OR                 = 80
+    OS_LLONG_LSHIFT             = 81
+    OS_LLONG_RSHIFT             = 82
+    OS_LLONG_XOR                = 83
+    OS_LLONG_FROM_INT           = 84
+    OS_LLONG_TO_INT             = 85
+    OS_LLONG_FROM_FLOAT         = 86
+    OS_LLONG_TO_FLOAT           = 87
 
     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
@@ -783,15 +783,16 @@
     # and unsupported ones are turned into a call to a function from
     # jit.codewriter.support.
 
-    def rewrite_op_llong_add(self, op):
-        if 'add' in self.cpu.supports_longlong:
-            return op
-        else:
-            op1 = self.prepare_builtin_call(op, 'llong_add', op.args)
-            return self._handle_oopspec_call(op1, op.args,
-                                             EffectInfo.OS_LLONG_ADD)
-
-    rewrite_op_ullong_add = rewrite_op_llong_add
+    for _op in ['is_true',
+                'add',
+                ]:
+        exec py.code.Source('''
+            def rewrite_op_llong_%s(self, op):
+                op1 = self.prepare_builtin_call(op, "llong_%s", op.args)
+                return self._handle_oopspec_call(op1, op.args,
+                                                 EffectInfo.OS_LLONG_%s)
+            rewrite_op_ullong_%s = rewrite_op_llong_%s
+        ''' % (_op, _op, _op.upper(), _op, _op)).compile()
 
     # ----------
     # Renames, from the _old opname to the _new one.


More information about the Pypy-commit mailing list