[pypy-commit] pypy vlen-resume: (fijal, cfbolz, arigo)
arigo
pypy.commits at gmail.com
Sun Feb 21 11:55:07 EST 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: vlen-resume
Changeset: r82371:a3dc1d20dc0f
Date: 2016-02-21 16:39 +0100
http://bitbucket.org/pypy/pypy/changeset/a3dc1d20dc0f/
Log: (fijal, cfbolz, arigo)
work in progress
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
@@ -1147,7 +1147,7 @@
end = first_snapshot_size - len(virtualizable_boxes)
elif ginfo is not None:
item, self.cur_index = resumecode.numb_next_item(self.numb,
- first_snapshot_size - 1)
+ first_snapshot_size - 1)xxxxxxxxxxxxx
virtualizable_boxes = [self.decode_ref(item)]
end = first_snapshot_size - 1
else:
@@ -1483,7 +1483,7 @@
if vinfo is not None:
end_vref = self.consume_vable_info(vinfo)
if ginfo is not None:
- end_vref -= 1
+ end_vref -= 1 xxxxxxxxxxxxxxx
self.consume_virtualref_info(vrefinfo, end_vref)
self.cur_index = rffi.cast(lltype.Signed, self.numb.first_snapshot_size)
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
@@ -20,77 +20,64 @@
# ('prev', NUMBERINGP),
# ('prev_index', rffi.USHORT),
('first_snapshot_size', rffi.USHORT), # ugh, ugly
- ('code', lltype.Array(rffi.SHORT)))
+ ('code', lltype.Array(rffi.UCHAR)))
NUMBERINGP.TO.become(NUMBERING)
NULL_NUMBER = lltype.nullptr(NUMBERING)
# this is the actually used version
+## def create_numbering(lst, first_snapshot_size):
+## numb = lltype.malloc(NUMBERING, len(lst))
+## for i in range(len(lst)):
+## numb.code[i] = rffi.cast(rffi.SHORT, lst[i])
+## numb.first_snapshot_size = rffi.cast(rffi.USHORT, first_snapshot_size)
+## return numb
+
+## def numb_next_item(numb, index):
+## return rffi.cast(lltype.Signed, numb.code[index]), index + 1
+
+# this is the version that can be potentially used
+
def create_numbering(lst, first_snapshot_size):
- numb = lltype.malloc(NUMBERING, len(lst))
- for i in range(len(lst)):
- numb.code[i] = rffi.cast(rffi.SHORT, lst[i])
+ result = []
+ for item in lst:
+ item *= 2
+ if item < 0:
+ item = -1 - item
+
+ assert item >= 0
+ if item < 2**7:
+ result.append(rffi.cast(rffi.UCHAR, item))
+ elif item < 2**14:
+ result.append(rffi.cast(rffi.UCHAR, item | 0x80))
+ result.append(rffi.cast(rffi.UCHAR, item >> 7))
+ else:
+ assert item < 2**16
+ result.append(rffi.cast(rffi.UCHAR, item | 0x80))
+ result.append(rffi.cast(rffi.UCHAR, (item >> 7) | 0x80))
+ result.append(rffi.cast(rffi.UCHAR, item >> 14))
+
+ numb = lltype.malloc(NUMBERING, len(result))
numb.first_snapshot_size = rffi.cast(rffi.USHORT, first_snapshot_size)
+ for i in range(len(result)):
+ numb.code[i] = result[i]
return numb
def numb_next_item(numb, index):
- return rffi.cast(lltype.Signed, numb.code[index]), index + 1
-
-# this is the version that can be potentially used
-
-def _create_numbering(lst, prev, prev_index, first_snapshot_size):
- count = 0
- for item in lst:
- if item < 0:
- if item < -63:
- count += 1
- if item > 127:
- count += 1
- count += 1
- numb = lltype.malloc(NUMBERING, count)
- numb.prev = prev
- numb.prev_index = rffi.cast(rffi.USHORT, prev_index)
- numb.first_snapshot_size = rffi.cast(rffi.USHORT, first_snapshot_size)
- index = 0
- for item in lst:
- if 0 <= item <= 128:
- numb.code[index] = rffi.cast(rffi.UCHAR, item)
+ value = rffi.cast(lltype.Signed, numb.code[index])
+ index += 1
+ if value & (2**7):
+ value &= 2**7 - 1
+ value |= rffi.cast(lltype.Signed, numb.code[index]) << 7
+ index += 1
+ if value & (2**14):
+ value &= 2**14 - 1
+ value |= rffi.cast(lltype.Signed, numb.code[index]) << 14
index += 1
- else:
- assert (item >> 8) <= 63
- if item < 0:
- item = -item
- if item <= 63:
- numb.code[index] = rffi.cast(rffi.UCHAR, item | 0x40)
- index += 1
- else:
- numb.code[index] = rffi.cast(rffi.UCHAR, (item >> 8) | 0x80 | 0x40)
- numb.code[index + 1] = rffi.cast(rffi.UCHAR, item & 0xff)
- index += 2
- else:
- numb.code[index] = rffi.cast(rffi.UCHAR, (item >> 8) | 0x80)
- numb.code[index + 1] = rffi.cast(rffi.UCHAR, item & 0xff)
- index += 2
- return numb
-
-def copy_from_list_to_numb(lst, numb, index):
- i = 0
- while i < len(lst):
- numb.code[i + index] = lst[i]
- i += 1
-
-def _numb_next_item(numb, index):
- one = rffi.cast(lltype.Signed, numb.code[index])
- if one & 0x40:
- if one & 0x80:
- two = rffi.cast(lltype.Signed, numb.code[index + 1])
- return -(((one & ~(0x80 | 0x40)) << 8) | two), index + 2
- else:
- return -(one & (~0x40)), index + 1
- if one & 0x80:
- two = rffi.cast(lltype.Signed, numb.code[index + 1])
- return ((one & 0x7f) << 8) | two, index + 2
- return one, index + 1
+ if value & 1:
+ value = -1 - value
+ value >>= 1
+ return value, index
def unpack_numbering(numb):
l = []
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
@@ -1,9 +1,12 @@
from rpython.jit.metainterp.resumecode import NUMBERING, NULL_NUMBER
from rpython.jit.metainterp.resumecode import create_numbering,\
- unpack_numbering, copy_from_list_to_numb
+ unpack_numbering
from rpython.rtyper.lltypesystem import lltype
+from hypothesis import strategies, given
+
+
def test_pack_unpack():
examples = [
[1, 2, 3, 4, 257, 10000, 13, 15],
@@ -14,3 +17,13 @@
for l in examples:
n = create_numbering(l, 0)
assert unpack_numbering(n) == l
+
+ at given(strategies.lists(strategies.integers(-2**15, 2**15-1)))
+def test_roundtrip(l):
+ n = create_numbering(l, 0)
+ assert unpack_numbering(n) == l
+
+ at given(strategies.lists(strategies.integers(-2**15, 2**15-1)))
+def test_compressing(l):
+ n = create_numbering(l, 0)
+ assert len(n.code) <= len(l) * 3
More information about the pypy-commit
mailing list