Commits

Maciej Fijalkowski committed 1244f49 Merge

merge heads

Comments (0)

Files changed (2)

pypy/jit/metainterp/test/test_ajit.py

                     found += 1
             assert found == 2
 
-    def test_loop_automatic_reds(self):
-        myjitdriver = JitDriver(greens = ['m'], reds = 'auto')
-        def f(n, m):
-            res = 0
-            # try to have lots of red vars, so that if there is an error in
-            # the ordering of reds, there are low chances that the test passes
-            # by chance
-            a = b = c = d = n
-            while n > 0:
-                myjitdriver.jit_merge_point(m=m)
-                n -= 1
-                a += 1 # dummy unused red
-                b += 2 # dummy unused red
-                c += 3 # dummy unused red
-                d += 4 # dummy unused red
-                res += m*2
-            return res
-        expected = f(21, 5)
-        res = self.meta_interp(f, [21, 5])
-        assert res == expected
-        self.check_resops(int_sub=2, int_mul=0, int_add=10)
-
-    def test_loop_automatic_reds_with_floats_and_refs(self):
-        myjitdriver = JitDriver(greens = ['m'], reds = 'auto')
-        class MyObj(object):
-            def __init__(self, val):
-                self.val = val
-        def f(n, m):
-            res = 0
-            # try to have lots of red vars, so that if there is an error in
-            # the ordering of reds, there are low chances that the test passes
-            # by chance
-            i1 = i2 = i3 = i4 = n
-            f1 = f2 = f3 = f4 = float(n)
-            r1 = r2 = r3 = r4 = MyObj(n)
-            while n > 0:
-                myjitdriver.jit_merge_point(m=m)
-                n -= 1
-                i1 += 1 # dummy unused red
-                i2 += 2 # dummy unused red
-                i3 += 3 # dummy unused red
-                i4 += 4 # dummy unused red
-                f1 += 1 # dummy unused red
-                f2 += 2 # dummy unused red
-                f3 += 3 # dummy unused red
-                f4 += 4 # dummy unused red
-                r1.val += 1 # dummy unused red
-                r2.val += 2 # dummy unused red
-                r3.val += 3 # dummy unused red
-                r4.val += 4 # dummy unused red
-                res += m*2
-            return res
-        expected = f(21, 5)
-        res = self.meta_interp(f, [21, 5])
-        assert res == expected
-        self.check_resops(int_sub=2, int_mul=0, int_add=18, float_add=8)
-
-    def test_loop_automatic_reds_livevars_before_jit_merge_point(self):
-        myjitdriver = JitDriver(greens = ['m'], reds = 'auto')
-        def f(n, m):
-            res = 0
-            while n > 0:
-                n -= 1
-                myjitdriver.jit_merge_point(m=m)
-                res += m*2
-            return res
-        expected = f(21, 5)
-        res = self.meta_interp(f, [21, 5])
-        assert res == expected
-        self.check_resops(int_sub=2, int_mul=0, int_add=2)
-
     def test_loop_variant_mul1(self):
         myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x'])
         def f(x, y):
                 i += 1
         res = self.meta_interp(f, [32])
         assert res == f(32)
-
-    def test_inline_in_portal(self):
-        myjitdriver = JitDriver(greens = [], reds = 'auto')
-        class MyRange(object):
-            def __init__(self, n):
-                self.cur = 0
-                self.n = n
-
-            def __iter__(self):
-                return self
-
-            @myjitdriver.inline_in_portal
-            def next(self):
-                myjitdriver.jit_merge_point()
-                if self.cur == self.n:
-                    raise StopIteration
-                self.cur += 1
-                return self.cur
-
-        def f(n, m):
-            res = 0
-            for i in MyRange(100):
-                res += i
-            return res
-        expected = f(21, 5)
-        res = self.meta_interp(f, [21, 5])
-        assert res == expected
-        self.check_resops(int_eq=2, int_add=4)
         
 class XXXDisabledTestOOtype(BasicTests, OOJitMixin):
 

pypy/jit/metainterp/test/test_warmspot.py

                            'int_sub': 2})
 
     def test_void_red_variable(self):
