[pypy-svn] r52705 - in pypy/branch/jit-hotpath/pypy/jit: rainbow/test timeshifter
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Mar 18 21:08:14 CET 2008
Author: cfbolz
Date: Tue Mar 18 21:08:10 2008
New Revision: 52705
Modified:
pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hp_vdict.py
pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_vdict.py
pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
pypy/branch/jit-hotpath/pypy/jit/timeshifter/vdict.py
Log:
write a merging test for dicts. fix fallback code for dicts
Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hp_vdict.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hp_vdict.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hp_vdict.py Tue Mar 18 21:08:10 2008
@@ -28,6 +28,29 @@
assert res == 34 * 11
self.check_insns_in_loops({'int_gt': 1, 'int_rshift': 1, 'int_add': 1})
+ def test_merge(self):
+ class MyJitDriver(JitDriver):
+ greens = []
+ reds = ['i', 'tot', 'flag']
+ def ll_function(flag):
+ tot = 0
+ i = 1024
+ while i > 0:
+ i >>= 1
+ dic = {}
+ if flag:
+ dic[12] = 34
+ else:
+ dic[12] = 35
+ dic[13] = 35
+ tot += dic[12]
+ MyJitDriver.jit_merge_point(tot=tot, i=i, flag=flag)
+ MyJitDriver.can_enter_jit(tot=tot, i=i, flag=flag)
+ return tot
+ res = self.run(ll_function, [True], 2, policy=P_OOPSPEC)
+ assert res == 34 * 11
+ self.check_insns_in_loops({'int_gt': 1, 'int_rshift': 1, 'int_add': 1})
+
def test_vdict_and_vlist(self):
class MyJitDriver(JitDriver):
greens = []
Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_vdict.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_vdict.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_vdict.py Tue Mar 18 21:08:10 2008
@@ -17,6 +17,20 @@
assert res == 34
self.check_insns({})
+ def test_merge(self):
+ def ll_function(flag):
+ dic = {}
+ if flag:
+ dic[12] = 34
+ else:
+ dic[12] = 35
+ dic[13] = 35
+ return dic[12]
+
+ res = self.interpret(ll_function, [True], [], policy=P_OOPSPEC)
+ assert res == 34
+ self.check_insns({})
+
def test_vdict_and_vlist(self):
def ll_function():
dic = {}
Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py Tue Mar 18 21:08:10 2008
@@ -956,7 +956,7 @@
def load_from(self, jitstate, gv_outside):
typedesc = self.typedesc
assert isinstance(typedesc, VirtualizableStructTypeDesc)
- # XXX missing check for gv_outside being NULL
+ assert self.content_boxes[-1].genvar is typedesc.gv_null
boxes = self.content_boxes
boxes[-1] = rvalue.PtrRedBox(boxes[-1].kind,
gv_outside,
Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/vdict.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/vdict.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/vdict.py Tue Mar 18 21:08:10 2008
@@ -126,6 +126,8 @@
keydesc = LLEqDesc(DICT.KEY, keyeq, keyhash)
self.VirtualDict = keydesc.VirtualDict
+ self._define_allocate()
+
def _freeze_(self):
return True
@@ -136,6 +138,27 @@
vdict.ownbox = box
return box
+ def _define_allocate(self):
+ from pypy.rpython.lltypesystem import rdict
+ DICT = self.DICT
+ DICTPTR = self.DICTPTR
+ KEY = DICT.KEY
+
+ def allocate(rgenop, n):
+ d = rdict.ll_newdict_size(DICT, n)
+ return rgenop.genconst(d)
+
+ def populate(item_boxes, gv_lst, box_gv_reader):
+ d = gv_lst.revealconst(DICTPTR)
+ for key, valuebox in item_boxes.iteritems():
+ if valuebox is not None:
+ gv_value = box_gv_reader(valuebox)
+ v = gv_value.revealconst(KEY)
+ rdict.ll_dict_setitem(key, v)
+
+ self.allocate = allocate
+ self.populate = populate
+
TypeDesc = DictTypeDesc
@@ -263,6 +286,12 @@
def internal_replace(self, memo):
raise NotImplementedError
+ def allocate_gv_container(self, rgenop):
+ return self.typedesc.allocate(rgenop, len(self.item_boxes))
+
+ def populate_gv_container(self, gv_dictptr, box_gv_reader):
+ return self.typedesc.populate(self.item_boxes,
+ gv_dictptr, box_gv_reader)
def oop_newdict(jitstate, oopspecdesc, deepfrozen):
return oopspecdesc.typedesc.factory()
More information about the Pypy-commit
mailing list