[pypy-svn] r65876 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Tue Jun 23 12:01:42 CEST 2009


Author: arigo
Date: Tue Jun 23 12:01:40 2009
New Revision: 65876

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
Log:
Getting the length of the '[*]' arrays.


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py	Tue Jun 23 12:01:40 2009
@@ -911,6 +911,19 @@
         self.emit(self.var_position(op.args[1]))
         self.emit(self.var_position(op.args[2]))
 
+    def serialize_op_getarraysize(self, op):
+        ARRAY = op.args[0].concretetype.TO
+        assert ARRAY._gckind == 'gc'
+        if op.args[0] in self.vable_array_vars:     # for virtualizables
+            self.emit('arraylen_vable',
+                      self.vable_array_vars[op.args[0]])
+            self.register_var(op.result)
+            return
+        # normal case follows
+        self.emit('arraylen_gc')
+        self.emit(self.var_position(op.args[0]))
+        self.register_var(op.result)
+
     def serialize_op_getinteriorarraysize(self, op):
         # XXX only supports strings and unicodes for now
         assert len(op.args) == 2

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Tue Jun 23 12:01:40 2009
@@ -484,6 +484,13 @@
         self.metainterp.virtualizable_boxes[index] = valuebox
         self.metainterp.synchronize_virtualizable()
         # XXX only the index'th field needs to be synchronized, really
+    @arguments("int")
+    def opimpl_arraylen_vable(self, arrayindex):
+        vinfo = self.metainterp.staticdata.virtualizable_info
+        virtualizable_box = self.metainterp.virtualizable_boxes[-1]
+        virtualizable = virtualizable_box.getptr(vinfo.VTYPEPTR)
+        result = vinfo.get_array_length(virtualizable, arrayindex)
+        self.make_result_box(ConstInt(result))
 
     def perform_call(self, jitcode, varargs):
         if (isinstance(self.metainterp.history, history.BlackHole) and

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	Tue Jun 23 12:01:40 2009
@@ -201,7 +201,33 @@
         assert f(18) == 10360
         res = self.meta_interp(f, [18])
         assert res == 10360
-        self.check_loops(getfield_gc=0, setfield_gc=0)
+        self.check_loops(getfield_gc=0, setfield_gc=0,
+                         getarrayitem_gc=0)
+
+    def test_array_length(self):
+        myjitdriver = JitDriver(greens = [], reds = ['n', 'xy2'],
+                                virtualizables = ['xy2'])
+        ARRAY = lltype.GcArray(lltype.Signed)
+        def g(xy2, n):
+            while n > 0:
+                myjitdriver.can_enter_jit(xy2=xy2, n=n)
+                myjitdriver.jit_merge_point(xy2=xy2, n=n)
+                xy2.inst_l1[1] += len(xy2.inst_l2)
+                n -= 1
+        def f(n):
+            xy2 = self.setup2()
+            xy2.inst_x = 2
+            xy2.inst_l1 = lltype.malloc(ARRAY, 2)
+            xy2.inst_l1[0] = 1941309
+            xy2.inst_l1[1] = 2941309
+            xy2.inst_l2 = lltype.malloc(ARRAY, 1)
+            xy2.inst_l2[0] = 10000
+            g(xy2, n)
+            return xy2.inst_l1[1]
+        res = self.meta_interp(f, [18])
+        assert res == 2941309 + 18
+        self.check_loops(getfield_gc=0, setfield_gc=0,
+                         getarrayitem_gc=0, arraylen_gc=0)
 
 
 class ImplicitVirtualizableTests:



More information about the Pypy-commit mailing list