[pypy-svn] r24312 - in pypy/dist/pypy/jit: . test

pedronis at codespeak.net pedronis at codespeak.net
Mon Mar 13 17:12:53 CET 2006


Author: pedronis
Date: Mon Mar 13 17:12:46 2006
New Revision: 24312

Modified:
   pypy/dist/pypy/jit/hintrtyper.py
   pypy/dist/pypy/jit/rtimeshift.py
   pypy/dist/pypy/jit/test/test_hint_timeshift.py
Log:
proper getarrayitem support



Modified: pypy/dist/pypy/jit/hintrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/hintrtyper.py	(original)
+++ pypy/dist/pypy/jit/hintrtyper.py	Mon Mar 13 17:12:46 2006
@@ -118,6 +118,25 @@
             [v_jitstate,    c_fielddesc, v_argbox,    c_fieldname,  c_resulttype],
             ts.s_RedBox)
 
+    def translate_op_getarrayitem(self, hop):
+        ts = self.timeshifter
+        PTRTYPE = originalconcretetype(hop.args_s[0])
+        RESTYPE = originalconcretetype(hop.s_result)
+        v_argbox, v_index = hop.inputargs(self.getredrepr(PTRTYPE),
+                                          self.getredrepr(lltype.Signed))
+        fielddesc = rtimeshift.make_fielddesc(PTRTYPE, '-')
+        c_fielddesc = inputconst(lltype.Void, fielddesc)
+        s_fielddesc = ts.rtyper.annotator.bookkeeper.immutablevalue(fielddesc)
+        gv_resulttype = rgenop.constTYPE(RESTYPE)
+        c_resulttype = hop.inputconst(rgenop.CONSTORVAR, gv_resulttype)
+        v_jitstate = hop.llops.getjitstate()
+        s_CONSTORVAR = annmodel.SomePtr(rgenop.CONSTORVAR)
+        return hop.llops.genmixlevelhelpercall(rtimeshift.ll_generate_getarrayitem,
+            [ts.s_JITState, s_fielddesc, ts.s_RedBox, ts.s_RedBox, s_CONSTORVAR],
+            [v_jitstate,    c_fielddesc, v_argbox,    v_index,     c_resulttype],
+            ts.s_RedBox)
+
+
 
 class HintLowLevelOpList(LowLevelOpList):
     """Warning: the HintLowLevelOpList's rtyper is the *original*

Modified: pypy/dist/pypy/jit/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/rtimeshift.py	(original)
+++ pypy/dist/pypy/jit/rtimeshift.py	Mon Mar 13 17:12:46 2006
@@ -208,6 +208,21 @@
                           gv_resulttype)
     return VarRedBox(genvar)
 
+
+def ll_generate_getarrayitem(jitstate, fielddesc, argbox,
+                             indexbox, gv_resulttype):
+    if (fielddesc.immutable and
+        isinstance(argbox, ConstRedBox) and isinstance(indexbox, ConstRedBox)):        
+        res = argbox.ll_getvalue(fielddesc.PTRTYPE)[indexbox.ll_getvalue(lltype.Signed)]
+        return ConstRedBox.ll_fromvalue(res)
+    op_args = lltype.malloc(VARLIST.TO, 2)
+    op_args[0] = argbox.getgenvar()
+    op_args[1] = indexbox.getgenvar()
+    genvar = rgenop.genop(jitstate.curblock, 'getarrayitem', op_args,
+                          gv_resulttype)
+    return VarRedBox(genvar)
+
+
 # ____________________________________________________________
 # other jitstate/graph level operations
 

Modified: pypy/dist/pypy/jit/test/test_hint_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_hint_timeshift.py	(original)
+++ pypy/dist/pypy/jit/test/test_hint_timeshift.py	Mon Mar 13 17:12:46 2006
@@ -268,3 +268,19 @@
     insns, res = timeshift(ll_function, [s1], [0])
     assert res == 42
     assert insns == {}
+
+def test_simple_array():
+    A = lltype.GcArray(lltype.Signed, 
+                        hints={'immutable': True})
+    def ll_function(a):
+        return a[0] * a[1]
+    a1 = lltype.malloc(A, 2)
+    a1[0] = 6
+    a1[1] = 7
+    insns, res = timeshift(ll_function, [a1], [])
+    assert res == 42
+    assert insns == {'getarrayitem': 2,
+                     'int_mul': 1}
+    insns, res = timeshift(ll_function, [a1], [0])
+    assert res == 42
+    assert insns == {}



More information about the Pypy-commit mailing list