Author: Remi Meier <[email protected]>
Branch: stmgc-c8-gcc
Changeset: r79656:4fac55ea7358
Date: 2015-09-16 13:48 +0200
http://bitbucket.org/pypy/pypy/changeset/4fac55ea7358/
Log: add varsize variant
diff --git a/rpython/memory/gctransform/stmframework.py
b/rpython/memory/gctransform/stmframework.py
--- a/rpython/memory/gctransform/stmframework.py
+++ b/rpython/memory/gctransform/stmframework.py
@@ -271,6 +271,32 @@
self.pop_roots(hop, livevars)
hop.genop("cast_opaque_ptr", [v_result], resultvar=op.result)
+ def gct_stm_malloc_noconflict_varsize(self, hop):
+ op = hop.spaceop
+ args = hop.inputargs()
+ PTRTYPE = op.result.concretetype
+ TYPE = PTRTYPE.TO
+ type_id = self.get_type_id(TYPE)
+ info = self.layoutbuilder.get_info(type_id)
+ info_varsize = self.layoutbuilder.get_info_varsize(type_id)
+
+ v_length = args[0]
+ c_type_id = rmodel.inputconst(TYPE_ID, type_id)
+ c_size = rmodel.inputconst(lltype.Signed, info.fixedsize)
+ c_ofstolength = rmodel.inputconst(lltype.Signed,
+ info_varsize.ofstolength)
+ c_varitemsize = rmodel.inputconst(lltype.Signed,
+ info_varsize.varitemsize)
+
+ args = [c_size, c_varitemsize, c_ofstolength, v_length, c_type_id]
+
+ livevars = self.push_roots(hop)
+ v_result = hop.genop("stm_allocate_noconflict_varsize",
+ args, resulttype=llmemory.GCREF)
+ self.pop_roots(hop, livevars)
+ hop.genop("cast_opaque_ptr", [v_result], resultvar=op.result)
+ hop.genop("stm_set_into_obj", [v_result, c_ofstolength, v_length])
+
diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -190,11 +190,14 @@
return llop.stm_allocate_preexisting(TP, size, p)
@specialize.ll()
-def allocate_noconflict(GCTYPE):
+def allocate_noconflict(GCTYPE, n=None):
"""Return a new instance of GCTYPE that never generates conflicts when
reading or writing to it. However, modifications may get lost
and are not guaranteed to propagate."""
- return llop.stm_malloc_noconflict(lltype.Ptr(GCTYPE))
+ if n is None:
+ return llop.stm_malloc_noconflict(lltype.Ptr(GCTYPE))
+ else:
+ return llop.stm_malloc_noconflict_varsize(lltype.Ptr(GCTYPE), n)
@specialize.ll()
def allocate_nonmovable(GCTYPE):
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
@@ -424,7 +424,9 @@
'stm_allocate_f_light': LLOp(sideeffects=False, canmallocgc=True),
'stm_allocate_preexisting':LLOp(sideeffects=False, canmallocgc=True),
'stm_allocate_noconflict':LLOp(sideeffects=False, canmallocgc=True),
+ 'stm_allocate_noconflict_varsize':LLOp(sideeffects=False,
canmallocgc=True),
'stm_malloc_noconflict': LLOp(sideeffects=False, canmallocgc=True),
+ 'stm_malloc_noconflict_varsize': LLOp(sideeffects=False,
canmallocgc=True),
'stm_allocate_nonmovable':LLOp(sideeffects=False, canmallocgc=True),
'stm_malloc_nonmovable': LLOp(sideeffects=False, canmallocgc=True),
'stm_set_into_obj': LLOp(),
diff --git a/rpython/translator/stm/funcgen.py
b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -123,9 +123,9 @@
arg_type_id = funcgen.expr(op.args[1])
result = funcgen.expr(op.result)
# XXX NULL returns?
- return ('%s = (rpygcchar_t *)_stm_allocate_external(%s >= 16 ? %s : 16); '
%
+ return ('%s = (rpygcchar_t *)_stm_allocate_external(%s >= 16 ? %s :
16);\n' %
(result, arg_size, arg_size) +
- 'pypy_stm_memclearinit((object_t*)%s, 0, %s >= 16 ? %s : 16);' %
+ 'pypy_stm_memclearinit((object_t*)%s, 0, %s >= 16 ? %s : 16);\n' %
(result, arg_size, arg_size) +
'((rpyobj_t *)%s)->tid = %s;' % (result, arg_type_id))
@@ -134,12 +134,33 @@
arg_type_id = funcgen.expr(op.args[1])
result = funcgen.expr(op.result)
# XXX NULL returns?
- return ('%s = (rpygcchar_t *)stm_allocate_noconflict(%s >= 16 ? %s : 16);
' %
+ return ('%s = (rpygcchar_t *)stm_allocate_noconflict(%s >= 16 ? %s :
16);\n' %
(result, arg_size, arg_size) +
- 'pypy_stm_memclearinit((object_t*)%s, 0, %s >= 16 ? %s : 16);' %
+ 'pypy_stm_memclearinit((object_t*)%s, 0, %s >= 16 ? %s : 16);\n' %
(result, arg_size, arg_size) +
'((rpyobj_t *)%s)->tid = %s;' % (result, arg_type_id))
+def stm_allocate_noconflict_varsize(funcgen, op):
+ arg_size = funcgen.expr(op.args[0])
+ arg_itemsize = funcgen.expr(op.args[1])
+ arg_ofstolength = funcgen.expr(op.args[2])
+ arg_length = funcgen.expr(op.args[3])
+ arg_type_id = funcgen.expr(op.args[4])
+ result = funcgen.expr(op.result)
+ # XXX NULL returns?
+ return """
+{
+ ssize_t size = %s + %s * %s;
+ %s = (rpygcchar_t *)stm_allocate_noconflict(size);
+ pypy_stm_memclearinit((object_t*)%s, %s, size);
+ ((rpyobj_t *)%s)->tid = %s;
+}
+ """ % (arg_size, arg_itemsize, arg_length,
+ result,
+ result, arg_size,
+ result, arg_type_id,)
+
+
def stm_set_into_obj(funcgen, op):
assert op.args[0].concretetype == llmemory.GCREF
arg_obj = funcgen.expr(op.args[0])
diff --git a/rpython/translator/stm/test/test_ztranslated.py
b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -723,3 +723,18 @@
t, cbuilder = self.compile(main)
data = cbuilder.cmdexec('')
assert 'ok!\n' in data
+
+ def test_allocate_noconflict2(self):
+ S = lltype.GcArray(lltype.Signed)
+
+ def main(argv):
+ s1 = rstm.allocate_noconflict(S, 4)
+ s1[1] = 42
+ assert s1[1] == 42
+ #
+ print "ok!"
+ return 0
+
+ t, cbuilder = self.compile(main)
+ data = cbuilder.cmdexec('')
+ assert 'ok!\n' in data
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit