[pypy-svn] r64817 - in pypy/branch/pyjitpl5/pypy: annotation rpython rpython/lltypesystem translator/c/src translator/c/test translator/cli translator/jvm translator/test

arigo at codespeak.net arigo at codespeak.net
Wed Apr 29 18:17:27 CEST 2009


Author: arigo
Date: Wed Apr 29 18:17:20 2009
New Revision: 64817

Modified:
   pypy/branch/pyjitpl5/pypy/annotation/binaryop.py
   pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lloperation.py
   pypy/branch/pyjitpl5/pypy/rpython/rint.py
   pypy/branch/pyjitpl5/pypy/translator/c/src/int.h
   pypy/branch/pyjitpl5/pypy/translator/c/test/test_typed.py
   pypy/branch/pyjitpl5/pypy/translator/cli/opcodes.py
   pypy/branch/pyjitpl5/pypy/translator/jvm/opcodes.py
   pypy/branch/pyjitpl5/pypy/translator/test/test_simplify.py
Log:
Try to get rid of shifting operations that detect
a negative shift count and throw a ValueError,
i.e. int_[rl]shift_val and variants.


Modified: pypy/branch/pyjitpl5/pypy/annotation/binaryop.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/annotation/binaryop.py	(original)
+++ pypy/branch/pyjitpl5/pypy/annotation/binaryop.py	Wed Apr 29 18:17:20 2009
@@ -281,13 +281,19 @@
     and_.can_only_throw = []
 
     def lshift((int1, int2)):
-        return SomeInteger(knowntype=int1.knowntype)
-
-    lshift_ovf = _clone(lshift, [ValueError, OverflowError])
+        if isinstance(int1, SomeBool):
+            return SomeInteger()
+        else:
+            return SomeInteger(knowntype=int1.knowntype)
+    lshift.can_only_throw = []
+    lshift_ovf = _clone(lshift, [OverflowError])
 
     def rshift((int1, int2)):
-        return SomeInteger(nonneg=int1.nonneg, knowntype=int1.knowntype)
-    rshift.can_only_throw = [ValueError]
+        if isinstance(int1, SomeBool):
+            return SomeInteger(nonneg=True)
+        else:
+            return SomeInteger(nonneg=int1.nonneg, knowntype=int1.knowntype)
+    rshift.can_only_throw = []
 
     def pow((int1, int2), obj3):
         knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
@@ -361,16 +367,6 @@
     def gt(intint): return intint._compare_helper('gt', operator.gt)
     def ge(intint): return intint._compare_helper('ge', operator.ge)
 
-class __extend__(pairtype(SomeBool, SomeInteger)):
-    def lshift((int1, int2)):
-        return SomeInteger()
-
-    lshift.can_only_throw = [ValueError]
-    lshift_ovf = _clone(lshift, [ValueError, OverflowError])
-
-    def rshift((int1, int2)):
-        return SomeInteger(nonneg=True)
-    rshift.can_only_throw = [ValueError]
 
 class __extend__(pairtype(SomeBool, SomeBool)):
 

Modified: pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/lltypesystem/lloperation.py	Wed Apr 29 18:17:20 2009
@@ -189,9 +189,7 @@
     'int_and':              LLOp(canfold=True),
     'int_or':               LLOp(canfold=True),
     'int_lshift':           LLOp(canfold=True),
-    'int_lshift_val':       LLOp(canraise=(ValueError,), tryfold=True),
     'int_rshift':           LLOp(canfold=True),
-    'int_rshift_val':       LLOp(canraise=(ValueError,), tryfold=True),
     'int_xor':              LLOp(canfold=True),
 
     'int_add_ovf':          LLOp(canraise=(OverflowError,), tryfold=True),
@@ -207,8 +205,6 @@
     'int_mod_ovf_zer':      LLOp(canraise=(OverflowError, ZeroDivisionError),
                                                             tryfold=True),
     'int_lshift_ovf':       LLOp(canraise=(OverflowError,), tryfold=True),
-    'int_lshift_ovf_val':   LLOp(canraise=(OverflowError, ValueError,),
-                                                            tryfold=True),
 
     'uint_is_true':         LLOp(canfold=True),
     'uint_invert':          LLOp(canfold=True),
