[pypy-svn] r76629 - in pypy/branch/jit-bounds/pypy: jit/metainterp module/pypyjit/test
hakanardo at codespeak.net
hakanardo at codespeak.net
Sun Aug 15 21:44:30 CEST 2010
Author: hakanardo
Date: Sun Aug 15 21:44:28 2010
New Revision: 76629
Modified:
pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt.py
pypy/branch/jit-bounds/pypy/module/pypyjit/test/test_pypy_c.py
Log:
rpythonized, pypy-c tests
Modified: pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt.py (original)
+++ pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt.py Sun Aug 15 21:44:28 2010
@@ -18,7 +18,6 @@
from pypy.rpython.lltypesystem import lltype
from pypy.jit.metainterp.history import AbstractDescr, make_hashable_int
from pypy.rlib.rarithmetic import ovfcheck
-from copy import copy
def optimize_loop_1(metainterp_sd, loop):
"""Optimize loop.operations to make it match the input of loop.specnodes
@@ -40,6 +39,8 @@
# ____________________________________________________________
class IntBound(object):
+ _attrs_ = ('has_upper', 'has_lower', 'upper', 'lower')
+
def __init__(self, lower, upper):
self.has_upper = True
self.has_lower = True
@@ -103,7 +104,7 @@
return r
def add(self, offset):
- res = copy(self)
+ res = self.copy()
try:
res.lower = ovfcheck(res.lower + offset)
except OverflowError:
@@ -115,7 +116,7 @@
return res
def add_bound(self, other):
- res = copy(self)
+ res = self.copy()
if other.has_upper:
res.upper += other.upper
else:
@@ -127,7 +128,7 @@
return res
def sub_bound(self, other):
- res = copy(self)
+ res = self.copy()
if other.has_upper:
res.lower -= other.upper
else:
@@ -156,6 +157,11 @@
u = 'Inf'
return '%s <= x <= %s' % (l, u)
+ def copy(self):
+ res = IntBound(self.lower, self.upper)
+ res.has_lower = self.has_lower
+ res.has_upper = self.has_upper
+ return res
@@ -186,15 +192,15 @@
LEVEL_CONSTANT = '\x03'
class OptValue(object):
- _attrs_ = ('box', 'known_class', 'last_guard_index', 'level')
+ _attrs_ = ('box', 'known_class', 'last_guard_index', 'level', 'intbound')
last_guard_index = -1
level = LEVEL_UNKNOWN
known_class = None
+ intbound = None
- def __init__(self, box, producer=None):
+ def __init__(self, box):
self.box = box
- self.producer = producer
self.intbound = IntUnbounded()
if isinstance(box, Const):
self.make_constant(box)
@@ -1229,10 +1235,10 @@
r.intbound.intersect(v1.intbound.add_bound(v2.intbound))
# Synthesize the reverse op for optimize_default to reuse
- revop = ResOperation(rop.INT_SUB, (op.result, op.args[1]), \
+ revop = ResOperation(rop.INT_SUB, [op.result, op.args[1]], \
op.args[0], op.descr)
self.pure_operations[self.make_args_key(revop)] = revop
- revop = ResOperation(rop.INT_SUB, (op.result, op.args[0]), \
+ revop = ResOperation(rop.INT_SUB, [op.result, op.args[0]], \
op.args[1], op.descr)
self.pure_operations[self.make_args_key(revop)] = revop
Modified: pypy/branch/jit-bounds/pypy/module/pypyjit/test/test_pypy_c.py
==============================================================================
--- pypy/branch/jit-bounds/pypy/module/pypyjit/test/test_pypy_c.py (original)
+++ pypy/branch/jit-bounds/pypy/module/pypyjit/test/test_pypy_c.py Sun Aug 15 21:44:28 2010
@@ -118,6 +118,7 @@
assert result.splitlines()[-1].strip() == 'OK :-)'
self.parse_loops(logfilepath)
self.print_loops()
+ print logfilepath
if self.total_ops > expected_max_ops:
assert 0, "too many operations: got %d, expected maximum %d" % (
self.total_ops, expected_max_ops)
@@ -846,6 +847,112 @@
return intimg[i - 1]
''', maxops, ([tc], res))
+ def test_intbound(self):
+ ops = ('<', '>', '<=', '>=')
+ nbr = (3, 7)
+ for o1 in ops:
+ for o2 in ops:
+ for n1 in nbr:
+ for n2 in nbr:
+ src = '''
+ def f(i):
+ a, b = 3, 3
+ if i %s %d:
+ a = 0
+ else:
+ a = 1
+ if i %s %d:
+ b = 0
+ else:
+ b = 1
+ return a + b * 2
+
+ def main():
+ res = [0] * 4
+ for i in range(15) * 1500:
+ res[f(i)] += 1
+ return res
+
+ ''' % (o1, n1, o2, n2)
+
+ exec(str(py.code.Source(src)))
+ res = [0] * 4
+ for i in range(15):
+ res[f(i)] += 1500
+ self.run_source(src, 220, ([], res))
+
+ def test_intbound_addsub(self):
+ tests = ('i > 4', 'i > 2', 'i + 1 > 2', '1 + i > 4',
+ 'i - 1 > 1', '1 - i > 1', '1 - i < -3')
+ for t1 in tests:
+ for t2 in tests:
+ src = '''
+ def f(i):
+ a, b = 3, 3
+ if %s:
+ a = 0
+ else:
+ a = 1
+ if %s:
+ b = 0
+ else:
+ b = 1
+ return a + b * 2
+
+ def main():
+ res = [0] * 4
+ for i in range(15) * 1500:
+ res[f(i)] += 1
+ return res
+
+ ''' % (t1, t2)
+
+ exec(str(py.code.Source(src)))
+ res = [0] * 4
+ for i in range(15):
+ res[f(i)] += 1500
+ self.run_source(src, 232, ([], res))
+
+ def test_intbound_gt(self):
+ self.run_source('''
+ def main():
+ i, a, b = 0, 0, 0
+ while i < 2000:
+ if i > -1:
+ a += 1
+ if i > -2:
+ b += 1
+ i += 1
+ return (a, b)
+ ''', 48, ([], (2000, 2000)))
+
+
+ def test_intbound_addsub_ge(self):
+ self.run_source('''
+ def main():
+ i, a, b = 0, 0, 0
+ while i < 2000:
+ if i + 5 >= 5:
+ a += 1
+ #if i - 1 >= -1:
+ if i - 1 >= -1:
+ b += 1
+ i += 1
+ return (a, b)
+ ''', 0, ([], (2000, 2000)))
+
+ def test_intbound_sub_lt(self):
+ self.run_source('''
+ def main():
+ i, a, b = 0, 0, 0
+ while i < 2000:
+ if i - 10 < 1995:
+ a += 1
+ i += 1
+ return (a, b)
+ ''', 0, ([], (2000, 0)))
+
+
class AppTestJIT(PyPyCJITTests):
def setup_class(cls):
if not option.runappdirect:
More information about the Pypy-commit
mailing list