[pypy-commit] pypy virtual-dicts: Started on them, really just as simple as unrolling lookup and setitem for virtual dicts with constant keys. Next step is to teach virtualize.py about {get, set}interiorfield_gc.
alex_gaynor
noreply at buildbot.pypy.org
Sat Oct 22 16:40:13 CEST 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: virtual-dicts
Changeset: r48342:15690256a200
Date: 2011-10-22 07:39 -0700
http://bitbucket.org/pypy/pypy/changeset/15690256a200/
Log: Started on them, really just as simple as unrolling lookup and
setitem for virtual dicts with constant keys. Next step is to teach
virtualize.py about {get,set}interiorfield_gc.
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
@@ -3435,7 +3435,20 @@
return sa
res = self.meta_interp(f, [16])
assert res == f(16)
-
+
+ def test_virtual_dict_constant_keys(self):
+ myjitdriver = JitDriver(greens = [], reds = ["n"])
+ def g(d):
+ return d["key"] - 1
+
+ def f(n):
+ while n > 0:
+ myjitdriver.jit_merge_point(n=n)
+ n = g({"key": n})
+ return n
+ res = self.meta_interp(f, [10])
+ assert res == 0
+ self.check_loops({"int_sub": 1, "int_gt": 1, "guard_true": 1, "jump": 1})
class TestLLtype(BaseLLtypeTests, LLJitMixin):
diff --git a/pypy/rpython/lltypesystem/rdict.py b/pypy/rpython/lltypesystem/rdict.py
--- a/pypy/rpython/lltypesystem/rdict.py
+++ b/pypy/rpython/lltypesystem/rdict.py
@@ -445,9 +445,9 @@
i = ll_dict_lookup(d, key, hash)
return _ll_dict_setitem_lookup_done(d, key, value, hash, i)
-# Leaving as dont_look_inside ATM, it has a few branches which could lead to
-# many bridges if we don't consider their possible frequency.
- at jit.dont_look_inside
+# It may be safe to look inside always, it has a few branches though, and their
+# frequencies needs to be investigated.
+ at jit.look_inside_iff(lambda d, key, value, hash, i: jit.isvirtual(d) and jit.isconstant(key))
def _ll_dict_setitem_lookup_done(d, key, value, hash, i):
valid = (i & HIGHEST_BIT) == 0
i = i & MASK
@@ -533,7 +533,7 @@
# ------- a port of CPython's dictobject.c's lookdict implementation -------
PERTURB_SHIFT = 5
- at jit.dont_look_inside
+ at jit.look_inside_iff(lambda d, key, hash: jit.isvirtual(d) and jit.isconstant(key))
def ll_dict_lookup(d, key, hash):
entries = d.entries
ENTRIES = lltype.typeOf(entries).TO
More information about the pypy-commit
mailing list