[pypy-svn] r67538 - in pypy/trunk/pypy/jit: backend/llgraph backend/test metainterp metainterp/test
arigo at codespeak.net
arigo at codespeak.net
Sun Sep 6 00:05:47 CEST 2009
Author: arigo
Date: Sun Sep 6 00:05:46 2009
New Revision: 67538
Modified:
pypy/trunk/pypy/jit/backend/llgraph/llimpl.py
pypy/trunk/pypy/jit/backend/test/runner_test.py
pypy/trunk/pypy/jit/metainterp/executor.py
pypy/trunk/pypy/jit/metainterp/pyjitpl.py
pypy/trunk/pypy/jit/metainterp/resoperation.py
pypy/trunk/pypy/jit/metainterp/test/test_executor.py
pypy/trunk/pypy/jit/metainterp/test/test_pyjitpl.py
Log:
(pedronis, arigo)
Refactor tests about floats. Add the float comparisons and casts.
Modified: pypy/trunk/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/llgraph/llimpl.py (original)
+++ pypy/trunk/pypy/jit/backend/llgraph/llimpl.py Sun Sep 6 00:05:46 2009
@@ -87,6 +87,14 @@
'float_sub' : (('float', 'float'), 'float'),
'float_mul' : (('float', 'float'), 'float'),
'float_truediv' : (('float', 'float'), 'float'),
+ 'float_lt' : (('float', 'float'), 'int'),
+ 'float_le' : (('float', 'float'), 'int'),
+ 'float_eq' : (('float', 'float'), 'int'),
+ 'float_ne' : (('float', 'float'), 'int'),
+ 'float_gt' : (('float', 'float'), 'int'),
+ 'float_ge' : (('float', 'float'), 'int'),
+ 'cast_float_to_int':(('float',), 'int'),
+ 'cast_int_to_float':(('int',), 'float'),
'same_as' : (('int',), 'int'), # could also be ptr=>ptr
'new_with_vtable' : (('ref',), 'ref'),
'new' : ((), 'ref'),
Modified: pypy/trunk/pypy/jit/backend/test/runner_test.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/test/runner_test.py (original)
+++ pypy/trunk/pypy/jit/backend/test/runner_test.py Sun Sep 6 00:05:46 2009
@@ -219,22 +219,18 @@
'int')
assert res.value == y
- def _requires_floats(self):
- if not self.cpu.supports_floats:
- py.test.skip("requires float support from the backend")
-
- def test_float_binary_operations(self):
- self._requires_floats()
- for opnum, testcases in [
- (rop.FLOAT_ADD, [(10.5, -2.25, 8.25)]),
- (rop.FLOAT_SUB, [(10.5, -2.25, 12.75)]),
- (rop.FLOAT_MUL, [(-6.5, -3.5, 22.75)]),
- (rop.FLOAT_TRUEDIV, [(118.75, 12.5, 9.5)]),
- ]:
- for x, y, z in testcases:
- res = self.execute_operation(opnum, [BoxFloat(x), BoxFloat(y)],
- 'float')
- assert res.value == z
+ def test_float_operations(self):
+ from pypy.jit.metainterp.test.test_executor import get_float_tests
+ for opnum, boxargs, rettype, retvalue in get_float_tests(self.cpu):
+ if len(boxargs) == 2:
+ args_variants = [(boxargs[0], boxargs[1]),
+ (boxargs[0], boxargs[1].constbox()),
+ (boxargs[0].constbox(), boxargs[1])]
+ else:
+ args_variants = [boxargs]
+ for argboxes in args_variants:
+ res = self.execute_operation(opnum, argboxes, rettype)
+ assert res.value == retvalue
def test_ovf_operations(self, reversed=False):
minint = -sys.maxint-1
Modified: pypy/trunk/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/executor.py (original)
+++ pypy/trunk/pypy/jit/metainterp/executor.py Sun Sep 6 00:05:46 2009
@@ -256,6 +256,12 @@
def do_float_ge(cpu, args, descr=None):
return ConstInt(args[0].getfloat() >= args[1].getfloat())
+def do_cast_float_to_int(cpu, args, descr=None):
+ return ConstInt(int(args[0].getfloat()))
+
+def do_cast_int_to_float(cpu, args, descr=None):
+ return ConstFloat(float(args[0].getint()))
+
# ____________________________________________________________
def do_debug_merge_point(cpu, args, descr=None):
Modified: pypy/trunk/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/trunk/pypy/jit/metainterp/pyjitpl.py Sun Sep 6 00:05:46 2009
@@ -228,6 +228,8 @@
'int_rshift', 'int_lshift', 'uint_rshift',
'uint_lt', 'uint_le', 'uint_gt', 'uint_ge',
'float_add', 'float_sub', 'float_mul', 'float_truediv',
+ 'float_lt', 'float_le', 'float_eq',
+ 'float_ne', 'float_gt', 'float_ge',
]:
exec py.code.Source('''
@arguments("box", "box")
@@ -244,7 +246,8 @@
''' % (_opimpl, _opimpl.upper())).compile()
for _opimpl in ['int_is_true', 'int_neg', 'int_invert', 'bool_not',
- 'cast_ptr_to_int',
+ 'cast_ptr_to_int', 'cast_float_to_int',
+ 'cast_int_to_float',
]:
exec py.code.Source('''
@arguments("box")
@@ -471,9 +474,8 @@
def opimpl_ptr_iszero(self, box):
self.execute(rop.OOISNULL, [box])
- @arguments("box")
- def opimpl_oononnull(self, box):
- self.execute(rop.OONONNULL, [box])
+ opimpl_oononnull = opimpl_ptr_nonzero
+ opimpl_ooisnull = opimpl_ptr_iszero
@arguments("box", "box")
def opimpl_ptr_eq(self, box1, box2):
@@ -484,6 +486,7 @@
self.execute(rop.OOISNOT, [box1, box2])
opimpl_oois = opimpl_ptr_eq
+ opimpl_ooisnot = opimpl_ptr_ne
@arguments("box", "descr")
def opimpl_getfield_gc(self, box, fielddesc):
Modified: pypy/trunk/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/resoperation.py (original)
+++ pypy/trunk/pypy/jit/metainterp/resoperation.py Sun Sep 6 00:05:46 2009
@@ -142,6 +142,8 @@
'FLOAT_SUB',
'FLOAT_MUL',
'FLOAT_TRUEDIV',
+ 'CAST_FLOAT_TO_INT',
+ 'CAST_INT_TO_FLOAT',
#
'_COMPARISON_FIRST',
'INT_LT',
@@ -155,6 +157,12 @@
'UINT_GT',
'UINT_GE',
'_COMPARISON_LAST',
+ 'FLOAT_LT', # maybe these ones should be comparisons too
+ 'FLOAT_LE',
+ 'FLOAT_EQ',
+ 'FLOAT_NE',
+ 'FLOAT_GT',
+ 'FLOAT_GE',
#
'INT_IS_TRUE',
'INT_NEG',
Modified: pypy/trunk/pypy/jit/metainterp/test/test_executor.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_executor.py (original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_executor.py Sun Sep 6 00:05:46 2009
@@ -1,3 +1,4 @@
+import py
from pypy.jit.metainterp.executor import make_execute_list, execute
from pypy.jit.metainterp.resoperation import rop
from pypy.jit.metainterp.history import BoxInt, ConstInt
@@ -6,7 +7,7 @@
class FakeCPU(AbstractCPU):
- pass
+ supports_floats = True
make_execute_list(FakeCPU)
@@ -14,13 +15,52 @@
box = execute(FakeCPU(), rop.INT_ADD, [BoxInt(40), ConstInt(2)])
assert box.value == 42
+def _float_binary_operations():
+ for opnum, testcases in [
+ (rop.FLOAT_ADD, [(10.5, -2.25, 8.25)]),
+ (rop.FLOAT_SUB, [(10.5, -2.25, 12.75)]),
+ (rop.FLOAT_MUL, [(-6.5, -3.5, 22.75)]),
+ (rop.FLOAT_TRUEDIV, [(118.75, 12.5, 9.5)]),
+ ]:
+ for x, y, z in testcases:
+ yield (opnum, [x, y], 'float', z)
+
+def _float_comparison_operations():
+ for y in [-522.25, 10.125, 22.6]:
+ yield (rop.FLOAT_LT, [10.125, y], 'int', 10.125 < y)
+ yield (rop.FLOAT_LE, [10.125, y], 'int', 10.125 <= y)
+ yield (rop.FLOAT_EQ, [10.125, y], 'int', 10.125 == y)
+ yield (rop.FLOAT_NE, [10.125, y], 'int', 10.125 != y)
+ yield (rop.FLOAT_GT, [10.125, y], 'int', 10.125 > y)
+ yield (rop.FLOAT_GE, [10.125, y], 'int', 10.125 >= y)
+
+def _float_unary_operations():
+ yield (rop.CAST_FLOAT_TO_INT, [-5.9], 'int', -5)
+ yield (rop.CAST_FLOAT_TO_INT, [5.9], 'int', 5)
+ yield (rop.CAST_INT_TO_FLOAT, [123], 'float', 123.0)
+
+def get_float_tests(cpu):
+ if not cpu.supports_floats:
+ py.test.skip("requires float support from the backend")
+ for opnum, args, rettype, retvalue in (
+ list(_float_binary_operations()) +
+ list(_float_comparison_operations()) +
+ list(_float_unary_operations())):
+ boxargs = []
+ for x in args:
+ if isinstance(x, float):
+ boxargs.append(BoxFloat(x))
+ else:
+ boxargs.append(BoxInt(x))
+ yield opnum, boxargs, rettype, retvalue
+
def test_float_ops():
cpu = FakeCPU()
- box = execute(cpu, rop.FLOAT_ADD, [BoxFloat(40.5), ConstFloat(2.25)])
- assert box.value == 42.75
- box = execute(cpu, rop.FLOAT_SUB, [BoxFloat(40.5), ConstFloat(2.25)])
- assert box.value == 38.25
- box = execute(cpu, rop.FLOAT_MUL, [BoxFloat(40.5), ConstFloat(2.25)])
- assert box.value == 91.125
- box = execute(cpu, rop.FLOAT_TRUEDIV, [BoxFloat(10.125), ConstFloat(2.25)])
- assert box.value == 4.5
+ for opnum, boxargs, rettype, retvalue in get_float_tests(cpu):
+ box = execute(cpu, opnum, boxargs)
+ if rettype == 'float':
+ assert box.getfloat() == retvalue
+ elif rettype == 'int':
+ assert box.getint() == retvalue
+ else:
+ assert retvalue is None
Modified: pypy/trunk/pypy/jit/metainterp/test/test_pyjitpl.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_pyjitpl.py (original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_pyjitpl.py Sun Sep 6 00:05:46 2009
@@ -1,7 +1,7 @@
# some unit tests for the bytecode decoding
-from pypy.jit.metainterp import pyjitpl, codewriter
+from pypy.jit.metainterp import pyjitpl, codewriter, resoperation
def make_frame(code):
bytecode = codewriter.JitCode("hello")
@@ -24,3 +24,11 @@
frame = make_frame("\x01")
assert frame.load_bool()
+
+def test_simple_opimpl_exist():
+ rop = resoperation.rop
+ for opnum, opname in resoperation.opname.items():
+ if opnum in (rop.SAME_AS, rop.CALL_PURE, rop.OOSEND_PURE):
+ continue
+ if rop._NOSIDEEFFECT_FIRST <= opnum <= rop._NOSIDEEFFECT_LAST:
+ assert hasattr(pyjitpl.MIFrame, 'opimpl_' + opname.lower()), opname
More information about the Pypy-commit
mailing list