[pypy-svn] r31734 - in pypy/dist/pypy/jit/codegen/i386: . test

arigo at codespeak.net arigo at codespeak.net
Sun Aug 27 15:59:38 CEST 2006


Author: arigo
Date: Sun Aug 27 15:59:36 2006
New Revision: 31734

Modified:
   pypy/dist/pypy/jit/codegen/i386/ri386genop.py
   pypy/dist/pypy/jit/codegen/i386/test/test_interp_ts.py
Log:
Hack array access operations.  This needs to be done differently Very
Soon Now.



Modified: pypy/dist/pypy/jit/codegen/i386/ri386genop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/ri386genop.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/ri386genop.py	Sun Aug 27 15:59:36 2006
@@ -247,6 +247,7 @@
         return self.push(eax)
 
     def op_getfield(self, (gv_ptr, gv_offset), gv_RESTYPE):
+        # XXX only for int fields
         assert isinstance(gv_offset, IntConst)
         offset = gv_offset.value
         self.mc.MOV(edx, gv_ptr.operand(self))
@@ -267,6 +268,53 @@
         self.mc.LEA(eax, mem(edx, offset))
         return self.push(eax)
 
+    def op_getarrayitem(self, (gv_ptr, gv_index), gv_RESTYPE):
+        # XXX! only works for GcArray(Signed) for now!!
+        A = DUMMY_A
+        lengthoffset, startoffset, itemoffset = self.rgenop.access_array(A)
+        self.mc.MOV(edx, gv_ptr.operand(self))
+        if isinstance(gv_index, IntConst):
+            startoffset += itemoffset * gv_index.value
+            op = mem(edx, startoffset)
+        elif itemoffset in SIZE2SHIFT:
+            self.mc.MOV(ecx, gv_index.operand(self))
+            op = memSIB(edx, ecx, SIZE2SHIFT[itemoffset], startoffset)
+        else:
+            self.mc.IMUL(ecx, gv_index.operand(self), imm(itemoffset))
+            op = memSIB(edx, ecx, 0, startoffset)
+        return self.push(op)
+
+    def op_getarraysize(self, (gv_ptr,), gv_RESTYPE):
+        # XXX! only works for GcArray(Signed) for now!!
+        A = DUMMY_A
+        lengthoffset, startoffset, itemoffset = self.rgenop.access_array(A)
+        self.mc.MOV(edx, gv_ptr.operand(self))
+        return self.push(mem(edx, lengthoffset))
+
+    def op_setarrayitem(self, (gv_ptr, gv_index, gv_value), gv_RESTYPE):
+        # XXX! only works for GcArray(Signed) for now!!
+        A = DUMMY_A
+        lengthoffset, startoffset, itemoffset = self.rgenop.access_array(A)
+        self.mc.MOV(eax, gv_value.operand(self))
+        self.mc.MOV(edx, gv_ptr.operand(self))
+        if isinstance(gv_index, IntConst):
+            startoffset += itemoffset * gv_index.value
+            op = mem(edx, startoffset)
+        elif itemoffset in SIZE2SHIFT:
+            self.mc.MOV(ecx, gv_index.operand(self))
+            op = memSIB(edx, ecx, SIZE2SHIFT[itemoffset], startoffset)
+        else:
+            self.mc.IMUL(ecx, gv_index.operand(self), imm(itemoffset))
+            op = memSIB(edx, ecx, 0, startoffset)
+        self.mc.MOV(op, eax)
+
+DUMMY_A = lltype.GcArray(lltype.Signed)
+SIZE2SHIFT = {1: 0,
+              2: 1,
+              4: 2,
+              8: 3}
+
+
 class Link(CodeGenLink):
 
     def __init__(self, prevblock):
@@ -392,6 +440,13 @@
     constFieldName._annspecialcase_ = 'specialize:memo'
     constFieldName = staticmethod(constFieldName)
 
+    def access_array(A):   # XXX temporary
+        return (llmemory.ArrayLengthOffset(A),
+                llmemory.ArrayItemsOffset(A),
+                llmemory.ItemOffset(A.OF))
+    access_array._annspecialcase_ = 'specialize:memo'
+    access_array = staticmethod(access_array)
+
     def gencallableconst(self, name, block, gv_FUNCTYPE):
         prologue = self.newblock()
         #prologue.mc.BREAKPOINT()

Modified: pypy/dist/pypy/jit/codegen/i386/test/test_interp_ts.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/test/test_interp_ts.py	(original)
+++ pypy/dist/pypy/jit/codegen/i386/test/test_interp_ts.py	Sun Aug 27 15:59:36 2006
@@ -20,6 +20,11 @@
         constFieldName._annspecialcase_ = 'specialize:memo'
         constFieldName = staticmethod(constFieldName)
 
+        def access_array(A):
+            return 0, 1, 1
+        access_array._annspecialcase_ = 'specialize:memo'
+        access_array = staticmethod(access_array)
+
     def timeshift(self, ll_function, values, opt_consts=[], *args, **kwds):
         values = self.timeshift_cached(ll_function, values, *args, **kwds)
 



More information about the Pypy-commit mailing list