[pypy-svn] r76271 - in pypy/branch/interplevel-array/pypy: jit/metainterp jit/metainterp/test module/pypyjit/test

hakanardo at codespeak.net hakanardo at codespeak.net
Sat Jul 17 10:42:03 CEST 2010


Author: hakanardo
Date: Sat Jul 17 10:42:02 2010
New Revision: 76271

Modified:
   pypy/branch/interplevel-array/pypy/jit/metainterp/optimizeopt.py
   pypy/branch/interplevel-array/pypy/jit/metainterp/resoperation.py
   pypy/branch/interplevel-array/pypy/jit/metainterp/test/test_executor.py
   pypy/branch/interplevel-array/pypy/jit/metainterp/test/test_optimizeopt.py
   pypy/branch/interplevel-array/pypy/module/pypyjit/test/test_pypy_c.py
Log:
bool rewriting tests and UINT support

Modified: pypy/branch/interplevel-array/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/branch/interplevel-array/pypy/jit/metainterp/optimizeopt.py	Sat Jul 17 10:42:02 2010
@@ -620,36 +620,49 @@
         self.emit_operation(op)
 
 
+    def try_boolinvers(self, op, targs):
+        oldop = self.pure_operations.get(targs, None)
+        if oldop is not None and oldop.descr is op.descr:
+            value = self.getvalue(oldop.result)
+            if value.is_constant():
+                if value.box is CONST_1:
+                    self.make_constant(op.result, CONST_0)
+                    return True
+                elif value.box is CONST_0:
+                    self.make_constant(op.result, CONST_1)
+                    return True
+        return False
+
+    
     def find_rewriteable_bool(self, op, args):
         try:
             oldopnum = opboolinvers[op.opnum]
-            targ = [args[0], args[1], ConstInt(oldopnum)]
-            oldop = self.pure_operations.get(targ, None)
-            if oldop is not None and oldop.descr is op.descr:
-                value = self.getvalue(oldop.result)
-                if value.is_constant():
-                    if value.box is CONST_1:
-                        self.make_constant(op.result, CONST_0)
-                        return True
-                    elif value.box is CONST_0:
-                        self.make_constant(op.result, CONST_1)
-                        return True
+            targs = [args[0], args[1], ConstInt(oldopnum)]
+            if self.try_boolinvers(op, targs):
+                return True
         except KeyError:
             pass
 
         try:
             oldopnum = opboolreflex[op.opnum]
-            targ = [args[1], args[0], ConstInt(oldopnum)]
-            oldop = self.pure_operations.get(targ, None)
+            targs = [args[1], args[0], ConstInt(oldopnum)]
+            oldop = self.pure_operations.get(targs, None)
             if oldop is not None and oldop.descr is op.descr:
                 self.make_equal_to(op.result, self.getvalue(oldop.result))
                 return True
         except KeyError:
             pass
 
-        # FIXME: oldopnum = opboolinvers[opboolreflex[op.opnum]]?
-            
+        try:
+            oldopnum = opboolinvers[opboolreflex[op.opnum]]
+            targs = [args[1], args[0], ConstInt(oldopnum)]
+            if self.try_boolinvers(op, targs):
+                return True
+        except KeyError:
+            pass
+
         return False
+
         
     def optimize_JUMP(self, op):
         orgop = self.loop.operations[-1]

Modified: pypy/branch/interplevel-array/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/jit/metainterp/resoperation.py	(original)
+++ pypy/branch/interplevel-array/pypy/jit/metainterp/resoperation.py	Sat Jul 17 10:42:02 2010
@@ -283,6 +283,11 @@
     rop.INT_GT: rop.INT_LE,
     rop.INT_LE: rop.INT_GT,
 
+    rop.UINT_LT: rop.UINT_GE,
+    rop.UINT_GE: rop.UINT_LT,
+    rop.UINT_GT: rop.UINT_LE,
+    rop.UINT_LE: rop.UINT_GT,
+
     rop.FLOAT_EQ: rop.FLOAT_NE,
     rop.FLOAT_NE: rop.FLOAT_EQ,
     rop.FLOAT_LT: rop.FLOAT_GE,
@@ -302,6 +307,11 @@
     rop.INT_GT: rop.INT_LT,
     rop.INT_LE: rop.INT_GE,
 
+    rop.UINT_LT: rop.UINT_GT,
+    rop.UINT_GE: rop.UINT_LE,
+    rop.UINT_GT: rop.UINT_LT,
+    rop.UINT_LE: rop.UINT_GE,
+
     rop.FLOAT_EQ: rop.FLOAT_EQ,
     rop.FLOAT_NE: rop.FLOAT_NE,
     rop.FLOAT_LT: rop.FLOAT_GT,

Modified: pypy/branch/interplevel-array/pypy/jit/metainterp/test/test_executor.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/jit/metainterp/test/test_executor.py	(original)
+++ pypy/branch/interplevel-array/pypy/jit/metainterp/test/test_executor.py	Sat Jul 17 10:42:02 2010
@@ -4,14 +4,14 @@
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.jit.metainterp.executor import execute
 from pypy.jit.metainterp.executor import execute_varargs, execute_nonspec
