[pypy-commit] pypy faster-rstruct-2: WIP: start to implement llop.gc_store_indexed; still missing implementation in the C backend and the JIT
antocuni
pypy.commits at gmail.com
Fri May 12 10:29:09 EDT 2017
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: faster-rstruct-2
Changeset: r91258:4be2157b169f
Date: 2017-05-11 18:30 +0200
http://bitbucket.org/pypy/pypy/changeset/4be2157b169f/
Log: WIP: start to implement llop.gc_store_indexed; still missing
implementation in the C backend and the JIT
diff --git a/rpython/rtyper/lltypesystem/lloperation.py b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -397,6 +397,7 @@
'raw_store': LLOp(canrun=True),
'bare_raw_store': LLOp(),
'gc_load_indexed': LLOp(sideeffects=False, canrun=True),
+ 'gc_store_indexed': LLOp(canrun=True),
'track_alloc_start': LLOp(),
'track_alloc_stop': LLOp(),
'adr_add': LLOp(canfold=True),
diff --git a/rpython/rtyper/lltypesystem/opimpl.py b/rpython/rtyper/lltypesystem/opimpl.py
--- a/rpython/rtyper/lltypesystem/opimpl.py
+++ b/rpython/rtyper/lltypesystem/opimpl.py
@@ -728,6 +728,17 @@
return p[0]
op_gc_load_indexed.need_result_type = True
+def op_gc_store_indexed(p, index, scale, base_ofs, newvalue):
+ # 'base_ofs' should be a CompositeOffset(..., ArrayItemsOffset).
+ # 'scale' should be a llmemory.sizeof().
+ from rpython.rtyper.lltypesystem import rffi
+ TVAL = lltype.typeOf(newvalue)
+ ofs = base_ofs + scale * index
+ if isinstance(ofs, int):
+ return op_raw_store(p, ofs, newvalue)
+ p = rffi.cast(rffi.CArrayPtr(TVAL), llmemory.cast_ptr_to_adr(p) + ofs)
+ p[0] = newvalue
+
def op_likely(x):
assert isinstance(x, bool)
return x
diff --git a/rpython/rtyper/test/test_llop.py b/rpython/rtyper/test/test_llop.py
--- a/rpython/rtyper/test/test_llop.py
+++ b/rpython/rtyper/test/test_llop.py
@@ -5,6 +5,9 @@
from rpython.rtyper.lltypesystem.rstr import STR
from rpython.rtyper.annlowlevel import llstr
from rpython.rlib.rarithmetic import r_singlefloat
+from rpython.rlib.rgc import (resizable_list_supporting_raw_ptr,
+ ll_for_resizable_list)
+
def str_gc_load(TYPE, buf, offset):
base_ofs = (llmemory.offsetof(STR, 'chars') +
@@ -14,6 +17,19 @@
return llop.gc_load_indexed(TYPE, lls, offset,
scale_factor, base_ofs)
+
+def list_gc_store(TYPE, lst, offset, value):
+ value = lltype.cast_primitive(TYPE, value)
+ ll_data = ll_for_resizable_list(lst)
+ ll_items = ll_data.items
+ LIST = lltype.typeOf(ll_data).TO # rlist.LIST_OF(lltype.Char)
+ base_ofs = llmemory.itemoffsetof(LIST.items.TO, 0)
+ scale_factor = llmemory.sizeof(lltype.Char)
+ return llop.gc_store_indexed(lltype.Void, ll_items, offset,
+ scale_factor, base_ofs, value)
+
+
+
class BaseLLOpTest(object):
def test_gc_load_indexed(self):
@@ -27,6 +43,14 @@
val = self.gc_load_from_string(rffi.INT, buf, 12)
assert val == 0x12345678
+ def test_gc_store_indexed(self):
+ expected = struct.pack('i', 0x12345678)
+ n = len(expected)
+ lst = resizable_list_supporting_raw_ptr(['\x00']*n)
+ list_gc_store(rffi.INT, lst, 0, 0x12345678)
+ buf = ''.join(lst)
+ assert buf == expected
+
class TestDirect(BaseLLOpTest):
More information about the pypy-commit
mailing list