Commits

Antonio Cuni  committed b0cb6a4

use the new RawBuffer to implement the virtual raw memory

  • Participants
  • Parent commits db54acd
  • Branches virtual-raw-mallocs

Comments (0)

Files changed (6)

File pypy/jit/backend/llgraph/runner.py

             token = '?'
         return self.getdescr(size, token)
 
+    def unpack_arraydescr_size(self, arraydescr):
+        # so far this is used only by optimizeopt.virtualize for
+        # {GET,SET}ARRAYITEM_RAW: it's hard (if not impossible) to compute
+        # precise values, so we just return dummy ones for now
+        return 0, 8, True
+
     # ---------- the backend-dependent operations ----------
 
     def bh_strlen(self, string):

File pypy/jit/backend/model.py

     def typedescrof(self, TYPE):
         raise NotImplementedError
 
+    def unpack_arraydescr_size(self, arraydescr):
+        """
+        Return basesize, itemsize, is_signed
+        """
+        raise NotImplementedError
+
     # ---------- the backend-dependent operations ----------
 
     # lltype specific operations
         self.cpu.total_freed_loops += 1
         self.cpu.total_freed_bridges += self.bridges_count
         debug_stop("jit-mem-looptoken-free")
+

File pypy/jit/metainterp/history.py

     def get_jitcode_for_class(self, oocls):
         return self.jitcodes[oocls]
 
-
 class Const(AbstractValue):
     __slots__ = ()
 

File pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py

         ops = """
         [i1]
         i2 = call('malloc', 10, descr=raw_malloc_descr)
-        setarrayitem_raw(i2, 0, i1, descr=arraydescr)
-        i3 = getarrayitem_raw(i2, 0, descr=arraydescr)
+        setarrayitem_raw(i2, 0, i1, descr=rawarraydescr)
+        i3 = getarrayitem_raw(i2, 0, descr=rawarraydescr)
         call('free', i2, descr=raw_free_descr)
         jump(i3)
         """

File pypy/jit/metainterp/optimizeopt/test/test_util.py

     complexrealdescr = cpu.interiorfielddescrof(complexarray, "real")
     compleximagdescr = cpu.interiorfielddescrof(complexarray, "imag")
 
+    rawarraydescr = cpu.arraydescrof(lltype.Array(lltype.Signed,
+                                                  hints={'nolength': True}))
+
     for _name, _os in [
         ('strconcatdescr',               'OS_STR_CONCAT'),
         ('strslicedescr',                'OS_STR_SLICE'),

File pypy/jit/metainterp/optimizeopt/virtualize.py

 from pypy.jit.metainterp.optimizeopt import optimizer
 from pypy.jit.metainterp.optimizeopt.util import (make_dispatcher_method,
     descrlist_dict, sort_descrs)
+from pypy.jit.metainterp.optimizeopt.rawbuffer import RawBuffer, InvalidRawOperation
 from pypy.jit.metainterp.resoperation import rop, ResOperation
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.jit.metainterp.optimizeopt.optimizer import OptValue
     def __init__(self, cpu, size, keybox, source_op):
         AbstractVirtualValue.__init__(self, keybox, source_op)
         self.cpu = cpu
+        # note that size is unused, because we assume that the buffer is big
+        # enough to write/read everything we need. If it's not, it's undefined
+        # behavior anyway, although in theory we could probably detect such
+        # cases here
         self.size = size
-        self._raw_items = {}
+        self.buffer = RawBuffer()
 
     def _really_force(self, optforce):
         import pdb;pdb.set_trace()
 
-    def setitem_raw(self, index, value):
-        self._raw_items[index] = value
+    def setitem_raw(self, offset, length, descr, value):
+        try:
+            self.buffer.write_value(offset, length, descr, value)
+        except InvalidRawOperation:
+            XXX
 
-    def getitem_raw(self, index):
-        return self._raw_items[index]
+    def getitem_raw(self, offset, length, descr):
+        try:
+            return self.buffer.read_value(offset, length, descr)
+        except InvalidRawOperation:
+            XXX
 
 
 class OptVirtualize(optimizer.Optimization):
         value.ensure_nonnull()
         self.emit_operation(op)
 
+    def _unpack_arrayitem_raw_op(self, op, indexbox):
+        index = indexbox.getint()
+        cpu = self.optimizer.cpu
+        descr = op.getdescr()
+        basesize, itemsize, _ = cpu.unpack_arraydescr_size(descr)
+        offset = basesize + (itemsize*index)
+        return offset, itemsize, descr
+
     def optimize_GETARRAYITEM_RAW(self, op):
         value = self.getvalue(op.getarg(0))
         if value.is_virtual():
             indexbox = self.get_constant_box(op.getarg(1))
             if indexbox is not None:
-                itemvalue = value.getitem_raw(indexbox.getint())
+                offset, itemsize, descr = self._unpack_arrayitem_raw_op(op, indexbox)
+                itemvalue = value.getitem_raw(offset, itemsize, descr)
                 self.make_equal_to(op.result, itemvalue)
                 return
         value.ensure_nonnull()
         if value.is_virtual():
             indexbox = self.get_constant_box(op.getarg(1))
             if indexbox is not None:
-                # XXX: we should check that the descr is always the same, or
-                # we might get wrong results
-                value.setitem_raw(indexbox.getint(), self.getvalue(op.getarg(2)))
+                offset, itemsize, descr = self._unpack_arrayitem_raw_op(op, indexbox)
+                itemvalue = self.getvalue(op.getarg(2))
+                value.setitem_raw(offset, itemsize, descr, itemvalue)
                 return
         value.ensure_nonnull()
         self.emit_operation(op)