@@ -229,9 +225,7 @@
     'uint_and':             LLOp(canfold=True),
     'uint_or':              LLOp(canfold=True),
     'uint_lshift':          LLOp(canfold=True),
-    'uint_lshift_val':      LLOp(canraise=(ValueError,), tryfold=True),
     'uint_rshift':          LLOp(canfold=True),
-    'uint_rshift_val':      LLOp(canraise=(ValueError,), tryfold=True),
     'uint_xor':             LLOp(canfold=True),
 
     'float_is_true':        LLOp(canfold=True),
@@ -274,9 +268,7 @@
     'llong_and':            LLOp(canfold=True),
     'llong_or':             LLOp(canfold=True),
     'llong_lshift':         LLOp(canfold=True),
-    'llong_lshift_val':     LLOp(canraise=(ValueError,), tryfold=True),
     'llong_rshift':         LLOp(canfold=True),
-    'llong_rshift_val':     LLOp(canraise=(ValueError,), tryfold=True),
     'llong_xor':            LLOp(canfold=True),
 
     'ullong_is_true':       LLOp(canfold=True),
@@ -298,9 +290,7 @@
     'ullong_and':           LLOp(canfold=True),
     'ullong_or':            LLOp(canfold=True),
     'ullong_lshift':        LLOp(canfold=True),
-    'ullong_lshift_val':    LLOp(canraise=(ValueError,), tryfold=True),
     'ullong_rshift':        LLOp(canfold=True),
-    'ullong_rshift_val':    LLOp(canraise=(ValueError,), tryfold=True),
     'ullong_xor':           LLOp(canfold=True),
 
     'cast_primitive':       LLOp(canfold=True),

Modified: pypy/branch/pyjitpl5/pypy/rpython/rint.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/rint.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/rint.py	Wed Apr 29 18:17:20 2009
@@ -115,14 +115,14 @@
     rtype_inplace_or = rtype_or_
 
     def rtype_lshift(_, hop):
-        return _rtype_template(hop, 'lshift', [ValueError])
+        return _rtype_template(hop, 'lshift')
     rtype_inplace_lshift = rtype_lshift
 
     def rtype_lshift_ovf(_, hop):
-        return _rtype_template(hop, 'lshift_ovf', [ValueError])
+        return _rtype_template(hop, 'lshift_ovf')
 
     def rtype_rshift(_, hop):
-        return _rtype_template(hop, 'rshift', [ValueError])
+        return _rtype_template(hop, 'rshift')
     rtype_inplace_rshift = rtype_rshift
 
     def rtype_pow(_, hop):

Modified: pypy/branch/pyjitpl5/pypy/translator/c/src/int.h
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/c/src/int.h	(original)
+++ pypy/branch/pyjitpl5/pypy/translator/c/src/int.h	Wed Apr 29 18:17:20 2009
@@ -114,42 +114,6 @@
 	if ((x) != Py_ARITHMETIC_RIGHT_SHIFT(long, r, (y))) \
 		FAIL_OVF("x<<y losing bits or changing sign")
 
-/* the safe value-checking version of the above macros */
-
-#define OP_INT_RSHIFT_VAL(x,y,r) \
-	if ((y) >= 0) { OP_INT_RSHIFT(x,y,r); } \
-	else FAIL_VAL("negative shift count")
-#define OP_LLONG_RSHIFT_VAL(x,y,r) \
-	if ((y) >= 0) { OP_LLONG_RSHIFT(x,y,r); } \
-	else FAIL_VAL("negative shift count")
-
-#define OP_INT_LSHIFT_VAL(x,y,r) \
-	if ((y) >= 0) { OP_INT_LSHIFT(x,y,r); } \
-	else FAIL_VAL("negative shift count")
-#define OP_LLONG_LSHIFT_VAL(x,y,r) \
-	if ((y) >= 0) { OP_LLONG_LSHIFT(x,y,r); } \
-	else FAIL_VAL("negative shift count")
-
-#define OP_INT_LSHIFT_OVF_VAL(x,y,r) \
-	if ((y) >= 0) { OP_INT_LSHIFT_OVF(x,y,r); } \
-	else FAIL_VAL("negative shift count")
-
-/* pff */
-#define OP_UINT_LSHIFT_VAL(x,y,r) \
-	if ((y) >= 0) { OP_UINT_LSHIFT(x,y,r); } \
-	else FAIL_VAL("negative shift count")
-#define OP_ULLONG_LSHIFT_VAL(x,y,r) \
-	if ((y) >= 0) { OP_ULLONG_LSHIFT(x,y,r); } \
-	else FAIL_VAL("negative shift count")
-
-#define OP_UINT_RSHIFT_VAL(x,y,r) \
-	if ((y) >= 0) { OP_UINT_RSHIFT(x,y,r); } \
-	else FAIL_VAL("negative shift count")
-#define OP_ULLONG_RSHIFT_VAL(x,y,r) \
-	if ((y) >= 0) { OP_ULLONG_RSHIFT(x,y,r); } \
-	else FAIL_VAL("negative shift count")
-
-
 /* floor division */
 
 #define OP_INT_FLOORDIV(x,y,r)    r = (x) / (y)