-from pypy.jit.metainterp.resoperation import rop
+from pypy.jit.metainterp.resoperation import rop, opboolinvers, opboolreflex, opname
 from pypy.jit.metainterp.history import BoxInt, ConstInt
 from pypy.jit.metainterp.history import BoxPtr, ConstPtr
 from pypy.jit.metainterp.history import BoxFloat, ConstFloat
 from pypy.jit.metainterp.history import AbstractDescr, Box
 from pypy.jit.metainterp import history
 from pypy.jit.backend.model import AbstractCPU
-
+from pypy.rpython.lltypesystem import  llmemory, rffi
 
 class FakeDescr(AbstractDescr):
     pass
@@ -312,3 +312,40 @@
             assert box.getint() == retvalue
         else:
             assert 0, "rettype is %r" % (rettype,)
+
+def make_args_for_op(op, a, b):
+    n=opname[op]
+    if n[0:3] == 'INT' or n[0:4] == 'UINT':
+        arg1 = ConstInt(a)
+        arg2 = ConstInt(b)
+    elif n[0:5] == 'FLOAT':
+        arg1 = ConstFloat(float(a))
+        arg2 = ConstFloat(float(b))
+    elif n[0:3] == 'PTR':
+        arg1 = ConstPtr(rffi.cast(llmemory.GCREF, a))
+        arg2 = ConstPtr(rffi.cast(llmemory.GCREF, b))
+    else:
+        raise NotImplementedError(
+            "Don't know how to make args for " + n)
+    return arg1, arg2
+
+
+def test_opboolinvers():
+    cpu = FakeCPU()
+    for op1, op2 in opboolinvers.items():
+        for a in (1,2,3):
+            for b in (1,2,3):
+                arg1, arg2 = make_args_for_op(op1, a, b)
+                box1 = execute(cpu, None, op1, None, arg1, arg2)
+                box2 = execute(cpu, None, op2, None, arg1, arg2)
+                assert box1.value == (not box2.value)
+
+def test_opboolreflex():
+    cpu = FakeCPU()
+    for op1, op2 in opboolreflex.items():
+        for a in (1,2,3):
+            for b in (1,2,3):
+                arg1, arg2 = make_args_for_op(op1, a, b)
+                box1 = execute(cpu, None, op1, None, arg1, arg2)
+                box2 = execute(cpu, None, op2, None, arg2, arg1)
+                assert box1.value == box2.value

Modified: pypy/branch/interplevel-array/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/interplevel-array/pypy/jit/metainterp/test/test_optimizeopt.py	Sat Jul 17 10:42:02 2010
@@ -364,7 +364,7 @@
         """
         self.optimize_loop(ops, 'Not', expected)
 
-    def test_constant_boolrewrite1(self):
+    def test_constant_boolrewrite_lt(self):
         ops = """
         [i0]
         i1 = int_lt(i0, 0)
@@ -381,7 +381,7 @@
         """
         self.optimize_loop(ops, 'Not', expected)
 
-    def test_constant_boolrewrite2(self):
+    def test_constant_boolrewrite_gt(self):
         ops = """
         [i0]
         i1 = int_gt(i0, 0)
@@ -398,7 +398,7 @@
         """
         self.optimize_loop(ops, 'Not', expected)
 
-    def test_constant_boolrewrite3(self):
+    def test_constant_boolrewrite_reflex(self):
         ops = """
         [i0]
         i1 = int_gt(i0, 0)
@@ -415,6 +415,23 @@
         """
         self.optimize_loop(ops, 'Not', expected)
 
+    def test_constant_boolrewrite_reflex_invers(self):
+        ops = """
+        [i0]
+        i1 = int_gt(i0, 0)
+        guard_true(i1) []
+        i2 = int_ge(0, i0)
+        guard_false(i2) []
+        jump(i0)
+        """
+        expected = """
+        [i0]
+        i1 = int_gt(i0, 0)
+        guard_true(i1) []
+        jump(i0)
+        """
+        self.optimize_loop(ops, 'Not', expected)
+
     def test_remove_consecutive_guard_value_constfold(self):
         ops = """
         []

Modified: pypy/branch/interplevel-array/pypy/module/pypyjit/test/test_pypy_c.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/module/pypyjit/test/test_pypy_c.py	(original)
+++ pypy/branch/interplevel-array/pypy/module/pypyjit/test/test_pypy_c.py	Sat Jul 17 10:42:02 2010
@@ -741,7 +741,7 @@
                     '''%(op1, float(a)/4.0, float(b)/4.0, op2), 109, ([], res))
 
     def test_boolrewrite_ptr(self):
-        compares = ('a == b', 'b == a', 'a != b', 'a == c')
+        compares = ('a == b', 'b == a', 'a != b', 'b != a', 'a == c', 'c != b')
         for e1 in compares:
             for e2 in compares:
                 a, b, c = 1, 2, 3



More information about the Pypy-commit mailing list