[pypy-svn] r66808 - in pypy/branch/pyjitpl5-guardovf/pypy/jit/backend: . llgraph llgraph/test test

arigo at codespeak.net arigo at codespeak.net
Thu Aug 13 20:41:32 CEST 2009


Author: arigo
Date: Thu Aug 13 20:41:32 2009
New Revision: 66808

Modified:
   pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/runner.py
   pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/test/test_llgraph.py
   pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/model.py
   pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/test/runner_test.py
   pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/test/test_random.py
Log:
Adapt the backends, step 1.


Modified: pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/llimpl.py	Thu Aug 13 20:41:32 2009
@@ -108,10 +108,11 @@
     'guard_true'      : (('bool',), None),
     'guard_false'     : (('bool',), None),
     'guard_value'     : (('int', 'int'), None),
-    'guard_value_inverse'  : (('int', 'int'), None),
     'guard_class'     : (('ptr', 'ptr'), None),
     'guard_no_exception'   : ((), None),
     'guard_exception'      : (('ptr',), 'ptr'),
+    'guard_no_overflow'    : ((), None),
+    'guard_overflow'       : ((), None),
     'newstr'          : (('int',), 'ptr'),
     'strlen'          : (('ptr',), 'int'),
     'strgetitem'      : (('ptr', 'int'), 'int'),
@@ -534,30 +535,14 @@
         if value.typeptr != expected_class:
             raise GuardFailed
 
-    def op_guard_class_inverse(self, _, value, expected_class):
-        value = lltype.cast_opaque_ptr(rclass.OBJECTPTR, value)
-        expected_class = llmemory.cast_adr_to_ptr(
-            cast_int_to_adr(self.memocast, expected_class),
-            rclass.CLASSTYPE)
-        if value.typeptr == expected_class:
-            raise GuardFailed
-
     def op_guard_value(self, _, value, expected_value):
         if value != expected_value:
             raise GuardFailed
 
-    def op_guard_value_inverse(self, _, value, expected_value):
-        if value == expected_value:
-            raise GuardFailed
-
     def op_guard_no_exception(self, _):
         if _last_exception:
             raise GuardFailed
 
-    def op_guard_no_exception_inverse(self, _):
-        if _last_exception is None:
-            raise GuardFailed
-
     def _check_exception(self, expected_exception):
         global _last_exception
         expected_exception = self._cast_exception(expected_exception)
@@ -587,14 +572,19 @@
         _last_exception = None
         return res
 
-    def op_guard_exception_inverse(self, _, expected_exception):
-        global _last_exception
-        if self._check_exception(expected_exception):
+    def op_guard_no_overflow(self, _):
+        global _overflow_flag
+        if _overflow_flag:
+            _overflow_flag = False
             raise GuardFailed
-        res = _last_exception[1]
-        _last_exception = None
-        return res
-    
+
+    def op_guard_overflow(self, _):
+        global _overflow_flag
+        if _overflow_flag:
+            _overflow_flag = False
+        else:
+            raise GuardFailed
+
     # ----------
     # delegating to the builtins do_xxx() (done automatically for simple cases)
 
@@ -926,6 +916,15 @@
 def set_zero_division_error():
     _set_error(ZeroDivisionError)
 
+_overflow_flag = False
+
+def get_overflow_flag():
+    return _overflow_flag
+
+def set_overflow_flag(flag):
+    global _overflow_flag
+    _overflow_flag = flag
+
 class MemoCast(object):
     def __init__(self):
         self.addresses = [llmemory.NULL]

Modified: pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/runner.py	Thu Aug 13 20:41:32 2009
@@ -219,6 +219,12 @@
     def set_zero_division_error(self):
         llimpl.set_zero_division_error()
 
+    def get_overflow_flag(self):
+        return llimpl.get_overflow_flag()
+
+    def set_overflow_flag(self, flag):
+        llimpl.set_overflow_flag(flag)
+
     @staticmethod
     def sizeof(S):
         return Descr(symbolic.get_size(S))

Modified: pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/test/test_llgraph.py
==============================================================================
--- pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/test/test_llgraph.py	(original)
+++ pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/llgraph/test/test_llgraph.py	Thu Aug 13 20:41:32 2009
@@ -36,9 +36,6 @@
                     assert getattr(res, key) == value
         interpret(main, [])
 
-    def test_ovf_operations(self):
-        py.test.skip('no way to run this without a typer')
-
     def test_execute_operations_in_env(self):
         py.test.skip("Rewrite me")
         x = BoxInt(123)

Modified: pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/model.py
==============================================================================
--- pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/model.py	(original)
+++ pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/model.py	Thu Aug 13 20:41:32 2009
@@ -1,4 +1,5 @@
 class AbstractCPU(object):
+    _overflow_flag = False
 
     def set_class_sizes(self, class_sizes):
         self.class_sizes = class_sizes
@@ -60,6 +61,12 @@
     def set_zero_division_error(self):
         raise NotImplementedError
 
+    def get_overflow_flag(self):
+        return self._overflow_flag
+
+    def set_overflow_flag(self, flag):
+        self._overflow_flag = flag
+
     @staticmethod
     def sizeof(S):
         raise NotImplementedError