Modified: pypy/branch/pyjitpl5/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/c/test/test_typed.py	(original)
+++ pypy/branch/pyjitpl5/pypy/translator/c/test/test_typed.py	Wed Apr 29 18:17:20 2009
@@ -480,13 +480,8 @@
         raises(OverflowError, fn, -1)
         raises(ZeroDivisionError, fn, 0)
 
-    def test_int_rshift_val(self):
-        fn = self.getcompiled(snippet.rshift_func, [int])
-        raises(ValueError, fn, -1)
-
-    def test_int_lshift_ovf_val(self):
+    def test_int_lshift_ovf(self):
         fn = self.getcompiled(snippet.lshift_func, [int])
-        raises(ValueError, fn, -1)
         raises(OverflowError, fn, 1)
 
     def test_int_unary_ovf(self):

Modified: pypy/branch/pyjitpl5/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/cli/opcodes.py	(original)
+++ pypy/branch/pyjitpl5/pypy/translator/cli/opcodes.py	Wed Apr 29 18:17:20 2009
@@ -179,8 +179,6 @@
 
     'int_lshift_ovf':           _check_ovf([PushArg(0),'conv.i8',PushArg(1), 'shl',
                                             'conv.ovf.i4', StoreResult]),
-    'int_lshift_ovf_val':       _check_ovf([PushArg(0),'conv.i8',PushArg(1), 'shl',
-                                            'conv.ovf.i4', StoreResult]),
 
     'int_rshift_ovf':           'shr', # these can't overflow!
     'int_xor_ovf':              'xor',

Modified: pypy/branch/pyjitpl5/pypy/translator/jvm/opcodes.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/jvm/opcodes.py	(original)
+++ pypy/branch/pyjitpl5/pypy/translator/jvm/opcodes.py	Wed Apr 29 18:17:20 2009
@@ -129,7 +129,6 @@
     'int_or_ovf':               jvm.IOR,
 
     'int_lshift_ovf':           jvm.ISHLOVF,
-    'int_lshift_ovf_val':       jvm.ISHLOVF, # VAL... what is val used for??
 
     'int_rshift_ovf':           jvm.ISHR, # these can't overflow!
     'int_xor_ovf':              jvm.IXOR,

Modified: pypy/branch/pyjitpl5/pypy/translator/test/test_simplify.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/test/test_simplify.py	(original)
+++ pypy/branch/pyjitpl5/pypy/translator/test/test_simplify.py	Wed Apr 29 18:17:20 2009
@@ -51,11 +51,13 @@
             return -42
     graph, _ = translate(f, [int])
     assert len(graph.startblock.operations) == 1
-    assert graph.startblock.operations[0].opname == 'int_lshift_ovf_val'
+    assert graph.startblock.operations[0].opname == 'int_lshift_ovf'
     assert len(graph.startblock.operations[0].args) == 2
-    assert len(graph.startblock.exits) == 3
+    assert len(graph.startblock.exits) == 2
+    assert [link.exitcase for link in graph.startblock.exits] == \
+           [None, OverflowError]
     assert [link.target.operations for link in graph.startblock.exits] == \
-           [(), (), ()]
+           [(), ()]
 
 def test_remove_ovfcheck_floordiv():
     # check that ovfcheck() is handled even if the operation raises



More information about the Pypy-commit mailing list