[pypy-svn] r67311 - pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport
arigo at codespeak.net
arigo at codespeak.net
Sat Aug 29 14:35:25 CEST 2009
Author: arigo
Date: Sat Aug 29 14:35:25 2009
New Revision: 67311
Modified:
pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/gc.py
pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/llmodel.py
pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/symbolic.py
Log:
do_new_array, do_setarrayitem_gc.
Modified: pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/gc.py
==============================================================================
--- pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/gc.py (original)
+++ pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/gc.py Sat Aug 29 14:35:25 2009
@@ -4,7 +4,8 @@
from pypy.rpython.annlowlevel import llhelper
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from pypy.jit.backend.llsupport import symbolic
-from pypy.jit.backend.llsupport.descr import SizeDescr
+from pypy.jit.backend.llsupport.symbolic import WORD
+from pypy.jit.backend.llsupport.descr import SizeDescr, AbstractArrayDescr
# ____________________________________________________________
@@ -27,6 +28,7 @@
def __init__(self, gcdescr, cpu):
# grab a pointer to the Boehm 'malloc' function
+ self.translate_support_code = cpu.translate_support_code
compilation_info = ExternalCompilationInfo(libraries=['gc'])
malloc_fn_ptr = rffi.llexternal("GC_local_malloc",
[lltype.Signed], # size_t, but good enough
@@ -46,32 +48,18 @@
init_fn_ptr()
- def sizeof(self, S, translate_support_code):
- size = symbolic.get_size(S, translate_support_code)
- return ConstDescr3(size, 0, False)
-
- def arraydescrof(self, A, translate_support_code):
- basesize, itemsize, ofs_length = symbolic.get_array_token(A,
- translate_support_code)
- assert rffi.sizeof(A.OF) in [1, 2, WORD]
- # assert ofs_length == 0 --- but it's symbolic...
- if isinstance(A.OF, lltype.Ptr) and A.OF.TO._gckind == 'gc':
- ptr = True
- else:
- ptr = False
- return ConstDescr3(basesize, itemsize, ptr)
-
def gc_malloc(self, sizedescr):
assert isinstance(sizedescr, SizeDescr)
return self.funcptr_for_new(sizedescr.size)
def gc_malloc_array(self, arraydescr, num_elem):
- assert isinstance(arraydescr, ConstDescr3)
- basesize = arraydescr.v0
- itemsize = arraydescr.v1
+ assert isinstance(arraydescr, AbstractArrayDescr)
+ ofs_length = arraydescr.get_ofs_length(self.translate_support_code)
+ basesize = arraydescr.get_base_size(self.translate_support_code)
+ itemsize = arraydescr.get_item_size(self.translate_support_code)
size = basesize + itemsize * num_elem
res = self.funcptr_for_new(size)
- rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[0] = num_elem
+ rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[ofs_length/WORD] = num_elem
return res
def gc_malloc_str(self, num_elem, translate_support_code):
Modified: pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/llmodel.py
==============================================================================
--- pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/llmodel.py (original)
+++ pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/llmodel.py Sat Aug 29 14:35:25 2009
@@ -1,25 +1,15 @@
import sys
from pypy.rpython.lltypesystem import lltype, llmemory, rffi, rclass, rstr
from pypy.rlib.objectmodel import we_are_translated, specialize
-from pypy.rlib.unroll import unrolling_iterable
from pypy.jit.metainterp.history import BoxInt, BoxPtr
from pypy.jit.backend.model import AbstractCPU
from pypy.jit.backend.llsupport import symbolic
+from pypy.jit.backend.llsupport.symbolic import WORD, unroll_basic_sizes
from pypy.jit.backend.llsupport.descr import get_size_descr, SizeDescr
from pypy.jit.backend.llsupport.descr import get_field_descr, get_array_descr
from pypy.jit.backend.llsupport.descr import AbstractFieldDescr
from pypy.jit.backend.llsupport.descr import AbstractArrayDescr
-WORD = rffi.sizeof(lltype.Signed)
-SIZEOF_CHAR = rffi.sizeof(lltype.Char)
-SIZEOF_SHORT = rffi.sizeof(rffi.SHORT)
-SIZEOF_INT = rffi.sizeof(rffi.INT)
-
-unroll_basic_sizes = unrolling_iterable([(lltype.Signed, WORD),
- (lltype.Char, SIZEOF_CHAR),
- (rffi.SHORT, SIZEOF_SHORT),
- (rffi.INT, SIZEOF_INT)])
-
def _check_addr_range(x):
if sys.platform == 'linux2':
# this makes assumption about address ranges that are valid
@@ -83,6 +73,8 @@
return ofs, size, ptr
unpack_arraydescr._always_inline_ = True
+ # ____________________________________________________________
+
def do_arraylen_gc(self, args, arraydescr):
assert isinstance(arraydescr, AbstractArrayDescr)
ofs = arraydescr.get_ofs_length(self.translate_support_code)
@@ -108,6 +100,27 @@
else:
return BoxInt(val)
+ def do_setarrayitem_gc(self, args, arraydescr):
+ itemindex = args[1].getint()
+ gcref = args[0].getptr_base()
+ ofs, size, ptr = self.unpack_arraydescr(arraydescr)
+ vbox = args[2]
+ #
+ if ptr:
+ vboxptr = vbox.getptr_base()
+ self.gc_ll_descr.do_write_barrier(gcref, vboxptr)
+ a = rffi.cast(rffi.CArrayPtr(lltype.Signed), gcref)
+ a[ofs/WORD + itemindex] = self.cast_gcref_to_int(vboxptr)
+ else:
+ v = vbox.getint()
+ for TYPE, itemsize in unroll_basic_sizes:
+ if size == itemsize:
+ a = rffi.cast(rffi.CArrayPtr(TYPE), gcref)
+ a[ofs/itemsize + itemindex] = rffi.cast(TYPE, v)
+ break
+ else:
+ raise NotImplementedError("size = %d" % size)
+
def _new_do_len(TP):
def do_strlen(self, args, descr=None):
basesize, itemsize, ofs_length = symbolic.get_array_token(TP,
@@ -190,6 +203,11 @@
as_array[self.vtable_offset/WORD] = classint
return BoxPtr(res)
+ def do_new_array(self, args, arraydescr):
+ num_elem = args[0].getint()
+ res = self.gc_ll_descr.gc_malloc_array(arraydescr, num_elem)
+ return BoxPtr(res)
+
import pypy.jit.metainterp.executor
pypy.jit.metainterp.executor.make_execute_list(AbstractLLCPU)
Modified: pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/symbolic.py
==============================================================================
--- pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/symbolic.py (original)
+++ pypy/branch/pyjitpl5-llmodel/pypy/jit/backend/llsupport/symbolic.py Sat Aug 29 14:35:25 2009
@@ -1,6 +1,7 @@
import ctypes
-from pypy.rpython.lltypesystem import lltype, ll2ctypes, llmemory
+from pypy.rpython.lltypesystem import lltype, ll2ctypes, llmemory, rffi
from pypy.rlib.objectmodel import specialize
+from pypy.rlib.unroll import unrolling_iterable
@specialize.memo()
def get_field_token(STRUCT, fieldname, translate_support_code):
@@ -54,3 +55,14 @@
itemsize = ctypes.sizeof(carrayitem)
return basesize, itemsize, ofs_length
+# ____________________________________________________________
+
+WORD = get_size(lltype.Signed, False)
+SIZEOF_CHAR = get_size(lltype.Char, False)
+SIZEOF_SHORT = get_size(rffi.SHORT, False)
+SIZEOF_INT = get_size(rffi.INT, False)
+
+unroll_basic_sizes = unrolling_iterable([(lltype.Signed, WORD),
+ (lltype.Char, SIZEOF_CHAR),
+ (rffi.SHORT, SIZEOF_SHORT),
+ (rffi.INT, SIZEOF_INT)])
More information about the Pypy-commit
mailing list