[pypy-svn] r63656 - in pypy/branch/pyjitpl5-simplify/pypy/jit: backend/llgraph backend/test metainterp metainterp/test
fijal at codespeak.net
fijal at codespeak.net
Sun Apr 5 04:33:21 CEST 2009
Author: fijal
Date: Sun Apr 5 04:33:16 2009
New Revision: 63656
Modified:
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_exception.py
Log:
implement int_lshift and int_lshift_ovf (no support so far in x86 backend)
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py Sun Apr 5 04:33:16 2009
@@ -73,6 +73,7 @@
'int_sub_ovf' : (('int', 'int'), 'int'),
'int_mul_ovf' : (('int', 'int'), 'int'),
'int_neg_ovf' : (('int',), 'int'),
+ 'int_lshift_ovf' : (('int', 'int'), 'int'),
'bool_not' : (('bool',), 'bool'),
'uint_add' : (('int', 'int'), 'int'),
'uint_sub' : (('int', 'int'), 'int'),
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py Sun Apr 5 04:33:16 2009
@@ -74,7 +74,14 @@
[BoxPtr(x)], 'int').value
res2 = self.execute_operation(rop.CAST_INT_TO_PTR,
[BoxInt(res)], 'ptr').value
- assert res2 == x
+ assert res2 == x
+
+ def test_lshift(self):
+ res = execute(self.cpu, rop.INT_LSHIFT, [BoxInt(10), ConstInt(4)])
+ assert res.value == 10 << 4
+ res = self.execute_operation(rop.INT_LSHIFT, [BoxInt(10), BoxInt(4)],
+ 'int')
+ assert res.value == 10 << 4
def test_uint_xor(self):
x = execute(self.cpu, rop.UINT_XOR, [BoxInt(100), ConstInt(4)])
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py Sun Apr 5 04:33:16 2009
@@ -517,6 +517,8 @@
_defl = default_serialize_op
def serialize_op_char_eq(self, op): self._defl(op, 'int_eq')
def serialize_op_char_ne(self, op): self._defl(op, 'int_ne')
+ def serialize_op_char_le(self, op): self._defl(op, 'int_le')
+ def serialize_op_char_lt(self, op): self._defl(op, 'int_lt')
serialize_op_unichar_eq = serialize_op_char_eq
serialize_op_unichar_ne = serialize_op_char_ne
@@ -528,6 +530,14 @@
# XXX handle ZeroDivisionError
self.default_serialize_op(op, 'int_mod_ovf')
+ def setialize_op_int_floordiv_ovf_zer(self, op):
+ # XXX handle ZeroDivisionError
+ self.default_serialize_op(op, 'int_floordiv_ovf')
+
+ def serialize_op_int_lshift_ovf_val(self, op):
+ # XXX handle ValueError
+ self.default_serialize_op(op, 'int_lshift_ovf')
+
def serialize_op_hint(self, op):
hints = op.args[1].value
if hints.get('promote') and op.args[0].concretetype is not lltype.Void:
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py Sun Apr 5 04:33:16 2009
@@ -186,6 +186,16 @@
z = 0
return BoxInt(z)
+def do_int_lshift_ovf(cpu, args, descr=None):
+ x = args[0].getint()
+ y = args[1].getint()
+ try:
+ z = ovfcheck(x << y)
+ except OverflowError:
+ cpu.set_overflow_error()
+ z = 0
+ return BoxInt(z)
+
# ____________________________________________________________
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py Sun Apr 5 04:33:16 2009
@@ -246,7 +246,7 @@
''' % (_opimpl, _opimpl.upper())).compile()
for _opimpl in ['int_add_ovf', 'int_sub_ovf', 'int_mul_ovf', 'int_mod_ovf',
- ]:
+ 'int_lshift_ovf']:
exec py.code.Source('''
@arguments("box", "box")
def opimpl_%s(self, b1, b2):
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py Sun Apr 5 04:33:16 2009
@@ -179,7 +179,8 @@
INT_MUL_OVF = 112
INT_NEG_OVF = 113
INT_MOD_OVF = 114
- _OVF_LAST = 114
+ INT_LSHIFT_OVF = 115
+ _OVF_LAST = 115
_CANRAISE_LAST = 119 # ----- end of can_raise operations -----
_LAST = 119 # for the backend to add more internal operations
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_exception.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_exception.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_exception.py Sun Apr 5 04:33:16 2009
@@ -321,6 +321,22 @@
res = self.interp_operations(f, [1, 2])
assert res == 1
+ def test_int_lshift_ovf(self):
+ myjitdriver = JitDriver(greens = [], reds = ['n', 'x', 'y'])
+ def f(x, y, n):
+ while n < 100:
+ myjitdriver.can_enter_jit(n=n, x=x, y=y)
+ myjitdriver.jit_merge_point(n=n, x=x, y=y)
+ y += 1
+ try:
+ ovfcheck(x<<y)
+ except OverflowError:
+ return 2
+ n += 1
+ return n
+
+ res = self.meta_interp(f, [1, 1, 0])
+ assert res == f(1, 1, 0)
def test_reraise_through_portal(self):
jitdriver = JitDriver(greens = [], reds = ['n'])
More information about the Pypy-commit
mailing list