[pypy-svn] r75306 - in pypy/branch/int-between/pypy: jit/metainterp jit/metainterp/test rpython rpython/lltypesystem translator/c/src

arigo at codespeak.net arigo at codespeak.net
Sat Jun 12 10:01:15 CEST 2010


Author: arigo
Date: Sat Jun 12 10:01:13 2010
New Revision: 75306

Modified:
   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
   pypy/branch/int-between/pypy/rpython/lltypesystem/lloperation.py
   pypy/branch/int-between/pypy/rpython/lltypesystem/opimpl.py
   pypy/branch/int-between/pypy/rpython/normalizecalls.py
   pypy/branch/int-between/pypy/translator/c/src/int.h
Log:
Replace the meaning of 'int_between(a,b,c)' from 'a <= b <= c' to the more
Pythonic 'a <= b < c'.  This also has an advantage: rclass.ll_isinstance()
turns into int_between(a,b,a+1) for the case where the class has no subclass.
With the new definition this becomes equivalent to 'a==b'.



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	Sat Jun 12 10:01:13 2010
@@ -477,7 +477,7 @@
         return bool(a)
     @arguments("i", "i", "i", returns="i")
     def bhimpl_int_between(a, b, c):
-        return 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	Sat Jun 12 10:01:13 2010
@@ -319,7 +319,7 @@
     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)
+        return self.execute(rop.UINT_LT, b4, b5)
 
     @arguments("box", "descr", "orgpc")
     def opimpl_switch(self, valuebox, switchdict, orgpc):

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	Sat Jun 12 10:01:13 2010
@@ -581,30 +581,30 @@
             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', 'p', True,  int_sub=2, uint_lt=1)
+        check('n', 'p', 'm', False, int_sub=2, uint_lt=1)
         #
-        check('n', 'm', 6, True, int_sub=2, uint_le=1)
+        check('n', 'm', 6, False, int_sub=2, uint_lt=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', 4, 'p', False, int_sub=2, uint_lt=1)
+        check('n', 5, 'p', True,  int_sub=2, uint_lt=1)
+        check('n', 8, 'p', False, int_sub=2, uint_lt=1)
         #
-        check('n', 6, 7, True, int_sub=2, uint_le=1)
+        check('n', 6, 7, True, int_sub=2, uint_lt=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', 'p', True,  int_sub=2, uint_lt=1)
+        check(-2, 'm', 'p', True,  int_sub=2, uint_lt=1)
+        check(-2, 'p', 'm', False, int_sub=2, uint_lt=1)
+        #check(0, 'n', 'p', True,  uint_lt=1)   xxx implement me
+        #check(0, 'm', 'p', True,  uint_lt=1)
+        #check(0, 'p', 'm', False, uint_lt=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, 'n', 6, True,  int_sub=1, uint_lt=1)
+        check(2, 'm', 6, False, int_sub=1, uint_lt=1)
+        check(2, 'p', 6, False, int_sub=1, uint_lt=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, 6, 'm', False, int_sub=1, uint_lt=1)
+        check(2, 6, 'p', True,  int_sub=1, uint_lt=1)
         #
         check(2, 40, 6,  False)
         check(2, 40, 60, True)

Modified: pypy/branch/int-between/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/int-between/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/branch/int-between/pypy/rpython/lltypesystem/lloperation.py	Sat Jun 12 10:01:13 2010
@@ -227,7 +227,7 @@
     'int_rshift':           LLOp(canfold=True),
     'int_xor':              LLOp(canfold=True),
 
-    'int_between':          LLOp(canfold=True),   # a <= b <= c
+    'int_between':          LLOp(canfold=True),   # a <= b < c
 
     'int_add_ovf':          LLOp(canraise=(OverflowError,), tryfold=True),
     'int_add_nonneg_ovf':   LLOp(canraise=(OverflowError,), tryfold=True),

Modified: pypy/branch/int-between/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/branch/int-between/pypy/rpython/lltypesystem/opimpl.py	(original)
+++ pypy/branch/int-between/pypy/rpython/lltypesystem/opimpl.py	Sat Jun 12 10:01:13 2010
@@ -201,7 +201,7 @@
     assert lltype.typeOf(a) is lltype.Signed
     assert lltype.typeOf(b) is lltype.Signed
     assert lltype.typeOf(c) is lltype.Signed
-    return a <= b <= c
+    return a <= b < c
 
 def op_int_and(x, y):
     if not isinstance(x, int):

Modified: pypy/branch/int-between/pypy/rpython/normalizecalls.py
==============================================================================
--- pypy/branch/int-between/pypy/rpython/normalizecalls.py	(original)
+++ pypy/branch/int-between/pypy/rpython/normalizecalls.py	Sat Jun 12 10:01:13 2010
@@ -292,7 +292,7 @@
         else:
             return cmp(self.orderwitness, other.orderwitness)
 
-    # support for implementing int_between: (a<=b<=c) with (b-a<=c-a)
+    # support for implementing int_between: (a<=b<c) with (b-a<c-a)
     # see pypy.jit.metainterp.pyjitpl.opimpl_int_between
     def __sub__(self, other):
         return self.compute_fn() - other

Modified: pypy/branch/int-between/pypy/translator/c/src/int.h
==============================================================================
--- pypy/branch/int-between/pypy/translator/c/src/int.h	(original)
+++ pypy/branch/int-between/pypy/translator/c/src/int.h	Sat Jun 12 10:01:13 2010
@@ -53,7 +53,7 @@
    Note that the following line only works if a <= c in the first place,
    which we assume is true. */
 #define OP_INT_BETWEEN(a,b,c,r)   r = (((unsigned long)b - (unsigned long)a) \
-                                    <= ((unsigned long)c - (unsigned long)a))
+                                     < ((unsigned long)c - (unsigned long)a))
 
 /* addition, subtraction */
 



More information about the Pypy-commit mailing list