[pypy-commit] pypy ppc-jit-backend: Added test which checks independence of different loops which are compiled with the same assembler instance.

hager noreply at buildbot.pypy.org
Mon Sep 12 17:42:42 CEST 2011


Author: hager <sven.hager at uni-duesseldorf.de>
Branch: ppc-jit-backend
Changeset: r47232:328a1cc7f30c
Date: 2011-09-12 17:42 +0200
http://bitbucket.org/pypy/pypy/changeset/328a1cc7f30c/

Log:	Added test which checks independence of different loops which are
	compiled with the same assembler instance.

diff --git a/pypy/jit/backend/ppc/ppcgen/assembler.py b/pypy/jit/backend/ppc/ppcgen/assembler.py
--- a/pypy/jit/backend/ppc/ppcgen/assembler.py
+++ b/pypy/jit/backend/ppc/ppcgen/assembler.py
@@ -15,6 +15,11 @@
         self.labels = {}
         self.rlabels = {}
 
+    def reset(self):
+        self.insts = []
+        self.labels = {}
+        self.rlabels = {}
+
     def label(self, name):
         if name in self.labels:
             raise AssemblerException, "duplicate label '%s'"%(name,)
diff --git a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
--- a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
+++ b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
@@ -1075,6 +1075,7 @@
 
     def _teardown(self):
         self.patch_list = None
+        self.reset()
 
     # translate a trace operation to corresponding machine code
     def build_op(self, trace_op, cpu):
diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py
--- a/pypy/jit/backend/test/runner_test.py
+++ b/pypy/jit/backend/test/runner_test.py
@@ -192,6 +192,49 @@
         res = self.cpu.get_latest_value_int(2)
         assert res == 10
 
+    def test_independent_loops(self):
+        # first loop
+        i0_1 = BoxInt()
+        i1_1 = BoxInt()
+        i2_1 = BoxInt()
+        looptoken1 = LoopToken()
+        operations1 = [
+            ResOperation(rop.INT_ADD, [i0_1, ConstInt(1)], i1_1),
+            ResOperation(rop.INT_LE, [i1_1, ConstInt(9)], i2_1),
+            ResOperation(rop.GUARD_TRUE, [i2_1], None, descr=BasicFailDescr(2)),
+            ResOperation(rop.JUMP, [i1_1], None, descr=looptoken1),
+            ]
+        inputargs1 = [i0_1]
+        operations1[2].setfailargs([i1_1])
+        
+        self.cpu.compile_loop(inputargs1, operations1, looptoken1)
+        self.cpu.set_future_value_int(0, 2)
+        fail1 = self.cpu.execute_token(looptoken1)
+        assert fail1.identifier == 2
+        res1 = self.cpu.get_latest_value_int(0)
+        assert res1 == 10
+    
+        # second loop
+        i0_2 = BoxInt()
+        i1_2 = BoxInt()
+        i2_2 = BoxInt()
+        looptoken2 = LoopToken()
+        operations2 = [
+            ResOperation(rop.INT_ADD, [i0_2, ConstInt(1)], i1_2),
+            ResOperation(rop.INT_LE, [i1_2, ConstInt(19)], i2_2),
+            ResOperation(rop.GUARD_TRUE, [i2_2], None, descr=BasicFailDescr(2)),
+            ResOperation(rop.JUMP, [i1_2], None, descr=looptoken2),
+            ]
+        inputargs2 = [i0_2]
+        operations2[2].setfailargs([i1_2])
+        
+        self.cpu.compile_loop(inputargs2, operations2, looptoken2)
+        self.cpu.set_future_value_int(0, 2)
+        fail2 = self.cpu.execute_token(looptoken2)
+        assert fail2.identifier == 2
+        res2 = self.cpu.get_latest_value_int(0)
+        assert res2 == 20
+
     def test_backends_dont_keep_loops_alive(self):
         import weakref, gc
         self.cpu.dont_keepalive_stuff = True


More information about the pypy-commit mailing list