Commits

Armin Rigo  committed 805e5d9

In progress.

  • Participants
  • Parent commits b02753f
  • Branches jit-tagged

Comments (0)

Files changed (6)

File pypy/jit/codewriter/support.py

 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:

File pypy/jit/metainterp/blackhole.py

         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")

File pypy/jit/metainterp/resoperation.py

     'GETARRAYITEM_GC_PURE/2d',
     'UNICODELEN/1',
     'UNICODEGETITEM/2',
+    'RERASED_IS_INTEGER/1',
     #
     # ootype operations
     #'INSTANCEOF/1db',

File pypy/jit/metainterp/simple_optimize.py

         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):

File pypy/jit/metainterp/test/test_basic.py

 
         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

File pypy/rlib/rerased.py

 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
         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 ----------
         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