Author: Antonio Cuni <[email protected]>
Branch: faster-rstruct-2
Changeset: r91260:884703561c51
Date: 2017-05-11 18:50 +0200
http://bitbucket.org/pypy/pypy/changeset/884703561c51/
Log: test and implement gc_store_indexed in the C backend
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -311,7 +311,8 @@
def gen_op(self, op):
macro = 'OP_%s' % op.opname.upper()
line = None
- if op.opname.startswith('gc_') and op.opname != 'gc_load_indexed':
+ if (op.opname.startswith('gc_') and
+ op.opname not in ('gc_load_indexed', 'gc_store_indexed')):
meth = getattr(self.gcpolicy, macro, None)
if meth:
line = meth(self, op)
@@ -727,6 +728,19 @@
"%(base_ofs)s + %(scale)s * %(index)s))[0];"
% locals())
+ def OP_GC_STORE_INDEXED(self, op):
+ addr = self.expr(op.args[0])
+ index = self.expr(op.args[1])
+ scale = self.expr(op.args[2])
+ base_ofs = self.expr(op.args[3])
+ value = self.expr(op.args[4])
+ TYPE = op.args[4].concretetype
+ typename = cdecl(self.db.gettype(TYPE).replace('@', '*@'), '')
+ return (
+ "((%(typename)s) (((char *)%(addr)s) + "
+ "%(base_ofs)s + %(scale)s * %(index)s))[0] = %(value)s;"
+ % locals())
+
def OP_CAST_PRIMITIVE(self, op):
TYPE = self.lltypemap(op.result)
val = self.expr(op.args[0])
diff --git a/rpython/translator/c/test/test_llop.py
b/rpython/translator/c/test/test_llop.py
--- a/rpython/translator/c/test/test_llop.py
+++ b/rpython/translator/c/test/test_llop.py
@@ -1,5 +1,6 @@
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
-from rpython.rtyper.test.test_llop import BaseLLOpTest, str_gc_load
+from rpython.rtyper.test.test_llop import (BaseLLOpTest, str_gc_load,
+ newlist_and_gc_store)
from rpython.translator.c.test.test_genc import compile
@@ -24,3 +25,22 @@
fn = self.cache[TYPE]
x = fn(buf, offset)
return lltype.cast_primitive(TYPE, x)
+
+ def newlist_and_gc_store(self, TYPE, value):
+ if TYPE not in self.cache:
+ assert isinstance(TYPE, lltype.Primitive)
+ if TYPE in (lltype.Float, lltype.SingleFloat):
+ argtype = float
+ else:
+ argtype = int
+
+ def llf(value):
+ value = lltype.cast_primitive(TYPE, value)
+ lst = newlist_and_gc_store(TYPE, value)
+ return ''.join(lst)
+
+ fn = compile(llf, [argtype])
+ self.cache[TYPE] = fn
+ #
+ fn = self.cache[TYPE]
+ return fn(value)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit