[pypy-svn] r62190 - in pypy/branch/pyjitpl5/pypy/jit: backend/llgraph metainterp metainterp/test
arigo at codespeak.net
arigo at codespeak.net
Thu Feb 26 16:04:34 CET 2009
Author: arigo
Date: Thu Feb 26 16:04:34 2009
New Revision: 62190
Modified:
pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_exception.py
Log:
Add a few overflow-checking integer operations.
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py Thu Feb 26 16:04:34 2009
@@ -59,6 +59,9 @@
'int_ne' : (('int', 'int'), 'bool'),
'int_is_true' : (('int',), 'bool'),
'int_neg' : (('int',), 'int'),
+ 'int_add_ovf' : (('int', 'int'), 'int'),
+ 'int_sub_ovf' : (('int', 'int'), 'int'),
+ 'int_mul_ovf' : (('int', 'int'), 'int'),
'bool_not' : (('bool',), 'bool'),
'new_with_vtable' : (('int', 'ptr'), 'ptr'),
'new' : (('int',), 'ptr'),
@@ -802,17 +805,19 @@
items[i] = default_val
return res
- def op_cast_int_to_ptr(self, i):
- if i == 0:
- return dummy_null
- elif i == 1:
- return dummy_nonnull
- else:
- raise Exception("cast_int_to_ptr: got %d" % (i,))
-
-DUMMY = lltype.GcStruct('DUMMY')
-dummy_null = lltype.nullptr(DUMMY)
-dummy_nonnull = lltype.malloc(DUMMY, immortal=True)
+ for _opname in ['int_add_ovf', 'int_sub_ovf', 'int_mul_ovf',
+ ]:
+ exec py.code.Source('''
+ def op_%s(self, x, y):
+ try:
+ z = LLFrame.op_%s(self, x, y)
+ except LLException, e:
+ self.catch_exception(e)
+ z = 0
+ else:
+ self.clear_exception()
+ return z
+ ''' % (_opname, _opname)).compile()
# ____________________________________________________________
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py Thu Feb 26 16:04:34 2009
@@ -471,6 +471,9 @@
serialize_op_unichar_eq = serialize_op_char_eq
serialize_op_unichar_ne = serialize_op_char_ne
+ def serialize_op_int_add_nonneg_ovf(self, op):
+ self.default_serialize_op(op, 'int_add_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/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py Thu Feb 26 16:04:34 2009
@@ -235,6 +235,14 @@
self.execute(%r, [b1, b2], "int", True)
''' % (_opimpl, _opimpl)).compile()
+ for _opimpl in ['int_add_ovf', 'int_sub_ovf', 'int_mul_ovf',
+ ]:
+ exec py.code.Source('''
+ @arguments("box", "box")
+ def opimpl_%s(self, b1, b2):
+ return self.execute_with_exc(%r, [b1, b2], "int", True)
+ ''' % (_opimpl, _opimpl)).compile()
+
for _opimpl in ['int_is_true', 'int_neg', 'bool_not',
]:
exec py.code.Source('''
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_exception.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_exception.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_exception.py Thu Feb 26 16:04:34 2009
@@ -1,6 +1,7 @@
import py
from pypy.jit.metainterp.test.test_basic import LLJitMixin, OOJitMixin
from pypy.rlib.jit import JitDriver, hint
+from pypy.rlib.rarithmetic import ovfcheck
from pypy.jit.metainterp.policy import StopAtXPolicy
@@ -294,6 +295,20 @@
res = self.meta_interp(main, [13], policy=StopAtXPolicy(check))
assert res == 132
+ def test_int_ovf(self):
+ myjitdriver = JitDriver(greens = [], reds = ['n'])
+ def f(n):
+ try:
+ while 1:
+ myjitdriver.can_enter_jit(n=n)
+ myjitdriver.jit_merge_point(n=n)
+ n = ovfcheck(n * -3)
+ except OverflowError:
+ return n
+ expected = f(1)
+ res = self.meta_interp(f, [1])
+ assert res == expected
+
class MyError(Exception):
def __init__(self, n):
More information about the Pypy-commit
mailing list