[pypy-svn] pypy jit-longlong: Add more operations.

arigo commits-noreply at bitbucket.org
Fri Jan 7 11:48:13 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: jit-longlong
Changeset: r40445:a402afa79273
Date: 2011-01-07 11:29 +0100
http://bitbucket.org/pypy/pypy/changeset/a402afa79273/

Log:	Add more operations.

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
@@ -47,7 +47,8 @@
             assert op1.opname == 'residual_call_irf_f'
         else:
             assert op1.opname == 'residual_call_irf_i'
-        assert op1.args[0].value == opname.lstrip('u')
+        gotindex = getattr(EffectInfo, 'OS_' + op1.args[0].value.upper())
+        assert gotindex == oopspecindex
         assert op1.args[1] == 'calldescr-%d' % oopspecindex
         assert list(op1.args[2]) == []
         assert list(op1.args[3]) == []
@@ -72,30 +73,47 @@
                 T = lltype.SignedLongLong
             self.do_check(opname, oopspecindex, [T], T)
 
-##                ('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_comparison(self):
+        for opname, oopspecindex in [
+                ('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),
+                ('ullong_lt', EffectInfo.OS_LLONG_ULT),
+                ('ullong_le', EffectInfo.OS_LLONG_ULE),
+                ('ullong_eq', EffectInfo.OS_LLONG_EQ),
+                ('ullong_ne', EffectInfo.OS_LLONG_NE),
+                ('ullong_gt', EffectInfo.OS_LLONG_UGT),
+                ('ullong_ge', EffectInfo.OS_LLONG_UGE),
+                ]:
+            if opname.startswith('u'):
+                T = lltype.UnsignedLongLong
+            else:
+                T = lltype.SignedLongLong
+            self.do_check(opname, oopspecindex, [T, T], lltype.Bool)
 
     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),
-
+        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),
+                ('ullong_add',   EffectInfo.OS_LLONG_ADD),
+                ('ullong_sub',   EffectInfo.OS_LLONG_SUB),
+                ('ullong_mul',   EffectInfo.OS_LLONG_MUL),
+                ('ullong_and',   EffectInfo.OS_LLONG_AND),
+                ('ullong_or',    EffectInfo.OS_LLONG_OR),
+                ('ullong_xor',   EffectInfo.OS_LLONG_XOR),
+                ]:
+            if opname.startswith('u'):
+                T = lltype.UnsignedLongLong
+            else:
+                T = lltype.SignedLongLong
+            self.do_check(opname, oopspecindex, [T, T], T)
 
 
 
@@ -103,53 +121,11 @@
 ##                ('', 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),
 
 ##            ]:
 

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
@@ -241,12 +241,92 @@
     y = ~x
     return longlong2float(y)
 
+def _ll_2_llong_lt(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    return x < y
+
+def _ll_2_llong_le(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    return x <= y
+
+def _ll_2_llong_eq(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    return x == y
+
+def _ll_2_llong_ne(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    return x != y
+
+def _ll_2_llong_gt(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    return x > y
+
+def _ll_2_llong_ge(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    return x >= y
+
+def _ll_2_llong_ult(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    return r_ulonglong(x) < r_ulonglong(y)
+
+def _ll_2_llong_ule(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    return r_ulonglong(x) <= r_ulonglong(y)
+
+def _ll_2_llong_ugt(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    return r_ulonglong(x) > r_ulonglong(y)
+
+def _ll_2_llong_uge(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    return r_ulonglong(x) >= r_ulonglong(y)
+
 def _ll_2_llong_add(xf, yf):
     x = float2longlong(xf)
     y = float2longlong(yf)
     z = x + y
     return longlong2float(z)
 
+def _ll_2_llong_sub(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    z = x - y
+    return longlong2float(z)
+
+def _ll_2_llong_mul(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    z = x * y
+    return longlong2float(z)
+
+def _ll_2_llong_and(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    z = x & y
+    return longlong2float(z)
+
+def _ll_2_llong_or(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    z = x | y
+    return longlong2float(z)
+
+def _ll_2_llong_xor(xf, yf):
+    x = float2longlong(xf)
+    y = float2longlong(yf)
+    z = x ^ y
+    return longlong2float(z)
+
 def _ll_1_llong_from_int(x):
     y = r_longlong(x)
     return longlong2float(y)

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
@@ -68,6 +68,10 @@
     OS_LLONG_TO_INT             = 85
     OS_LLONG_FROM_FLOAT         = 86
     OS_LLONG_TO_FLOAT           = 87
+    OS_LLONG_ULT                = 88
+    OS_LLONG_ULE                = 89
+    OS_LLONG_UGT                = 90
+    OS_LLONG_UGE                = 91
 
     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
@@ -804,13 +804,38 @@
                 args[i] = v_x
         return args
 
-    for _op in ['is_true',
-                'neg',
-                'invert',
-                'add',
-                ]:
+    for _op, _oopspec in [('llong_is_true', 'IS_TRUE'),
+                          ('ullong_is_true','IS_TRUE'),
+                          ('llong_neg',     'NEG'),
+                          ('llong_invert',  'INVERT'),
+                          ('ullong_invert', 'INVERT'),
+                          ('llong_lt',      'LT'),
+                          ('llong_le',      'LE'),
+                          ('llong_eq',      'EQ'),
+                          ('llong_ne',      'NE'),
+                          ('llong_gt',      'GT'),
+                          ('llong_ge',      'GE'),
+                          ('ullong_lt',     'ULT'),
+                          ('ullong_le',     'ULE'),
+                          ('ullong_eq',     'EQ'),
+                          ('ullong_ne',     'NE'),
+                          ('ullong_gt',     'UGT'),
+                          ('ullong_ge',     'UGE'),
+                          ('llong_add',     'ADD'),
+                          ('llong_sub',     'SUB'),
+                          ('llong_mul',     'MUL'),
+                          ('llong_and',     'AND'),
+                          ('llong_or',      'OR'),
+                          ('llong_xor',     'XOR'),
+                          ('ullong_add',    'ADD'),
+                          ('ullong_sub',    'SUB'),
+                          ('ullong_mul',    'MUL'),
+                          ('ullong_and',    'AND'),
+                          ('ullong_or',     'OR'),
+                          ('ullong_xor',    'XOR'),
+                          ]:
         exec py.code.Source('''
-            def rewrite_op_llong_%s(self, op):
+            def rewrite_op_%s(self, op):
                 oplist = []
                 args = self._remove_longlong_constants(op.args, oplist)
                 op1 = self.prepare_builtin_call(op, "llong_%s", args)
@@ -818,8 +843,7 @@
                                                 EffectInfo.OS_LLONG_%s)
                 oplist.append(op2)
                 return oplist
-            rewrite_op_ullong_%s = rewrite_op_llong_%s
-        ''' % (_op, _op, _op.upper(), _op, _op)).compile()
+        ''' % (_op, _oopspec.lower(), _oopspec)).compile()
 
     # ----------
     # Renames, from the _old opname to the _new one.


More information about the Pypy-commit mailing list