Author: Alex Gaynor <[email protected]>
Branch: float-bytes
Changeset: r53691:bf4509da496e
Date: 2012-03-15 11:06 -0700
http://bitbucket.org/pypy/pypy/changeset/bf4509da496e/
Log: initial jit support
diff --git a/pypy/jit/codewriter/jtransform.py
b/pypy/jit/codewriter/jtransform.py
--- a/pypy/jit/codewriter/jtransform.py
+++ b/pypy/jit/codewriter/jtransform.py
@@ -291,6 +291,11 @@
op1 = SpaceOperation('-live-', [], None)
return [op, op1]
+ def _noop_rewrite(self, op):
+ return op
+
+ rewrite_op_convert_float_bytes_to_longlong = _noop_rewrite
+
# ----------
# Various kinds of calls
diff --git a/pypy/jit/codewriter/test/test_flatten.py
b/pypy/jit/codewriter/test/test_flatten.py
--- a/pypy/jit/codewriter/test/test_flatten.py
+++ b/pypy/jit/codewriter/test/test_flatten.py
@@ -968,6 +968,15 @@
int_return %i2
""", transform=True)
+ def test_convert_float_bytes_to_int(self):
+ from pypy.rlib.longlong2float import float2longlong
+ def f(x):
+ return float2longlong(x)
+ self.encoding_test(f, [25.0], """
+ convert_float_bytes_to_longlong %f0 -> %i0
+ int_return %i0
+ """)
+
def check_force_cast(FROM, TO, operations, value):
"""Check that the test is correctly written..."""
diff --git a/pypy/jit/metainterp/blackhole.py b/pypy/jit/metainterp/blackhole.py
--- a/pypy/jit/metainterp/blackhole.py
+++ b/pypy/jit/metainterp/blackhole.py
@@ -1,15 +1,16 @@
+from pypy.jit.codewriter import heaptracker, longlong
+from pypy.jit.codewriter.jitcode import JitCode, SwitchDictDescr
+from pypy.jit.metainterp.compile import ResumeAtPositionDescr
+from pypy.jit.metainterp.jitexc import JitException, get_llexception, reraise
+from pypy.rlib import longlong2float
+from pypy.rlib.debug import debug_start, debug_stop, ll_assert,
make_sure_not_resized
+from pypy.rlib.objectmodel import we_are_translated
+from pypy.rlib.rarithmetic import intmask, LONG_BIT, r_uint, ovfcheck
+from pypy.rlib.rtimer import read_timestamp
from pypy.rlib.unroll import unrolling_iterable
-from pypy.rlib.rtimer import read_timestamp
-from pypy.rlib.rarithmetic import intmask, LONG_BIT, r_uint, ovfcheck
-from pypy.rlib.objectmodel import we_are_translated
-from pypy.rlib.debug import debug_start, debug_stop, ll_assert
-from pypy.rlib.debug import make_sure_not_resized
from pypy.rpython.lltypesystem import lltype, llmemory, rclass
from pypy.rpython.lltypesystem.lloperation import llop
-from pypy.jit.codewriter.jitcode import JitCode, SwitchDictDescr
-from pypy.jit.codewriter import heaptracker, longlong
-from pypy.jit.metainterp.jitexc import JitException, get_llexception, reraise
-from pypy.jit.metainterp.compile import ResumeAtPositionDescr
+
def arguments(*argtypes, **kwds):
resulttype = kwds.pop('returns', None)
@@ -663,6 +664,10 @@
a = float(a)
return longlong.getfloatstorage(a)
+ @arguments("f", returns="i")
+ def bhimpl_convert_float_bytes_to_longlong(a):
+ return longlong2float.float2longlong(a)
+
# ----------
# control flow operations
diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py
--- a/pypy/jit/metainterp/pyjitpl.py
+++ b/pypy/jit/metainterp/pyjitpl.py
@@ -223,6 +223,7 @@
'cast_float_to_singlefloat', 'cast_singlefloat_to_float',
'float_neg', 'float_abs',
'cast_ptr_to_int', 'cast_int_to_ptr',
+ 'convert_float_bytes_to_longlong',
]:
exec py.code.Source('''
@arguments("box")
diff --git a/pypy/jit/metainterp/resoperation.py
b/pypy/jit/metainterp/resoperation.py
--- a/pypy/jit/metainterp/resoperation.py
+++ b/pypy/jit/metainterp/resoperation.py
@@ -419,6 +419,7 @@
'CAST_INT_TO_FLOAT/1', # need some messy code in the backend
'CAST_FLOAT_TO_SINGLEFLOAT/1',
'CAST_SINGLEFLOAT_TO_FLOAT/1',
+ 'CONVERT_FLOAT_BYTES_TO_LONGLONG/1',
#
'INT_LT/2b',
'INT_LE/2b',
diff --git a/pypy/jit/metainterp/test/test_ajit.py
b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -14,6 +14,7 @@
loop_invariant, elidable, promote, jit_debug, assert_green,
AssertGreenFailed, unroll_safe, current_trace_length, look_inside_iff,
isconstant, isvirtual, promote_string, set_param, record_known_class)
+from pypy.rlib.longlong2float import float2longlong
from pypy.rlib.rarithmetic import ovfcheck, is_valid_int
from pypy.rpython.lltypesystem import lltype, llmemory, rffi
from pypy.rpython.ootypesystem import ootype
@@ -292,7 +293,7 @@
assert res == f(6, sys.maxint, 32, 48)
res = self.meta_interp(f, [sys.maxint, 6, 32, 48])
assert res == f(sys.maxint, 6, 32, 48)
-
+
def test_loop_invariant_intbox(self):
myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x'])
@@ -953,7 +954,7 @@
self.meta_interp(f, [20], repeat=7)
# the loop and the entry path as a single trace
self.check_jitcell_token_count(1)
-
+
# we get:
# ENTER - compile the new loop and the entry bridge
# ENTER - compile the leaving path
@@ -1470,7 +1471,7 @@
assert res == f(299)
self.check_resops(guard_class=0, guard_nonnull=4,
guard_nonnull_class=4, guard_isnull=2)
-
+
def test_merge_guardnonnull_guardvalue(self):
from pypy.rlib.objectmodel import instantiate
@@ -1499,7 +1500,7 @@
assert res == f(299)
self.check_resops(guard_value=4, guard_class=0, guard_nonnull=4,
guard_nonnull_class=0, guard_isnull=2)
-
+
def test_merge_guardnonnull_guardvalue_2(self):
from pypy.rlib.objectmodel import instantiate
@@ -1528,7 +1529,7 @@
assert res == f(299)
self.check_resops(guard_value=4, guard_class=0, guard_nonnull=4,
guard_nonnull_class=0, guard_isnull=2)
-
+
def test_merge_guardnonnull_guardclass_guardvalue(self):
from pypy.rlib.objectmodel import instantiate
@@ -2636,7 +2637,7 @@
return sa
assert self.meta_interp(f, [20]) == f(20)
self.check_resops(int_lt=6, int_le=2, int_ge=4, int_gt=3)
-
+
def test_intbounds_not_generalized2(self):
myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'node'])
@@ -2677,7 +2678,7 @@
assert self.meta_interp(f, [20, 3]) == f(20, 3)
self.check_jitcell_token_count(1)
self.check_target_token_count(5)
-
+
def test_max_retrace_guards(self):
myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'a'])
@@ -2815,7 +2816,7 @@
for cell in get_stats().get_all_jitcell_tokens():
# Initialal trace with two labels and 5 retraces
assert len(cell.target_tokens) <= 7
-
+
def test_nested_retrace(self):
myjitdriver = JitDriver(greens = ['pc'], reds = ['n', 'a', 'i', 'j',
'sa'])
@@ -3793,6 +3794,16 @@
res = self.interp_operations(g, [1])
assert res == 3
+ def test_float2longlong(self):
+ def f(n):
+ return float2longlong(n)
+
+ for x in [2.5, float("nan"), -2.5, float("inf")]:
+ # There are tests elsewhere to verify the correctness of this.
+ expected = float2longlong(x)
+ res = self.interp_operations(f, [x])
+ assert res == expected
+
class TestLLtype(BaseLLtypeTests, LLJitMixin):
def test_tagged(self):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit