Author: Carl Friedrich Bolz <[email protected]>
Branch: optinfo-into-bridges-2
Changeset: r90271:38359f83e374
Date: 2017-02-21 15:41 +0100
http://bitbucket.org/pypy/pypy/changeset/38359f83e374/
Log: - some more fixes
- make the storage in Reader be unencoded
diff --git a/rpython/jit/metainterp/resume.py b/rpython/jit/metainterp/resume.py
--- a/rpython/jit/metainterp/resume.py
+++ b/rpython/jit/metainterp/resume.py
@@ -13,7 +13,8 @@
from rpython.rtyper.rclass import OBJECTPTR
from rpython.jit.metainterp.walkvirtual import VirtualVisitor
from rpython.jit.metainterp import resumecode
-TagOverflow = resumecode.TagOverflow
+from rpython.jit.metainterp.resumecode import TagOverflow
+
# Logic to encode the chain of frames and the state of the boxes at a
@@ -563,8 +564,8 @@
raise TagOverflow
#
rd_pendingfields[i].lldescr = lldescr
- rd_pendingfields[i].num = num
- rd_pendingfields[i].fieldnum = fieldnum
+ rd_pendingfields[i].num = rffi.r_short(num)
+ rd_pendingfields[i].fieldnum = rffi.r_short(fieldnum)
rd_pendingfields[i].itemindex = rffi.cast(rffi.INT, itemindex)
self.storage.rd_pendingfields = rd_pendingfields
diff --git a/rpython/jit/metainterp/resumecode.py
b/rpython/jit/metainterp/resumecode.py
--- a/rpython/jit/metainterp/resumecode.py
+++ b/rpython/jit/metainterp/resumecode.py
@@ -1,7 +1,7 @@
""" Resume bytecode. It goes as following:
# ----- resume section
- [total size of resume section, unencoded]
+ [total size of resume section]
[<length> <virtualizable object> <numb> <numb> <numb>] if vinfo is not
None
-OR-
[1 <ginfo object>] if ginfo is not
None
@@ -99,29 +99,29 @@
class Writer(object):
def __init__(self, size=0):
- self.current = objectmodel.newlist_hint(3 * size)
- self.grow(size)
- self.items = 0
+ self.current = objectmodel.newlist_hint( size)
def append_int(self, item):
- self.items += 1
- append_numbering(self.current, item)
+ """ append an item. return the position of the item """
+ if not integer_fits(item):
+ raise TagOverflow
+ self.current.append(item)
+ return len(self.current) - 1
def create_numbering(self):
- numb = lltype.malloc(NUMBERING, len(self.current))
- for i, elt in enumerate(self.current):
+ l = []
+ for item in self.current:
+ append_numbering(l, item)
+ numb = lltype.malloc(NUMBERING, len(l))
+ for i, elt in enumerate(l):
numb.code[i] = elt
return numb
- def grow(self, size):
- pass
+ def patch_current_size(self, index):
+ self.patch(index, len(self.current))
- def patch_current_size(self, index):
- # mess :-(
- assert self.current[index] == 0
- l = []
- append_numbering(l, self.items)
- self.current = l + self.current[1:]
+ def patch(self, index, item):
+ self.current[index] = item
def create_numbering(l):
diff --git a/rpython/jit/metainterp/test/test_resume.py
b/rpython/jit/metainterp/test/test_resume.py
--- a/rpython/jit/metainterp/test/test_resume.py
+++ b/rpython/jit/metainterp/test/test_resume.py
@@ -113,19 +113,19 @@
def test_tag():
assert tag(3, 1) == 3<<2|1
assert tag(-3, 2) == -3<<2|2
- assert tag((1<<13)-1, 3) == ((1<<15)-1)|3
- assert tag(-1<<13, 3) ==(-1<<15)|3
+ assert tag((1<<19)-1, 3) == ((1<<21)-1)|3
+ assert tag(-1<<19, 3) ==(-1<<21)|3
py.test.raises(AssertionError, tag, 3, 5)
- py.test.raises(TagOverflow, tag, 1<<13, 0)
- py.test.raises(TagOverflow, tag, (1<<13)+1, 0)
- py.test.raises(TagOverflow, tag, (-1<<13)-1, 0)
- py.test.raises(TagOverflow, tag, (-1<<13)-5, 0)
+ py.test.raises(TagOverflow, tag, 1<<19, 0)
+ py.test.raises(TagOverflow, tag, (1<<19)+1, 0)
+ py.test.raises(TagOverflow, tag, (-1<<19)-1, 0)
+ py.test.raises(TagOverflow, tag, (-1<<19)-5, 0)
def test_untag():
assert untag(tag(3, 1)) == (3, 1)
assert untag(tag(-3, 2)) == (-3, 2)
- assert untag(tag((1<<13)-1, 3)) == ((1<<13)-1, 3)
- assert untag(tag(-1<<13, 3)) == (-1<<13, 3)
+ assert untag(tag((1<<19)-1, 3)) == ((1<<19)-1, 3)
+ assert untag(tag(-1<<19, 3)) == (-1<<19, 3)
def test_tagged_eq():
assert tagged_eq(UNASSIGNED, UNASSIGNED)
@@ -776,12 +776,12 @@
assert untag(tagged) == (44, TAGINT)
tagged = memo.getconst(ConstInt(-3))
assert untag(tagged) == (-3, TAGINT)
- const = ConstInt(50000)
+ const = ConstInt(1<<20)
tagged = memo.getconst(const)
index, tagbits = untag(tagged)
assert tagbits == TAGCONST
assert memo.consts[index - TAG_CONST_OFFSET] is const
- tagged = memo.getconst(ConstInt(50000))
+ tagged = memo.getconst(ConstInt(1<<20))
index2, tagbits = untag(tagged)
assert tagbits == TAGCONST
assert index2 == index
@@ -1081,7 +1081,7 @@
_next_section(reader, sys.maxint, 2**16, -65)
def test_virtual_adder_memo_const_sharing():
- b1s, b2s, b3s = [ConstInt(sys.maxint), ConstInt(2**16), ConstInt(-65)]
+ b1s, b2s, b3s = [ConstInt(sys.maxint), ConstInt(2**22), ConstInt(-65)]
storage, t = make_storage(b1s, b2s, b3s)
metainterp_sd = FakeMetaInterpStaticData()
memo = ResumeDataLoopMemo(metainterp_sd)
@@ -1091,7 +1091,7 @@
assert len(memo.consts) == 2
assert storage.rd_consts is memo.consts
- b1s, b2s, b3s = [ConstInt(sys.maxint), ConstInt(2**17), ConstInt(-65)]
+ b1s, b2s, b3s = [ConstInt(sys.maxint), ConstInt(2**23), ConstInt(-65)]
storage2, t = make_storage(b1s, b2s, b3s)
i = t.get_iter()
modifier2 = ResumeDataVirtualAdder(FakeOptimizer(i), storage2, storage2,
@@ -1497,14 +1497,12 @@
self.got_array = got_array
def setfield(self, struct, fieldnum, descr):
assert lltype.typeOf(struct) is lltype.Signed
- assert lltype.typeOf(fieldnum) is rffi.SHORT
- fieldnum = rffi.cast(lltype.Signed, fieldnum)
+ assert lltype.typeOf(fieldnum) is lltype.Signed
self.got.append((descr, struct, fieldnum))
def setarrayitem(self, array, index, fieldnum, arraydescr):
assert lltype.typeOf(array) is lltype.Signed
assert lltype.typeOf(index) is lltype.Signed
- assert lltype.typeOf(fieldnum) is rffi.SHORT
- fieldnum = rffi.cast(lltype.Signed, fieldnum)
+ assert lltype.typeOf(fieldnum) is lltype.Signed
self.got_array.append((arraydescr, array, index, fieldnum))
def decode_ref(self, num):
return rffi.cast(lltype.Signed, num) * 100
diff --git a/rpython/jit/metainterp/test/test_resumecode.py
b/rpython/jit/metainterp/test/test_resumecode.py
--- a/rpython/jit/metainterp/test/test_resumecode.py
+++ b/rpython/jit/metainterp/test/test_resumecode.py
@@ -20,8 +20,10 @@
[13000, 12000, 10000, 256, 255, 254, 257, -3, -1000]
]
+codelists = strategies.lists(strategies.integers(-2**21, 2**21-1), min_size=1)
+
def hypothesis_and_examples(func):
- func = given(strategies.lists(strategies.integers(-2**21, 2**21-1)))(func)
+ func = given(codelists)(func)
for ex in examples:
func = example(ex)(func)
return func
@@ -55,7 +57,7 @@
assert unpack_numbering(n) == l
@hypothesis_and_examples
-def test_patch(l):
+def test_patch_current_size(l):
for middle in range(len(l)):
l1 = l[:middle]
l2 = l[middle:]
@@ -70,4 +72,18 @@
assert unpack_numbering(n)[1:] == l
assert unpack_numbering(n)[0] == middle + 1
+@hypothesis_and_examples
+def test_patch(l):
+ item = l[0]
+ l = l[1:]
+ for middle in range(len(l)):
+ output = l[:]
+ output[middle] = item
+ w = Writer(len(l))
+ for i, num in enumerate(l):
+ index = w.append_int(num)
+ assert index == i
+ w.patch(middle, item)
+ n = w.create_numbering()
+ assert unpack_numbering(n) == output
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit