[pypy-svn] r75292 - in pypy/branch/int-between/pypy/jit: codewriter/test metainterp metainterp/test

arigo at codespeak.net arigo at codespeak.net
Fri Jun 11 22:41:46 CEST 2010


Author: arigo
Date: Fri Jun 11 22:41:45 2010
New Revision: 75292

Modified:
   pypy/branch/int-between/pypy/jit/codewriter/test/test_flatten.py
   pypy/branch/int-between/pypy/jit/metainterp/blackhole.py
   pypy/branch/int-between/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/int-between/pypy/jit/metainterp/test/test_basic.py
Log:
Implement int_between in the jit.


Modified: pypy/branch/int-between/pypy/jit/codewriter/test/test_flatten.py
==============================================================================
--- pypy/branch/int-between/pypy/jit/codewriter/test/test_flatten.py	(original)
+++ pypy/branch/int-between/pypy/jit/codewriter/test/test_flatten.py	Fri Jun 11 22:41:45 2010
@@ -715,3 +715,12 @@
             uint_le %i2, $456L -> %i3
             int_return %i3
         """, transform=True)
+
+    def test_int_between(self):
+        from pypy.rpython.lltypesystem.lloperation import llop
+        def f(n, m, p):
+            return llop.int_between(lltype.Bool, n, m, p)
+        self.encoding_test(f, [5, 6, 7], """
+            int_between %i0, %i1, %i2 -> %i3
+            int_return %i3
+        """, transform=True)

Modified: pypy/branch/int-between/pypy/jit/metainterp/blackhole.py
==============================================================================
--- pypy/branch/int-between/pypy/jit/metainterp/blackhole.py	(original)
+++ pypy/branch/int-between/pypy/jit/metainterp/blackhole.py	Fri Jun 11 22:41:45 2010
@@ -475,6 +475,9 @@
     @arguments("i", returns="i")
     def bhimpl_int_is_true(a):
         return bool(a)
+    @arguments("i", "i", "i", returns="i")
+    def bhimpl_int_between(a, b, c):
+        return a <= b <= c
 
     @arguments("i", "i", returns="i")
     def bhimpl_uint_lt(a, b):

Modified: pypy/branch/int-between/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/int-between/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/int-between/pypy/jit/metainterp/pyjitpl.py	Fri Jun 11 22:41:45 2010
@@ -315,6 +315,12 @@
         if value:
             self.pc = target
 
+    @arguments("box", "box", "box")
+    def opimpl_int_between(self, b1, b2, b3):
+        b4 = self.execute(rop.INT_SUB, b2, b1)
+        b5 = self.execute(rop.INT_SUB, b3, b1)
+        return self.execute(rop.UINT_LE, b4, b5)
+
     @arguments("box", "descr", "orgpc")
     def opimpl_switch(self, valuebox, switchdict, orgpc):
         box = self.implement_guard_value(orgpc, valuebox)

Modified: pypy/branch/int-between/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/int-between/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/int-between/pypy/jit/metainterp/test/test_basic.py	Fri Jun 11 22:41:45 2010
@@ -145,6 +145,9 @@
 
     def check_operations_history(self, expected=None, **isns):
         # this can be used after interp_operations
+        if expected is not None:
+            expected = dict(expected)
+            expected['jump'] = 1
         self.metainterp.staticdata.stats.check_history(expected, **isns)
 
 
@@ -548,6 +551,51 @@
                                       int_le=0, uint_le=1,
                                       int_sub=1)
 
+    def test_int_between(self):
+        #
+        def check(arg1, arg2, arg3, expect_result, **expect_operations):
+            from pypy.rpython.lltypesystem import lltype
+            from pypy.rpython.lltypesystem.lloperation import llop
+            loc = locals().copy()
+            exec py.code.Source("""
+                def f(n, m, p):
+                    arg1 = %(arg1)s
+                    arg2 = %(arg2)s
+                    arg3 = %(arg3)s
+                    return llop.int_between(lltype.Bool, arg1, arg2, arg3)
+            """ % locals()).compile() in loc
+            res = self.interp_operations(loc['f'], [5, 6, 7])
+            assert res == expect_result
+            self.check_operations_history(expect_operations)
+        #
+        check('n', 'm', 'p', True,  int_sub=2, uint_le=1)
+        check('n', 'p', 'm', False, int_sub=2, uint_le=1)
+        #
+        check('n', 'm', 6, True, int_sub=2, uint_le=1)
+        #
+        check('n', 4, 'p', False, int_sub=2, uint_le=1)
+        check('n', 5, 'p', True,  int_sub=2, uint_le=1)
+        check('n', 8, 'p', False, int_sub=2, uint_le=1)
+        #
+        check('n', 6, 7, True, int_sub=2, uint_le=1)
+        #
+        check(-2, 'n', 'p', True,  int_sub=2, uint_le=1)
+        check(-2, 'm', 'p', True,  int_sub=2, uint_le=1)
+        check(-2, 'p', 'm', False, int_sub=2, uint_le=1)
+        #check(0, 'n', 'p', True,  uint_le=1)   xxx implement me
+        #check(0, 'm', 'p', True,  uint_le=1)
+        #check(0, 'p', 'm', False, uint_le=1)
+        #
+        check(2, 'n', 6, True,  int_sub=1, uint_le=1)
+        check(2, 'm', 6, True,  int_sub=1, uint_le=1)
+        check(2, 'p', 6, False, int_sub=1, uint_le=1)
+        #
+        check(2, 6, 'n', False, int_sub=1, uint_le=1)
+        check(2, 6, 'm', True,  int_sub=1, uint_le=1)
+        #
+        check(2, 40, 6,  False)
+        check(2, 40, 60, True)
+
     def test_getfield(self):
         class A:
             pass



More information about the Pypy-commit mailing list