diff options
author | 2021-02-04 10:06:46 +0100 | |
---|---|---|
committer | 2021-02-04 10:06:46 +0100 | |
commit | 6d3aaef53a5f47a1fb2a3da71bd2be7918167bdf (patch) | |
tree | 4972e5d58813446bbd66f21ee26028efe3fe6658 | |
parent | remove unreachable code(?) (diff) | |
download | pypy-6d3aaef53a5f47a1fb2a3da71bd2be7918167bdf.tar.gz pypy-6d3aaef53a5f47a1fb2a3da71bd2be7918167bdf.tar.bz2 pypy-6d3aaef53a5f47a1fb2a3da71bd2be7918167bdf.zip |
use low-level interface where applicable, add at least a minimal hypothesis test for make_...
-rw-r--r-- | rpython/jit/metainterp/optimizeopt/intutils.py | 12 | ||||
-rw-r--r-- | rpython/jit/metainterp/optimizeopt/test/test_intbound.py | 22 |
2 files changed, 21 insertions, 13 deletions
diff --git a/rpython/jit/metainterp/optimizeopt/intutils.py b/rpython/jit/metainterp/optimizeopt/intutils.py index 281340fdc0..2590aad376 100644 --- a/rpython/jit/metainterp/optimizeopt/intutils.py +++ b/rpython/jit/metainterp/optimizeopt/intutils.py @@ -233,11 +233,11 @@ class IntBound(AbstractInfo): if other.is_constant(): val = other.getint() if val >= 0: # with Python's modulo: 0 <= (x % pos) < pos - r.make_ge(IntBound(0, 0)) - r.make_lt(IntBound(val, val)) + r.make_ge_const(0) + r.make_lt_const(val) else: # with Python's modulo: neg < (x % neg) <= 0 - r.make_gt(IntBound(val, val)) - r.make_le(IntBound(0, 0)) + r.make_gt_const(val) + r.make_le_const(0) return r def lshift_bound(self, other): @@ -274,7 +274,7 @@ class IntBound(AbstractInfo): pos2 = other.known_nonnegative() r = IntUnbounded() if pos1 or pos2: - r.make_ge(IntBound(0, 0)) + r.make_ge_const(0) if pos1: r.make_le(self) if pos2: @@ -289,7 +289,7 @@ class IntBound(AbstractInfo): mostsignificant = self.upper | other.upper r.intersect(IntBound(0, next_pow2_m1(mostsignificant))) else: - r.make_ge(IntBound(0, 0)) + r.make_ge_const(0) return r def contains(self, val): diff --git a/rpython/jit/metainterp/optimizeopt/test/test_intbound.py b/rpython/jit/metainterp/optimizeopt/test/test_intbound.py index ea243168e4..45b1635136 100644 --- a/rpython/jit/metainterp/optimizeopt/test/test_intbound.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_intbound.py @@ -48,13 +48,6 @@ def build_bound_with_contained_number(a, b, c): assert r.contains(b) return r, b -bound_with_contained_number = strategies.builds( - build_bound_with_contained_number, - ints_or_none, - ints_or_none, - ints -) - unbounded = strategies.builds( lambda x: (bound(None, None), int(x)), ints @@ -380,6 +373,21 @@ def test_next_pow2_m1(): @given(bound_with_contained_number, bound_with_contained_number) +def test_make_random(t1, t2): + def d(b): + return b.has_lower, b.lower, b.has_upper, b.upper + b1, n1 = t1 + b2, n2 = t2 + + for meth in [IntBound.make_le, IntBound.make_lt, IntBound.make_ge, IntBound.make_gt]: + b = b1.clone() + meth(b, b2) + data = d(b) + assert not meth(b, b2) + assert data == d(b) # idempotent + + +@given(bound_with_contained_number, bound_with_contained_number) def test_add_bound_random(t1, t2): b1, n1 = t1 b2, n2 = t2 |