[pypy-svn] r69886 - in pypy/branch/listcopyop/pypy/rpython: . lltypesystem memory memory/gc memory/gctransform memory/test
fijal at codespeak.net
fijal at codespeak.net
Fri Dec 4 11:23:36 CET 2009
Author: fijal
Date: Fri Dec 4 11:23:35 2009
New Revision: 69886
Modified:
pypy/branch/listcopyop/pypy/rpython/llinterp.py
pypy/branch/listcopyop/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/listcopyop/pypy/rpython/lltypesystem/opimpl.py
pypy/branch/listcopyop/pypy/rpython/lltypesystem/rlist.py
pypy/branch/listcopyop/pypy/rpython/memory/gc/generation.py
pypy/branch/listcopyop/pypy/rpython/memory/gctransform/framework.py
pypy/branch/listcopyop/pypy/rpython/memory/gctransform/transform.py
pypy/branch/listcopyop/pypy/rpython/memory/gcwrapper.py
pypy/branch/listcopyop/pypy/rpython/memory/test/test_gc.py
pypy/branch/listcopyop/pypy/rpython/memory/test/test_transformed_gc.py
Log:
* Rename listcopy to arraycopy
* Improve tests
* Implement framework transform
* Helper on GC can only accept addresses which point to GcArray of gc pointers
Modified: pypy/branch/listcopyop/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/llinterp.py (original)
+++ pypy/branch/listcopyop/pypy/rpython/llinterp.py Fri Dec 4 11:23:35 2009
@@ -754,9 +754,9 @@
def op_zero_gc_pointers_inside(self, obj):
raise NotImplementedError("zero_gc_pointers_inside")
- def op_listcopy(self, source, dest, source_start, dest_start, length):
- if hasattr(self.heap, 'listcopy'):
- self.heap.listcopy(source, dest, source_start, dest_start, length)
+ def op_gc_arraycopy(self, source, dest, source_start, dest_start, length):
+ if hasattr(self.heap, 'arraycopy'):
+ self.heap.arraycopy(source, dest, source_start, dest_start, length)
return True
return False
Modified: pypy/branch/listcopyop/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/listcopyop/pypy/rpython/lltypesystem/lloperation.py Fri Dec 4 11:23:35 2009
@@ -358,7 +358,7 @@
'resize_buffer': LLOp(canraise=(MemoryError,), canunwindgc=True),
'finish_building_buffer' : LLOp(canraise=(MemoryError,), canunwindgc=True),
'zero_gc_pointers_inside': LLOp(),
- 'gc_listcopy': LLOp(canrun=True),
+ 'gc_arraycopy': LLOp(canrun=True),
'free': LLOp(),
'getfield': LLOp(sideeffects=False, canrun=True),
'getarrayitem': LLOp(sideeffects=False, canrun=True),
Modified: pypy/branch/listcopyop/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/lltypesystem/opimpl.py (original)
+++ pypy/branch/listcopyop/pypy/rpython/lltypesystem/opimpl.py Fri Dec 4 11:23:35 2009
@@ -394,7 +394,7 @@
checkadr(addr2)
return addr1 - addr2
-def op_gc_listcopy(source, dest, source_start, dest_start, length):
+def op_gc_arraycopy(source, dest, source_start, dest_start, length):
return False # no special support
def op_getfield(p, name):
Modified: pypy/branch/listcopyop/pypy/rpython/lltypesystem/rlist.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/lltypesystem/rlist.py (original)
+++ pypy/branch/listcopyop/pypy/rpython/lltypesystem/rlist.py Fri Dec 4 11:23:35 2009
@@ -214,7 +214,7 @@
p = before_len
else:
p = new_allocated
- rgc.listcopy(items, newitems, 0, 0, p)
+ rgc.ll_arraycopy(items, newitems, 0, 0, p)
l.length = newsize
l.items = newitems
_ll_list_resize_really._annenforceargs_ = (None, int)
Modified: pypy/branch/listcopyop/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/gc/generation.py (original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/gc/generation.py Fri Dec 4 11:23:35 2009
@@ -475,25 +475,25 @@
objhdr.tid &= ~GCFLAG_NO_HEAP_PTRS
self.last_generation_root_objects.append(addr_struct)
- @specialize.arglltype(1)
- def listcopy(self, source, dest, source_start, dest_start, length):
- TP = lltype.typeOf(source).TO
- source_addr = llmemory.cast_ptr_to_adr(source)
- dest_addr = llmemory.cast_ptr_to_adr(dest)
- if isinstance(TP.OF, lltype.Ptr):
- need_set = False
- if self.header(source_addr).tid & GCFLAG_NO_YOUNG_PTRS == 0:
- need_set = True
- if self.header(source_addr).tid & GCFLAG_NO_HEAP_PTRS == 0:
- need_set = True
- if need_set:
- self.assume_young_pointers(dest_addr)
- cp_source_addr = (source_addr + llmemory.itemoffsetof(TP, 0) +
- llmemory.sizeof(TP.OF) * source_start)
- cp_dest_addr = (dest_addr + llmemory.itemoffsetof(TP, 0) +
- llmemory.sizeof(TP.OF) * dest_start)
+ def arraycopy(self, source_addr, dest_addr, source_start,
+ dest_start, length):
+ typeid = self.get_type_id(source_addr)
+ assert self.is_gcarrayofgcptr(typeid)
+ need_set = False
+ if self.header(source_addr).tid & GCFLAG_NO_YOUNG_PTRS == 0:
+ need_set = True
+ if self.header(source_addr).tid & GCFLAG_NO_HEAP_PTRS == 0:
+ need_set = True
+ if need_set:
+ self.assume_young_pointers(dest_addr)
+ itemsize = llmemory.gcarrayofptr_singleitemoffset
+ cp_source_addr = (source_addr + llmemory.gcarrayofptr_itemsoffset +
+ itemsize * source_start)
+ cp_dest_addr = (dest_addr + llmemory.gcarrayofptr_itemsoffset +
+ itemsize * dest_start)
llmemory.raw_memcopy(cp_source_addr, cp_dest_addr,
- llmemory.sizeof(TP.OF) * length)
+ itemsize * length)
+ return True
def write_into_last_generation_obj(self, addr_struct, addr):
objhdr = self.header(addr_struct)
Modified: pypy/branch/listcopyop/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/gctransform/framework.py (original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/gctransform/framework.py Fri Dec 4 11:23:35 2009
@@ -292,6 +292,11 @@
[s_gc, annmodel.SomeInteger(knowntype=rffi.r_ushort)],
annmodel.SomeInteger())
+ if hasattr(GCClass, 'arraycopy'):
+ self.arraycopy_ptr = getfn(GCClass.arraycopy.im_func,
+ [s_gc] + [annmodel.SomeAddress()] * 2 +
+ [annmodel.SomeInteger()] * 3, annmodel.SomeBool())
+
# in some GCs we can inline the common case of
# malloc_fixedsize(typeid, size, True, False, False)
if getattr(GCClass, 'inline_simple_malloc', False):
@@ -776,16 +781,17 @@
TYPE = v_ob.concretetype.TO
gen_zero_gc_pointers(TYPE, v_ob, hop.llops)
- # def gct_listcopy(self, hop):
- # if not hasattr(self.GCClass, 'listcopy'):
- # return GCTransformer.gct_listcopy(self, hop)
- # op = hop.spaceop
- # ARGS = ([self.c_const_gc.concretetype] +
- # [arg.concretetype for arg in op.args])
- # llptr = self.annotate_helper(self.GCClass.listcopy, ARGS,
- # op.result.concretetype, inline=True)
- # c_func = rmodel.inputconst(lltype.Void, llptr)
- # hop.genop('direct_call', [c_func, self.c_const_gc] + op.args)
+ def gct_gc_arraycopy(self, hop):
+ if not hasattr(self, 'arraycopy_ptr'):
+ return GCTransformer.gct_gc_arraycopy(self, hop)
+ op = hop.spaceop
+ source_addr = hop.genop('cast_ptr_to_adr', [op.args[0]],
+ resulttype=llmemory.Address)
+ dest_addr = hop.genop('cast_ptr_to_adr', [op.args[1]],
+ resulttype=llmemory.Address)
+ hop.genop('direct_call', [self.arraycopy_ptr, self.c_const_gc,
+ source_addr, dest_addr] + op.args[2:],
+ resultvar=op.result)
def gct_weakref_create(self, hop):
op = hop.spaceop
Modified: pypy/branch/listcopyop/pypy/rpython/memory/gctransform/transform.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/gctransform/transform.py (original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/gctransform/transform.py Fri Dec 4 11:23:35 2009
@@ -14,7 +14,7 @@
from pypy.annotation import model as annmodel
from pypy.rpython import rmodel
from pypy.rpython.memory import gc
-from pypy.rpython.memory.gctransform.support import var_ispyobj, ll_listcopy
+from pypy.rpython.memory.gctransform.support import var_ispyobj
from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
from pypy.rpython.rtyper import LowLevelOpList
from pypy.rpython.rbuiltin import gen_cast
@@ -380,7 +380,7 @@
def gct_zero_gc_pointers_inside(self, hop):
pass
- def gct_gc_listcopy(self, hop):
+ def gct_gc_arraycopy(self, hop):
return rmodel.inputconst(lltype.Bool, False)
def gct_gc_identityhash(self, hop):
Modified: pypy/branch/listcopyop/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/gcwrapper.py (original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/gcwrapper.py Fri Dec 4 11:23:35 2009
@@ -128,10 +128,12 @@
ptr = lltype.cast_opaque_ptr(llmemory.GCREF, ptr)
return self.gc.id(ptr)
- def listcopy(self, source, dest, source_start, dest_start, length):
- if hasattr(self.gc, 'listcopy'):
- return self.gc.listcopy(source, dest, source_start,
- dest_start, length)
+ def arraycopy(self, source, dest, source_start, dest_start, length):
+ if hasattr(self.gc, 'arraycopy'):
+ source_addr = llmemory.cast_ptr_to_adr(source)
+ dest_addr = llmemory.cast_ptr_to_adr(dest)
+ return self.gc.arraycopy(source_addr, dest_addr, source_start,
+ dest_start, length)
i = 0
while i < length:
dest[dest_start + i] = source[source_start + i]
Modified: pypy/branch/listcopyop/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/test/test_gc.py (original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/test/test_gc.py Fri Dec 4 11:23:35 2009
@@ -551,20 +551,7 @@
res = self.interpret(fn, [-1000], taggedpointers=True)
assert res == 111
- def test_listcopy(self):
- TP = lltype.GcArray(lltype.Signed)
- def fn():
- l = lltype.malloc(TP, 100)
- for i in range(100):
- l[i] = 1
- l2 = lltype.malloc(TP, 50)
- llop.listcopy(lltype.Void, l, l2, 50, 0, 50)
- for i in range(50):
- assert l2[i] == 1
-
- self.interpret(fn, [])
-
- def test_listcopy_ptr(self):
+ def test_arraycopy(self):
S = lltype.GcStruct('S')
TP = lltype.GcArray(lltype.Ptr(S))
def fn():
@@ -572,14 +559,14 @@
l2 = lltype.malloc(TP, 100)
for i in range(100):
l[i] = lltype.malloc(S)
- llop.listcopy(lltype.Void, l, l2, 50, 0, 50)
- x = []
- # force minor collect
- t = (1, lltype.malloc(S))
- for i in range(20):
- x.append(t)
- for i in range(50):
- assert l2[i]
+ if llop.gc_arraycopy(lltype.Void, l, l2, 50, 0, 50):
+ x = []
+ # force minor collect
+ t = (1, lltype.malloc(S))
+ for i in range(20):
+ x.append(t)
+ for i in range(50):
+ assert l2[i]
return 0
self.interpret(fn, [])
Modified: pypy/branch/listcopyop/pypy/rpython/memory/test/test_transformed_gc.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/test/test_transformed_gc.py (original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/test/test_transformed_gc.py Fri Dec 4 11:23:35 2009
@@ -844,26 +844,7 @@
# ^^^ a crude assumption that totsize - varsize would be dividable by 4
# (and give fixedsize)
-
- def define_listcopy(cls):
- TP = lltype.GcArray(lltype.Signed)
- def fn():
- l = lltype.malloc(TP, 100)
- for i in range(100):
- l[i] = 1
- l2 = lltype.malloc(TP, 50)
- if llop.gc_listcopy(lltype.Void, l, l2, 50, 0, 50):
- for i in range(50):
- assert l2[i] == 1
- return 0
-
- return fn
-
- def test_listcopy(self):
- run = self.runner("listcopy")
- run([])
-
- def define_listcopy_ptr(cls):
+ def define_arraycopy(cls):
S = lltype.GcStruct('S')
TP = lltype.GcArray(lltype.Ptr(S))
def fn():
@@ -871,7 +852,7 @@
l2 = lltype.malloc(TP, 100)
for i in range(100):
l[i] = lltype.malloc(S)
- if llop.gc_listcopy(lltype.Void, l, l2, 50, 0, 50):
+ if llop.gc_arraycopy(lltype.Void, l, l2, 50, 0, 50):
# force nursery collect
x = []
for i in range(20):
@@ -882,8 +863,8 @@
return fn
- def test_listcopy_ptr(self):
- run = self.runner("listcopy_ptr")
+ def test_arraycopy(self):
+ run = self.runner("arraycopy")
run([])
# ________________________________________________________________
More information about the Pypy-commit
mailing list