-        mydriver = JitDriver(greens=[], reds=['a', 'm'])
+        mydriver = JitDriver(greens=[], reds=['m'])
         def f1(m):
             a = None
             while m > 0:
-                mydriver.jit_merge_point(a=a, m=m)
+                mydriver.jit_merge_point(m=m)
                 m = m - 1
                 if m == 10:
                     pass   # other case
         self.meta_interp(f1, [18])
 
 
+    def test_loop_automatic_reds(self):
+        myjitdriver = JitDriver(greens = ['m'], reds = 'auto')
+        def f(n, m):
+            res = 0
+            # try to have lots of red vars, so that if there is an error in
+            # the ordering of reds, there are low chances that the test passes
+            # by chance
+            a = b = c = d = n
+            while n > 0:
+                myjitdriver.jit_merge_point(m=m)
+                n -= 1
+                a += 1 # dummy unused red
+                b += 2 # dummy unused red
+                c += 3 # dummy unused red
+                d += 4 # dummy unused red
+                res += m*2
+            return res
+        expected = f(21, 5)
+        res = self.meta_interp(f, [21, 5])
+        assert res == expected
+        self.check_resops(int_sub=2, int_mul=0, int_add=10)
+
+    def test_loop_automatic_reds_with_floats_and_refs(self):
+        myjitdriver = JitDriver(greens = ['m'], reds = 'auto')
+        class MyObj(object):
+            def __init__(self, val):
+                self.val = val
+        def f(n, m):
+            res = 0
+            # try to have lots of red vars, so that if there is an error in
+            # the ordering of reds, there are low chances that the test passes
+            # by chance
+            i1 = i2 = i3 = i4 = n
+            f1 = f2 = f3 = f4 = float(n)
+            r1 = r2 = r3 = r4 = MyObj(n)
+            while n > 0:
+                myjitdriver.jit_merge_point(m=m)
+                n -= 1
+                i1 += 1 # dummy unused red
+                i2 += 2 # dummy unused red
+                i3 += 3 # dummy unused red
+                i4 += 4 # dummy unused red
+                f1 += 1 # dummy unused red
+                f2 += 2 # dummy unused red
+                f3 += 3 # dummy unused red
+                f4 += 4 # dummy unused red
+                r1.val += 1 # dummy unused red
+                r2.val += 2 # dummy unused red
+                r3.val += 3 # dummy unused red
+                r4.val += 4 # dummy unused red
+                res += m*2
+            return res
+        expected = f(21, 5)
+        res = self.meta_interp(f, [21, 5])
+        assert res == expected
+        self.check_resops(int_sub=2, int_mul=0, int_add=18, float_add=8)
+
+    def test_loop_automatic_reds_livevars_before_jit_merge_point(self):
+        myjitdriver = JitDriver(greens = ['m'], reds = 'auto')
+        def f(n, m):
+            res = 0
+            while n > 0:
+                n -= 1
+                myjitdriver.jit_merge_point(m=m)
+                res += m*2
+            return res
+        expected = f(21, 5)
+        res = self.meta_interp(f, [21, 5])
+        assert res == expected
+        self.check_resops(int_sub=2, int_mul=0, int_add=2)
+
+    def test_inline_in_portal(self):
+        myjitdriver = JitDriver(greens = [], reds = 'auto')
+        class MyRange(object):
+            def __init__(self, n):
+                self.cur = 0
+                self.n = n
+
+            def __iter__(self):
+                return self
+
+            @myjitdriver.inline_in_portal
+            def next(self):
+                myjitdriver.jit_merge_point()
+                if self.cur == self.n:
+                    raise StopIteration
+                self.cur += 1
+                return self.cur
+
+        def one():
+            res = 0
+            for i in MyRange(10):
+                res += i
+            return res
+
+        def two():
+            res = 0
+            for i in MyRange(13):
+                res += i * 2
+            return res
+
+        def f(n, m):
+            res = one() * 100
+            res += two()
+            return res
+        expected = f(21, 5)
+        res = self.meta_interp(f, [21, 5])
+        assert res == expected
+        self.check_resops(int_eq=4, int_add=8)
+        self.check_trace_count(2)
+
 class TestLLWarmspot(WarmspotTests, LLJitMixin):
     CPUClass = runner.LLtypeCPU
     type_system = 'lltype'