[pypy-svn] r32064 - in pypy/dist/pypy/jit: codegen/i386 codegen/llgraph timeshifter timeshifter/test

pedronis at codespeak.net pedronis at codespeak.net
Thu Sep 7 18:52:50 CEST 2006


Author: pedronis
Date: Thu Sep  7 18:52:45 2006
New Revision: 32064

Modified:
   pypy/dist/pypy/jit/codegen/i386/ri386genop.py
   pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
   pypy/dist/pypy/jit/timeshifter/rtimeshift.py
   pypy/dist/pypy/jit/timeshifter/rtyper.py
   pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
Log:
implemented timeshifting of setarrayitem.



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	Thu Sep  7 18:52:45 2006
@@ -182,6 +182,22 @@
         self.mc.MOV(edx, gv_ptr.operand(self))
         return self.returnvar(mem(edx, lengthoffset))
 
+    def genop_setarrayitem(self, arraytoken, gv_ptr, gv_index, gv_value):
+        # XXX! only works for GcArray(Signed) for now!!
+        lengthoffset, startoffset, itemoffset = arraytoken
+        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)
+
     def genop_malloc_fixedsize(self, size):
         # XXX boehm only, no atomic/non atomic distinction for now
         self.push(imm(size))
@@ -363,29 +379,10 @@
         self.mc.MOVZX(eax, al)
         return self.returnvar(eax)
 
-    def op_setarrayitem(self, hello_world):
-        # XXX! only works for GcArray(Signed) for now!!
-        XXX-fixme
-        A = DUMMY_A
-        lengthoffset, startoffset, itemoffset = self.rgenop.arrayToken(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)
-
     op_ptr_nonzero = op_int_is_true
     op_ptr_iszero  = op_bool_not        # for now
 
 
-DUMMY_A = lltype.GcArray(lltype.Signed)
 SIZE2SHIFT = {1: 0,
               2: 1,
               4: 2,

Modified: pypy/dist/pypy/jit/codegen/llgraph/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llgraph/rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/llgraph/rgenop.py	Thu Sep  7 18:52:45 2006
@@ -81,6 +81,11 @@
         return LLVar(llimpl.genop(self.b, 'getarrayitem', vars_gv,
                                   gv_ITEMTYPE.v))
 
+    def genop_setarrayitem(self, gv_ITEMTYPE, gv_ptr, gv_index, gv_value):
+        vars_gv = [gv_ptr.v, gv_index.v, gv_value.v]
+        return LLVar(llimpl.genop(self.b, 'setarrayitem', vars_gv,
+                                  gv_Void.v))
+
     def genop_getarraysize(self, gv_ITEMTYPE, gv_ptr):
         return LLVar(llimpl.genop(self.b, 'getarraysize', [gv_ptr.v],
                                   llimpl.constTYPE(lltype.Signed)))

Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtimeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rtimeshift.py	Thu Sep  7 18:52:45 2006
@@ -126,6 +126,16 @@
                                                     
     return fielddesc.redboxcls(fielddesc.kind, genvar)
 
+def ll_gensetarrayitem(jitstate, fielddesc, destbox, indexbox, valuebox):
+    genvar = jitstate.curbuilder.genop_setarrayitem(
+        fielddesc.arraytoken,
+        destbox.getgenvar(jitstate.curbuilder),
+        indexbox.getgenvar(jitstate.curbuilder),
+        valuebox.getgenvar(jitstate.curbuilder)
+        )
+                                                    
+    return fielddesc.redboxcls(fielddesc.kind, genvar)
+
 def ll_gengetarraysize(jitstate, fielddesc, argbox):
     if argbox.is_constant():
         array = rvalue.ll_getvalue(argbox, fielddesc.PTRTYPE)

Modified: pypy/dist/pypy/jit/timeshifter/rtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtyper.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rtyper.py	Thu Sep  7 18:52:45 2006
@@ -105,6 +105,20 @@
 
     def translate_op_hint(self, hop):
         # don't try to generate hint operations, just discard them
+        hints = hop.args_v[-1].value
+        if hints.get('forget', False):
+            T = originalconcretetype(hop.args_s[0])
+            v_redbox = hop.inputarg(self.getredrepr(T), arg=0)
+            assert isinstance(hop.r_result, GreenRepr)
+            ts = self.timeshifter
+            c_T = hop.inputconst(lltype.Void, T)
+            s_T = ts.rtyper.annotator.bookkeeper.immutablevalue(T)
+            s_res = annmodel.lltype_to_annotation(T)
+            return hop.llops.genmixlevelhelpercall(rvalue.ll_getvalue,
+                                                   [ts.s_RedBox, s_T],
+                                                   [v_redbox,    c_T],
+                                                   s_res)
+                                                   
         return hop.inputarg(hop.r_result, arg=0)
 
     def translate_op_debug_log_exc(self, hop): # don't timeshift debug_log_exc
@@ -231,6 +245,22 @@
             [v_jitstate,    c_fielddesc, v_destbox,   v_valuebox],
             annmodel.s_None)
 
