[pypy-svn] pypy jit-tagged: In progress.
arigo
commits-noreply at bitbucket.org
Mon Dec 20 13:20:49 CET 2010
Author: Armin Rigo <arigo at tunes.org>
Branch: jit-tagged
Changeset: r40144:805e5d981821
Date: 2010-12-20 10:36 +0100
http://bitbucket.org/pypy/pypy/changeset/805e5d981821/
Log: In progress.
diff --git a/pypy/jit/metainterp/simple_optimize.py b/pypy/jit/metainterp/simple_optimize.py
--- a/pypy/jit/metainterp/simple_optimize.py
+++ b/pypy/jit/metainterp/simple_optimize.py
@@ -20,6 +20,9 @@
op = ResOperation(rop.SAME_AS, [op.getarg(0)], op.result)
elif op.getopnum() == rop.VIRTUAL_REF_FINISH:
return []
+ elif op.getopnum() == rop.RERASED_IS_INTEGER:
+ xxx
+ return []
return [op]
def optimize_loop(metainterp_sd, old_loops, loop):
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
@@ -440,6 +440,7 @@
'GETARRAYITEM_GC_PURE/2d',
'UNICODELEN/1',
'UNICODEGETITEM/2',
+ 'RERASED_IS_INTEGER/1',
#
# ootype operations
#'INSTANCEOF/1db',
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
@@ -866,6 +866,14 @@
pass
# ----------
+ # tagged pointers
+
+ @arguments("r", returns="i")
+ def bhimpl_rerased_is_integer(a):
+ from pypy.rlib.rerased import is_integer
+ return is_integer(a)
+
+ # ----------
# list operations
@arguments("cpu", "r", "d", "i", returns="i")
diff --git a/pypy/jit/metainterp/test/test_basic.py b/pypy/jit/metainterp/test/test_basic.py
--- a/pypy/jit/metainterp/test/test_basic.py
+++ b/pypy/jit/metainterp/test/test_basic.py
@@ -1885,5 +1885,36 @@
self.meta_interp(main, [])
+ def test_rerased_is_integer(self):
+ from pypy.rlib import rerased
+ driver = JitDriver(greens = [], reds = ['n', 'm'])
+ class X:
+ pass
+ def g(n):
+ if n > 5:
+ return rerased.erase(X())
+ else:
+ return rerased.erase(42)
+ def h(x):
+ return rerased.is_integer(x)
+ def f(n, m):
+ while True:
+ driver.jit_merge_point(n=n, m=m)
+ x = g(n)
+ res = h(x)
+ m -= 1
+ if m < 0:
+ return res
+
+ res = self.meta_interp(f, [10, 10], optimizer=OPTIMIZER_SIMPLE)
+ assert res == False
+ res = self.meta_interp(f, [3, 10], optimizer=OPTIMIZER_SIMPLE)
+ assert res == True
+
+ res = self.meta_interp(f, [10, 10])
+ assert res == False
+ self.check_loops(new_with_vtable=0)
+
+
class TestLLtype(BaseLLtypeTests, LLJitMixin):
pass
diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py
--- a/pypy/jit/codewriter/support.py
+++ b/pypy/jit/codewriter/support.py
@@ -174,6 +174,10 @@
def _ll_1_jit_force_virtual(inst):
return llop.jit_force_virtual(lltype.typeOf(inst), inst)
+def _ll_1_rerased_is_integer(inst):
+ from pypy.rlib import rerased
+ return rerased.is_integer(inst)
+
def _ll_2_int_floordiv_ovf_zer(x, y):
if y == 0:
diff --git a/pypy/rlib/rerased.py b/pypy/rlib/rerased.py
--- a/pypy/rlib/rerased.py
+++ b/pypy/rlib/rerased.py
@@ -5,6 +5,7 @@
import sys
from pypy.annotation import model as annmodel
from pypy.tool.pairtype import pairtype
+from pypy.rlib.objectmodel import we_are_translated
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.rpython.rclass import getinstancerepr
from pypy.rpython.rmodel import Repr
@@ -48,10 +49,14 @@
assert isinstance(y._x[0], type)
return y._x
-def is_integer(e):
+def ll_is_integer(e):
"""Gives information whether the erased argument is a tagged integer or not."""
- return isinstance(e._x, int)
-is_integer.oopspec = 'rerased.is_integer(e)'
+ if we_are_translated():
+ return (llop.cast_ptr_to_int(lltype.Signed, e) & 1) != 0
+ else:
+ return isinstance(e._x, int)
+ll_is_integer.oopspec = 'rerased.is_integer(e)'
+is_integer = ll_is_integer
# ---------- implementation-specific ----------
@@ -118,21 +123,6 @@
v, t = hop.inputargs(hop.args_r[0], lltype.Void)
return hop.genop('cast_opaque_ptr', [v], resulttype = hop.r_result)
-
-class Entry(ExtRegistryEntry):
- _about_ = is_integer
-
- def compute_result_annotation(self, s_obj):
- return annmodel.SomeBool()
-
- def specialize_call(self, hop):
- v, = hop.inputargs(hop.args_r[0])
- c_one = hop.inputconst(lltype.Signed, 1)
- vi = hop.genop('cast_ptr_to_int', [v], resulttype=lltype.Signed)
- vb = hop.genop('int_and', [vi, c_one], resulttype=lltype.Signed)
- return hop.genop('int_is_true', [vb], resulttype=lltype.Bool)
-
-
class Entry(ExtRegistryEntry):
_type_ = Erased
More information about the Pypy-commit
mailing list