Modified: pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/test/runner_test.py
==============================================================================
--- pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/test/runner_test.py	(original)
+++ pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/test/runner_test.py	Thu Aug 13 20:41:32 2009
@@ -217,24 +217,18 @@
             if not reversed:
                 ops = [
                     ResOperation(opnum, [v1, v2], v_res),
-                    ResOperation(rop.GUARD_NO_EXCEPTION, [], None),
+                    ResOperation(rop.GUARD_NO_OVERFLOW, [], None),
                     ResOperation(rop.FAIL, [v_res], None),
                     ]
                 ops[1].suboperations = [ResOperation(rop.FAIL, [], None)]
             else:
-                self.cpu.set_overflow_error()
-                ovferror = self.cpu.get_exception()
-                assert self.cpu.get_exc_value()
-                self.cpu.clear_exception()
                 if self.cpu.is_oo:
                     v_exc = BoxObj()
-                    c_ovferror = ConstObj(ovferror)
                 else:
                     v_exc = BoxPtr()
-                    c_ovferror = ConstInt(ovferror)
                 ops = [
                     ResOperation(opnum, [v1, v2], v_res),
-                    ResOperation(rop.GUARD_EXCEPTION, [c_ovferror], v_exc),
+                    ResOperation(rop.GUARD_OVERFLOW, [], None),
                     ResOperation(rop.FAIL, [], None),
                     ]
                 ops[1].suboperations = [ResOperation(rop.FAIL, [v_res], None)]
@@ -246,6 +240,7 @@
             for x, y, z in testcases:
                 assert not self.cpu.get_exception()
                 assert not self.cpu.get_exc_value()
+                assert not self.cpu.get_overflow_flag()
                 self.cpu.set_future_value_int(0, x)
                 self.cpu.set_future_value_int(1, y)
                 op = self.cpu.execute_operations(loop)
@@ -255,18 +250,9 @@
                     assert op is ops[-1]
                 if z != boom:
                     assert self.cpu.get_latest_value_int(0) == z
-                ovferror = self.cpu.get_exception()
-                assert bool(ovferror) == bool(self.cpu.get_exc_value())
-                if reversed:
-                    # in the 'reversed' case, ovferror should always be
-                    # consumed: either it is not set in the first place,
-                    # or it is set and GUARD_EXCEPTION succeeds.
-                    assert not ovferror
-                elif ovferror:
-                    assert z == boom
-                    self.cpu.clear_exception()
-                else:
-                    assert z != boom
+                assert not self.cpu.get_exception()
+                assert not self.cpu.get_exc_value()
+                assert not self.cpu.get_overflow_flag()
 
     def test_ovf_operations_reversed(self):
         self.test_ovf_operations(reversed=True)

Modified: pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/test/test_random.py
==============================================================================
--- pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/test/test_random.py	(original)
+++ pypy/branch/pyjitpl5-guardovf/pypy/jit/backend/test/test_random.py	Thu Aug 13 20:41:32 2009
@@ -184,7 +184,10 @@
         v_result = builder.do(self.opnum, args, descr=descr)
         if v_result is not None:
             builder.intvars.append(v_result)
-            if self.boolres:
+            boolres = self.boolres
+            if boolres == 'sometimes':
+                boolres = v_result.value in [0, 1]
+            if boolres:
                 builder.boolvars.append(v_result)
 
 class UnaryOperation(AbstractOperation):
@@ -228,20 +231,16 @@
         fail_subset = builder.subset_of_intvars(r)
         original_intvars = builder.intvars[:]
         super(AbstractOvfOperation, self).produce_into(builder, r)
-        exc = builder.cpu.get_exception()
-        assert bool(exc) == bool(builder.cpu.get_exc_value())
-        if exc:     # OverflowError
-            builder.cpu.clear_exception()
-            exc_box = ConstInt(exc)
-            res_box = BoxPtr()
-            op = ResOperation(rop.GUARD_EXCEPTION, [exc_box], res_box)
+        if builder.cpu.get_overflow_flag():   # overflow detected
+            builder.cpu.set_overflow_flag(False)
+            op = ResOperation(rop.GUARD_OVERFLOW, [], None)
             # the overflowed result should not be used any more, but can
             # be used on the failure path: recompute fail_subset including
             # the result, and then remove it from builder.intvars.
             fail_subset = builder.subset_of_intvars(r)
             builder.intvars[:] = original_intvars
         else:
-            op = ResOperation(rop.GUARD_NO_EXCEPTION, [], None)
+            op = ResOperation(rop.GUARD_NO_OVERFLOW, [], None)
         op.suboperations = [ResOperation(rop.FAIL, fail_subset, None)]
         builder.loop.operations.append(op)
 
@@ -322,7 +321,7 @@
 
 OPERATIONS.append(UnaryOperation(rop.INT_IS_TRUE, boolres=True))
 OPERATIONS.append(BooleanUnaryOperation(rop.BOOL_NOT, boolres=True))
-OPERATIONS.append(ConstUnaryOperation(rop.SAME_AS, boolres=True))
+OPERATIONS.append(ConstUnaryOperation(rop.SAME_AS, boolres='sometimes'))
 
 for _op in [rop.INT_ADD_OVF,
             rop.INT_SUB_OVF,



More information about the Pypy-commit mailing list