+    def translate_op_setarrayitem(self, hop):
+        PTRTYPE = originalconcretetype(hop.args_s[0])
+        VALUETYPE = PTRTYPE.TO.OF
+        ts = self.timeshifter
+        v_argbox, v_index, v_valuebox= hop.inputargs(self.getredrepr(PTRTYPE),
+                                                     self.getredrepr(lltype.Signed),
+                                                     self.getredrepr(VALUETYPE))
+        fielddesc = rcontainer.ArrayFieldDesc(self.RGenOp, PTRTYPE)
+        c_fielddesc = inputconst(lltype.Void, fielddesc)
+        s_fielddesc = ts.rtyper.annotator.bookkeeper.immutablevalue(fielddesc)
+        v_jitstate = hop.llops.getjitstate()
+        hop.llops.genmixlevelhelpercall(rtimeshift.ll_gensetarrayitem,
+            [ts.s_JITState, s_fielddesc, ts.s_RedBox, ts.s_RedBox, ts.s_RedBox],
+            [v_jitstate,    c_fielddesc, v_argbox,    v_index    , v_valuebox ],
+            ts.s_RedBox)
+
     def translate_op_getsubstruct(self, hop):
         ##if isinstance(hop.args_r[0], BlueRepr):
         ##    return hop.args_r[0].timeshift_getsubstruct(hop)

Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	Thu Sep  7 18:52:45 2006
@@ -541,6 +541,8 @@
         assert res == 24
         self.check_insns({})
 
+
+
     def test_simple_struct_malloc(self):
         py.test.skip("blue containers: to be reimplemented")
         S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
@@ -696,6 +698,33 @@
         assert res == 42
         self.check_insns({})
 
+
+    def test_setarrayitem(self):
+        A = lltype.GcArray(lltype.Signed)
+        a = lltype.malloc(A, 2, immortal=True)
+        def ll_function():
+            a[0] = 1
+            a[1] = 2
+            return a[0]+a[1]
+        
+        res = self.timeshift(ll_function, [], [], policy=P_NOVIRTUAL)
+        assert res == 3
+
+##     def test_red_array(self):
+##          A = lltype.GcArray(lltype.Signed)
+##          def ll_function(x, y, n):
+##              a = lltype.malloc(A, 2)
+##              a[0] = x
+##              a[1] = y
+##              return a[n]
+
+##          res = self.timeshift(ll_function, [42, -42, 0], [], policy=P_NOVIRTUAL)
+##          assert res == 42
+
+##          res = self.timeshift(ll_function, [42, -42, 1], [], policy=P_NOVIRTUAL)
+##          assert res == -42
+
+
     def test_red_propagate(self):
         S = lltype.GcStruct('S', ('n', lltype.Signed))
         def ll_function(n, k):



More information about the Pypy-commit mailing list