[pypy-svn] r65088 - pypy/branch/pyjitpl5/pypy/jit/backend/test

arigo at codespeak.net arigo at codespeak.net
Wed May 6 14:16:06 CEST 2009


Author: arigo
Date: Wed May  6 14:15:59 2009
New Revision: 65088

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/test/test_ll_random.py
   pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py
Log:
Support some INT_xxx_OVF operations.


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/test_ll_random.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/test_ll_random.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/test_ll_random.py	Wed May  6 14:15:59 2009
@@ -282,7 +282,6 @@
         descr = self.array_descr(builder, A)
         self.put(builder, [v], descr)
 
-# XXX why is the following here, and not in test_random?
 # there are five options in total:
 # 1. non raising call and guard_no_exception
 # 2. raising call and guard_exception

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py	Wed May  6 14:15:59 2009
@@ -1,5 +1,6 @@
 import py, sys
 from pypy.rlib.rarithmetic import intmask, LONG_BIT
+from pypy.rpython.lltypesystem import llmemory
 from pypy.jit.backend.test import conftest as demo_conftest
 from pypy.jit.metainterp.history import TreeLoop, BoxInt, ConstInt
 from pypy.jit.metainterp.history import BoxPtr, ConstPtr, ConstAddr
@@ -63,7 +64,6 @@
         num = int(k * len(self.intvars))
         for i in range(num):
             subset.append(r.choice(self.intvars))
-        r.shuffle(subset)
         return subset
 
     def process_operation(self, s, op, names, subops):
@@ -135,8 +135,9 @@
         #
         print >>s, '    cpu = CPU(None, None)'
         print >>s, "    loop = TreeLoop('test')"
-        print >>s, '    loop.inputargs = [...]' # % (
-            # ', '.join([names[v] for v in self.loop.inputargs]))
+        if hasattr(self.loop, 'inputargs'):
+            print >>s, '    loop.inputargs = [%s]' % (
+                ', '.join([names[v] for v in self.loop.inputargs]))
         print >>s, '    loop.operations = ['
         for op in self.loop.operations:
             self.process_operation(s, op, names, subops)
@@ -154,8 +155,10 @@
                 #print >>s, '        ResOperation(rop.FAIL, [%s], None)]' % (
                 #    ', '.join([names[v] for v in op.args]))
         print >>s, '    cpu.compile_operations(loop)'
-        #for i, v in enumerate(self.loop.inputargs):
-        #    print >>s, '    cpu.set_future_value_int(%d, %d)' % (i, v.value)
+        if hasattr(self.loop, 'inputargs'):
+            for i, v in enumerate(self.loop.inputargs):
+                print >>s, '    cpu.set_future_value_int(%d, %d)' % (i,
+                                                                     v.value)
         print >>s, '    op = cpu.execute_operations(loop)'
         if self.should_fail_by is None:
             for i, v in enumerate(self.loop.operations[-1].args):
@@ -216,6 +219,20 @@
             v_second = v
         self.put(builder, [v_first, v_second])
 
+class BinaryOvfOperation(BinaryOperation):
+    def produce_into(self, builder, r):
+        BinaryOperation.produce_into(self, builder, r)
+        exc = builder.cpu.get_exception()
+        if exc:     # OverflowError
+            builder.cpu.clear_exception()
+            exc_box = ConstInt(exc)
+            res_box = BoxPtr()
+            op = ResOperation(rop.GUARD_EXCEPTION, [exc_box], res_box)
+        else:
+            op = ResOperation(rop.GUARD_NO_EXCEPTION, [], None)
+        op.suboperations = [ResOperation(rop.FAIL, [], None)]
+        builder.loop.operations.append(op)
+
 class GuardOperation(AbstractOperation):
     def gen_guard(self, builder, r):
         v = builder.get_bool_var(r)
@@ -292,6 +309,21 @@
 OPERATIONS.append(UnaryOperation(rop.INT_IS_TRUE, boolres=True))
 OPERATIONS.append(BooleanUnaryOperation(rop.BOOL_NOT, boolres=True))
 
+for _op in [rop.INT_ADD_OVF,
+            rop.INT_SUB_OVF,
+            rop.INT_MUL_OVF,
+            ]:
+    OPERATIONS.append(BinaryOvfOperation(_op))
+
+OPERATIONS.append(BinaryOvfOperation(rop.INT_FLOORDIV_OVF, -1, 1))
+OPERATIONS.append(BinaryOvfOperation(rop.INT_MOD_OVF, -1, 1))
+OPERATIONS.append(BinaryOvfOperation(rop.INT_LSHIFT_OVF, LONG_BIT-1))
+
+for _op in [rop.INT_NEG_OVF,
+            rop.INT_ABS_OVF,
+            ]:
+    pass #OPERATIONS.append(UnaryOvfOperation(_op))
+
 OperationBuilder.OPERATIONS = OPERATIONS
 
 # ____________________________________________________________
@@ -395,7 +427,8 @@
         self.expected = {}
         for v in endvars:
             self.expected[v] = v.value
-        #builder.print_loop()
+        if demo_conftest.option.output:
+            builder.print_loop()
 
     def clear_state(self):
         for v, S, fields in self.prebuilt_ptr_consts:
@@ -409,21 +442,23 @@
     def run_loop(self):
         cpu = self.builder.cpu
         self.clear_state()
+        assert not cpu.get_exception()
 
         for i, v in enumerate(self.values):
             cpu.set_future_value_int(i, v)
         op = cpu.execute_operations(self.loop)
         assert op is self.should_fail_by
-        if (self.guard_op is not None and
-            self.guard_op.is_guard_exception()):
-            if cpu.get_exception():
-                cpu.clear_exception()
         for i, v in enumerate(op.args):
             value = cpu.get_latest_value_int(i)
             assert value == self.expected[v], (
                 "Got %d, expected %d" % (value,
                                          self.expected[v])
                 )
+        if (self.guard_op is not None and
+            self.guard_op.is_guard_exception()):
+            cpu.clear_exception()
+        else:
+            assert not cpu.get_exception()
 
     def build_bridge(self):
         def exc_handling(guard_op):



More information about the Pypy-commit mailing list