[pypy-svn] r75291 - in pypy/branch/int-between/pypy: rpython/lltypesystem translator/c/src
arigo at codespeak.net
arigo at codespeak.net
Fri Jun 11 22:04:52 CEST 2010
Author: arigo
Date: Fri Jun 11 22:04:50 2010
New Revision: 75291
Modified:
pypy/branch/int-between/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/int-between/pypy/rpython/lltypesystem/opimpl.py
pypy/branch/int-between/pypy/rpython/lltypesystem/rclass.py
pypy/branch/int-between/pypy/translator/c/src/int.h
Log:
Add the lloperation 'int_between'. Use it only in rclass for now.
Implement it in the C backend.
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 Fri Jun 11 22:04:50 2010
@@ -227,6 +227,8 @@
'int_rshift': LLOp(canfold=True),
'int_xor': LLOp(canfold=True),
+ '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),
# ^^^ more efficient version when 2nd arg is nonneg
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 Fri Jun 11 22:04:50 2010
@@ -197,6 +197,12 @@
assert isinstance(y, int)
return intmask(x - y)
+def op_int_between(a, b, c):
+ 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
+
def op_int_and(x, y):
if not isinstance(x, int):
from pypy.rpython.lltypesystem import llgroup
Modified: pypy/branch/int-between/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/branch/int-between/pypy/rpython/lltypesystem/rclass.py (original)
+++ pypy/branch/int-between/pypy/rpython/lltypesystem/rclass.py Fri Jun 11 22:04:50 2010
@@ -22,6 +22,7 @@
from pypy.rlib.rarithmetic import intmask
from pypy.rlib import objectmodel
from pypy.lib.identity_dict import identity_dict
+from pypy.rpython.lltypesystem.lloperation import llop
#
# There is one "vtable" per user class, with the following structure:
@@ -645,10 +646,12 @@
return cast_pointer(OBJECTPTR, obj).typeptr
def ll_issubclass(subcls, cls):
- return cls.subclassrange_min <= subcls.subclassrange_min <= cls.subclassrange_max
+ return llop.int_between(Bool, cls.subclassrange_min,
+ subcls.subclassrange_min,
+ cls.subclassrange_max)
def ll_issubclass_const(subcls, minid, maxid):
- return minid <= subcls.subclassrange_min <= maxid
+ return llop.int_between(Bool, minid, subcls.subclassrange_min, maxid)
def ll_isinstance(obj, cls): # obj should be cast to OBJECT or NONGCOBJECT
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 Fri Jun 11 22:04:50 2010
@@ -47,6 +47,14 @@
#define OP_INT_LT(x,y,r) r = ((x) < (y))
#define OP_INT_GE(x,y,r) r = ((x) >= (y))
+/* Implement INT_BETWEEN by optimizing for the common case where a and c
+ are constants (the 2nd subtraction below is then constant-folded), or
+ for the case of a == 0 (both subtractions are then constant-folded).
+ 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))
+
/* addition, subtraction */
#define OP_INT_ADD(x,y,r) r = (x) + (y)
More information about the Pypy-commit
mailing list