[pypy-svn] pypy jit-unroll-loops: More jit friendly overflowcheck for integer divisions. This should produce one operation less in the common case where nothing is known about arguments but there is no OverflowError, and it should allow the entire overflowcheck to be removed in cases where there are intbounds on the arguments.

hakanardo commits-noreply at bitbucket.org
Tue Jan 4 20:58:26 CET 2011


Author: Hakan Ardo <hakan at debian.org>
Branch: jit-unroll-loops
Changeset: r40397:35a90606fa3b
Date: 2011-01-04 20:58 +0100
http://bitbucket.org/pypy/pypy/changeset/35a90606fa3b/

Log:	More jit friendly overflowcheck for integer divisions. This should
	produce one operation less in the common case where nothing is known
	about arguments but there is no OverflowError, and it should allow
	the entire overflowcheck to be removed in cases where there are
	intbounds on the arguments.

diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py
--- a/pypy/jit/codewriter/support.py
+++ b/pypy/jit/codewriter/support.py
@@ -178,12 +178,12 @@
 def _ll_2_int_floordiv_ovf_zer(x, y):
     if y == 0:
         raise ZeroDivisionError
-    if ((x + sys.maxint) & y) == -1:    # detect "x = -sys.maxint-1, y = -1".
+    if x == -sys.maxint - 1 and y == -1:
         raise OverflowError
     return llop.int_floordiv(lltype.Signed, x, y)
 
 def _ll_2_int_floordiv_ovf(x, y):
-    if ((x + sys.maxint) & y) == -1:    # detect "x = -sys.maxint-1, y = -1".
+    if x == -sys.maxint - 1 and y == -1:        
         raise OverflowError
     return llop.int_floordiv(lltype.Signed, x, y)
 
@@ -195,12 +195,12 @@
 def _ll_2_int_mod_ovf_zer(x, y):
     if y == 0:
         raise ZeroDivisionError
-    if ((x + sys.maxint) & y) == -1:    # detect "x = -sys.maxint-1, y = -1".
+    if x == -sys.maxint - 1 and y == -1:
         raise OverflowError
     return llop.int_mod(lltype.Signed, x, y)
 
 def _ll_2_int_mod_ovf(x, y):
-    if ((x + sys.maxint) & y) == -1:    # detect "x = -sys.maxint-1, y = -1".
+    if x == -sys.maxint - 1 and y == -1:
         raise OverflowError
     return llop.int_mod(lltype.Signed, x, y)
 


More information about the Pypy-commit mailing list