[pypy-svn] r52607 - in pypy/branch/jit-hotpath/pypy/jit/rainbow: . test

arigo at codespeak.net arigo at codespeak.net
Sun Mar 16 16:43:16 CET 2008


Author: arigo
Date: Sun Mar 16 16:43:16 2008
New Revision: 52607

Modified:
   pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hp_interpreter.py
Log:
Red switches (easy: just add hp_promote in front to make it a green switch)


Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/codewriter.py	Sun Mar 16 16:43:16 2008
@@ -452,7 +452,18 @@
             self.emit(*truerenaming)
             self.make_bytecode_block(linktrue.target, insert_goto=True)
         else:
-            assert self.varcolor(block.exitswitch) == "green"
+            if self.varcolor(block.exitswitch) == "green":
+                switchvaridx = self.serialize_oparg("green", block.exitswitch)
+            else:
+                assert self.hannotator.policy.hotpath
+                TYPE = block.exitswitch.concretetype
+                self.emit("hp_promote")
+                self.emit(self.serialize_oparg("red", block.exitswitch))
+                self.emit(self.promotiondesc_position(TYPE))
+                switchvaridx = self.register_greenvar(
+                    ("promoted", block.exitswitch),
+                    check=False)
+
             for link in block.exits:
                 if link.exitcase == 'default':
                     defaultlink = link
@@ -467,7 +478,7 @@
             cases = [self.serialize_oparg("green", case) for case in cases]
             targets = [tlabel(link) for link in switchlinks]
             self.emit("green_switch")
-            self.emit(self.serialize_oparg("green", block.exitswitch))
+            self.emit(switchvaridx)
             self.emit(len(cases), *cases)
             self.emit(len(targets), *targets)
             self.emit(*defaultrenaming)

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hp_interpreter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hp_interpreter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hp_interpreter.py	Sun Mar 16 16:43:16 2008
@@ -1722,6 +1722,9 @@
         self.check_insns_in_loops({'int_gt': 1, 'int_rshift': 1})
 
     def test_manual_marking_of_pure_functions(self):
+        class MyJitDriver(JitDriver):
+            greens = ['n']
+            reds = ['i', 'res']
         d = {}
         def h1(s):
             try:
@@ -1731,23 +1734,30 @@
                 return r
         h1._pure_function_ = True
         def f(n):
-            hint(None, global_merge_point=True)
-            hint(n, concrete=True)
-            if n == 0:
-                s = 123
-            else:
-                s = 567
-            a = h1(s)
-            return hint(a, variable=True)
+            i = 1024
+            while i > 0:
+                i >>= 1
+                #
+                hint(n, concrete=True)
+                if n == 0:
+                    s = 123
+                else:
+                    s = 567
+                a = h1(s)
+                res = hint(a, variable=True)
+                #
+                MyJitDriver.jit_merge_point(n=n, res=res, i=i)
+                MyJitDriver.can_enter_jit(n=n, res=res, i=i)
+            return res
 
         P = StopAtXPolicy(h1)
         P.oopspec = True
-        res = self.interpret(f, [0], [], policy=P)
+        res = self.run(f, [0], threshold=2, policy=P)
         assert res == 123 * 15
-        self.check_insns({})
-        res = self.interpret(f, [4], [], policy=P)
+        self.check_insns_in_loops({'int_gt': 1, 'int_rshift': 1})
+        res = self.run(f, [4], threshold=2, policy=P)
         assert res == 567 * 15
-        self.check_insns({})
+        self.check_insns_in_loops({'int_gt': 1, 'int_rshift': 1})
 
 
     def test_red_int_add_ovf(self):
@@ -1853,6 +1863,9 @@
         assert res == -7
 
     def test_switch(self):
+        class MyJitDriver(JitDriver):
+            greens = ['m']
+            reds = ['n', 'i', 'res']
         def g(n, x):
             if n == 0:
                 return 12 + x
@@ -1865,13 +1878,21 @@
             else:
                 return 90 + x
         def f(n, m):
-            x = g(n, n)   # gives a red switch
-            y = g(hint(m, concrete=True), n)   # gives a green switch
-            return x - y
+            i = 1024
+            while i > 0:
+                i >>= 1
+                #
+                x = g(n, n)   # gives a red switch
+                y = g(hint(m, concrete=True), n)   # gives a green switch
+                res = x - y
+                #
+                MyJitDriver.jit_merge_point(n=n, m=m, res=res, i=i)
+                MyJitDriver.can_enter_jit(n=n, m=m, res=res, i=i)
+            return res
 
-        res = self.interpret(f, [7, 2], backendoptimize=True)
+        res = self.run(f, [7, 2], threshold=2)
         assert res == 78 - 90
-        res = self.interpret(f, [8, 1], backendoptimize=True)
+        res = self.run(f, [8, 1], threshold=2)
         assert res == 90 - 34
 
     def test_switch_char(self):



More information about the Pypy-commit mailing list