[pypy-svn] r69099 - in pypy/branch/guard-nonnull/pypy/jit/metainterp: . test

fijal at codespeak.net fijal at codespeak.net
Mon Nov 9 16:33:55 CET 2009


Author: fijal
Date: Mon Nov  9 16:33:54 2009
New Revision: 69099

Modified:
   pypy/branch/guard-nonnull/pypy/jit/metainterp/codewriter.py
   pypy/branch/guard-nonnull/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/guard-nonnull/pypy/jit/metainterp/test/test_basic.py
Log:
(arigo, fijal) A test and a fix for bridge around pointer comparison


Modified: pypy/branch/guard-nonnull/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/guard-nonnull/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/guard-nonnull/pypy/jit/metainterp/codewriter.py	Mon Nov  9 16:33:54 2009
@@ -820,16 +820,18 @@
             self.default_serialize_op(op)
 
     def serialize_op_ptr_eq(self, op):
-        self._serialize_op_ptr_eq(op, 'ptr_iszero')
+        self._serialize_op_ptr_eq(op, 'ooisnull')
+    serialize_op_oois = serialize_op_ptr_eq
 
     def serialize_op_ptr_ne(self, op):
-        self._serialize_op_ptr_eq(op, 'ptr_nonzero')
+        self._serialize_op_ptr_eq(op, 'oononnull')
+    serialize_op_ooisnot = serialize_op_ptr_ne
 
-    def serialize_op_oois(self, op):
-        self._serialize_op_ptr_eq(op, 'ooisnull')
+    def serialize_op_ptr_iszero(self, op):
+        self.default_serialize_op(op, 'ooisnull')
 
-    def serialize_op_ooisnot(self, op):
-        self._serialize_op_ptr_eq(op, 'oononnull')
+    def serialize_op_ptr_nonzero(self, op):
+        self.default_serialize_op(op, 'oononnull')
 
     def serialize_op_malloc(self, op):
         assert op.args[1].value == {'flavor': 'gc'}

Modified: pypy/branch/guard-nonnull/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/guard-nonnull/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/guard-nonnull/pypy/jit/metainterp/pyjitpl.py	Mon Nov  9 16:33:54 2009
@@ -281,9 +281,24 @@
         target = self.load_3byte()  # load the 'target' argument
         self.pc = target      # jump
 
-    def ignore_next_guard_nullness(self):
+    def ignore_next_guard_nullness(self, opnum):
+        _op_ooisnull = self.metainterp.staticdata._op_ooisnull
+        _op_oononnull = self.metainterp.staticdata._op_oononnull
+        bc = ord(self.bytecode[self.pc])
+        if bc == _op_ooisnull:
+            if opnum == rop.GUARD_ISNULL:
+                res = ConstInt(0)
+            else:
+                res = ConstInt(1)
+        else:
+            assert bc == _op_oononnull
+            if opnum == rop.GUARD_ISNULL:
+                res = ConstInt(1)
+            else:
+                res = ConstInt(0)
         self.pc += 1    # past the bytecode for ptr_iszero/ptr_nonzero
         self.load_int() # past the 'box' argument
+        self.make_result_box(res)
 
     def dont_follow_jump(self):
         _op_goto_if_not = self.metainterp.staticdata._op_goto_if_not
@@ -450,7 +465,7 @@
             self.execute(rop.INT_NEG, box)
 
     @arguments("orgpc", "box")
-    def opimpl_ptr_nonzero(self, pc, box):
+    def opimpl_oononnull(self, pc, box):
         value = box.nonnull()
         if value:
             opnum = rop.GUARD_NONNULL
@@ -462,7 +477,7 @@
         self.make_result_box(res)
 
     @arguments("orgpc", "box")
-    def opimpl_ptr_iszero(self, pc, box):
+    def opimpl_ooisnull(self, pc, box):
         value = box.nonnull()
         if value:
             opnum = rop.GUARD_NONNULL
@@ -473,9 +488,6 @@
         self.generate_guard(pc, opnum, box, [])
         self.make_result_box(res)
 
-    opimpl_oononnull = opimpl_ptr_nonzero
-    opimpl_ooisnull = opimpl_ptr_iszero
-
     @arguments("box", "box")
     def opimpl_ptr_eq(self, box1, box2):
         self.execute(rop.OOIS, box1, box2)
@@ -1001,6 +1013,8 @@
 
         self.warmrunnerdesc = warmrunnerdesc
         self._op_goto_if_not = self.find_opcode('goto_if_not')
+        self._op_ooisnull    = self.find_opcode('ooisnull')
+        self._op_oononnull   = self.find_opcode('oononnull')
 
         backendmodule = self.cpu.__module__
         backendmodule = backendmodule.split('.')[-2]
@@ -1548,7 +1562,7 @@
         elif opnum == rop.GUARD_NO_OVERFLOW:   # an overflow now detected
             self.raise_overflow_error()
         elif opnum == rop.GUARD_NONNULL or opnum == rop.GUARD_ISNULL:
-            self.framestack[-1].ignore_next_guard_nullness()
+            self.framestack[-1].ignore_next_guard_nullness(opnum)
 
     def compile(self, original_boxes, live_arg_boxes, start):
         num_green_args = self.staticdata.num_green_args

Modified: pypy/branch/guard-nonnull/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/guard-nonnull/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/guard-nonnull/pypy/jit/metainterp/test/test_basic.py	Mon Nov  9 16:33:54 2009
@@ -1180,8 +1180,24 @@
             history.BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, x))).value
         assert res == expected
 
+    def test_collapsing_ptr_eq(self):
+        S = lltype.GcStruct('S')
+        p = lltype.malloc(S)
+        driver = JitDriver(greens = [], reds = ['n', 'x'])
 
+        def f(n, x):
+            while n > 0:
+                driver.can_enter_jit(n=n, x=x)
+                driver.jit_merge_point(n=n, x=x)
+                if x:
+                    n -= 1
+                n -= 1
 
+        def main():
+            f(10, p)
+            f(10, lltype.nullptr(S))
+
+        self.meta_interp(main, [])
 
 class TestLLtype(BaseLLtypeTests, LLJitMixin):
     pass



More information about the Pypy-commit mailing list