[pypy-svn] pypy default: (arigo, cfbolz): add an interface for int_between checks

cfbolz commits-noreply at bitbucket.org
Fri Feb 25 20:31:08 CET 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r42296:8afcf372c10d
Date: 2011-02-25 18:19 +0100
http://bitbucket.org/pypy/pypy/changeset/8afcf372c10d/

Log:	(arigo, cfbolz): add an interface for int_between checks

diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -881,3 +881,13 @@
         # we use cast_primitive to go between Float and SingleFloat.
         return hop.genop('cast_primitive', [v],
                          resulttype = lltype.SingleFloat)
+
+
+def int_between(n, m, p):
+    """ check that n <= m < p. This assumes that n <= p. This is useful because
+    the JIT special-cases it. """
+    from pypy.rpython.lltypesystem import lltype
+    from pypy.rpython.lltypesystem.lloperation import llop
+    if not objectmodel.we_are_translated():
+        assert n <= p
+    return llop.int_between(lltype.Bool, n, m, p)

diff --git a/pypy/rlib/test/test_rarithmetic.py b/pypy/rlib/test/test_rarithmetic.py
--- a/pypy/rlib/test/test_rarithmetic.py
+++ b/pypy/rlib/test/test_rarithmetic.py
@@ -523,3 +523,12 @@
     almost_equal(round_double(-0.5e22, -22), -1e22)
     almost_equal(round_double(0.5e22, -22), 1e22)
     almost_equal(round_double(1.5e22, -22), 2e22)
+
+def test_int_between():
+    assert int_between(1, 1, 3)
+    assert int_between(1, 2, 3)
+    assert not int_between(1, 0, 2)
+    assert not int_between(1, 5, 2)
+    assert not int_between(1, 2, 2)
+    assert not int_between(1, 1, 1)
+


More information about the Pypy-commit mailing list