[pypy-commit] pypy vecopt-merge: implemented (g/s)etarrayitem_(gc/raw)[_pure] for vector operations. the assembler was missing

plan_rich noreply at buildbot.pypy.org
Fri Aug 21 14:50:10 CEST 2015


Author: Richard Plangger <rich at pasra.at>
Branch: vecopt-merge
Changeset: r79110:dcfb609c4b12
Date: 2015-08-21 14:50 +0200
http://bitbucket.org/pypy/pypy/changeset/dcfb609c4b12/

Log:	implemented (g/s)etarrayitem_(gc/raw)[_pure] for vector operations.
	the assembler was missing added a test case to verify

diff --git a/rpython/jit/backend/x86/vector_ext.py b/rpython/jit/backend/x86/vector_ext.py
--- a/rpython/jit/backend/x86/vector_ext.py
+++ b/rpython/jit/backend/x86/vector_ext.py
@@ -138,6 +138,8 @@
         self._vec_load(resloc, src_addr, integer_loc.value,
                        size_loc.value, aligned_loc.value)
 
+    genop_vec_getarrayitem_gc = genop_vec_getarrayitem_raw
+
     def genop_vec_raw_load(self, op, arglocs, resloc):
         base_loc, ofs_loc, size_loc, ofs, integer_loc, aligned_loc = arglocs
         src_addr = addr_add(base_loc, ofs_loc, ofs.value, 0)
@@ -164,6 +166,8 @@
         self._vec_store(dest_loc, value_loc, integer_loc.value,
                         size_loc.value, aligned_loc.value)
 
+    genop_discard_vec_setarrayitem_gc = genop_discard_vec_setarrayitem_raw
+
     def genop_discard_vec_raw_store(self, op, arglocs):
         base_loc, ofs_loc, value_loc, size_loc, baseofs, integer_loc, aligned_loc = arglocs
         dest_loc = addr_add(base_loc, ofs_loc, baseofs.value, 0)
@@ -560,6 +564,7 @@
         self.perform(op, [base_loc, ofs_loc, imm(itemsize), imm(ofs),
                           imm(integer), imm(aligned)], result_loc)
 
+    consider_vec_getarrayitem_gc = consider_vec_getarrayitem_raw
     consider_vec_raw_load = consider_vec_getarrayitem_raw
 
     def consider_vec_setarrayitem_raw(self, op):
@@ -578,6 +583,7 @@
         self.perform_discard(op, [base_loc, ofs_loc, value_loc,
                                  imm(itemsize), imm(ofs), imm(integer), imm(aligned)])
 
+    consider_vec_setarrayitem_gc = consider_vec_setarrayitem_raw
     consider_vec_raw_store = consider_vec_setarrayitem_raw
 
     def consider_vec_arith(self, op):
diff --git a/rpython/jit/metainterp/optimizeopt/guard.py b/rpython/jit/metainterp/optimizeopt/guard.py
--- a/rpython/jit/metainterp/optimizeopt/guard.py
+++ b/rpython/jit/metainterp/optimizeopt/guard.py
@@ -265,7 +265,7 @@
         self.eliminate_guards(loop)
         #
         if len(loop.versions) >= 2:
-            assert len(loop.version) == 2
+            assert len(loop.versions) == 2
             root_version = loop.versions[0]
             version = loop.versions[1]
 
diff --git a/rpython/jit/metainterp/resoperation.py b/rpython/jit/metainterp/resoperation.py
--- a/rpython/jit/metainterp/resoperation.py
+++ b/rpython/jit/metainterp/resoperation.py
@@ -807,6 +807,10 @@
     rop.RAW_LOAD:         rop.VEC_RAW_LOAD,
     rop.GETARRAYITEM_RAW: rop.VEC_GETARRAYITEM_RAW,
     rop.GETARRAYITEM_GC: rop.VEC_GETARRAYITEM_GC,
+    # note that there is no _PURE operation for vector operations.
+    # reason: currently we do not care if it is pure or not!
+    rop.GETARRAYITEM_RAW_PURE: rop.VEC_GETARRAYITEM_RAW,
+    rop.GETARRAYITEM_GC_PURE: rop.VEC_GETARRAYITEM_GC,
     rop.RAW_STORE:        rop.VEC_RAW_STORE,
     rop.SETARRAYITEM_RAW: rop.VEC_SETARRAYITEM_RAW,
     rop.SETARRAYITEM_GC: rop.VEC_SETARRAYITEM_GC,
diff --git a/rpython/jit/metainterp/test/test_vectorize.py b/rpython/jit/metainterp/test/test_vectorize.py
--- a/rpython/jit/metainterp/test/test_vectorize.py
+++ b/rpython/jit/metainterp/test/test_vectorize.py
@@ -283,6 +283,27 @@
         res = self.meta_interp(f, [i])
         assert res == f(i)
 
+    @py.test.mark.parametrize('i,v1,v2',[(25,2.5,0.3)])
+    def test_list_vectorize(self,i,v1,v2):
+        myjitdriver = JitDriver(greens = [],
+                                reds = 'auto')
+        def f(d, v1, v2):
+            a = [v1] * d
+            b = [v2] * d
+            i = 0
+            while i < len(a):
+                myjitdriver.jit_merge_point()
+                a[i] = a[i] + b[i]
+                i += 1
+            s = 0
+            for i in range(d):
+                s += a[i]
+            return s
+        res = self.meta_interp(f, [i,v1,v2], vec_all=True)
+        # sum helps to generate the rounding error of floating points
+        # return 69.999 ... instead of 70, (v1+v2)*i == 70.0
+        assert res == f(i,v1,v2) == sum([v1+v2]*i)
+
 class VectorizeLLtypeTests(VectorizeTests):
     pass
 


More information about the pypy-commit mailing list