1. Pypy
  2. Untitled project
  3. pypy

Commits

Maciej Fijalkowski  committed 9d52e03

always pure operations don't have to reset anything. Add float vector_sub

  • Participants
  • Parent commits 4be184b
  • Branches backend-vector-ops

Comments (0)

Files changed (4)

File pypy/jit/metainterp/executor.py

View file
  • Ignore whitespace
 # ____________________________________________________________
 
 
-IGNORED = ['FLOAT_VECTOR_ADD', 'GETARRAYITEM_VECTOR_RAW',
+IGNORED = ['FLOAT_VECTOR_ADD', 'FLOAT_VECTOR_SUB',
+           'GETARRAYITEM_VECTOR_RAW',
            'SETARRAYITEM_VECTOR_RAW', 'ASSERT_ALIGNED']
 
 def _make_execute_list():

File pypy/jit/metainterp/optimizeopt/test/test_vectorize.py

View file
  • Ignore whitespace
 class TestVectorize(BaseTestBasic, LLtypeMixin):
     enable_opts = "intbounds:rewrite:virtualize:string:earlyforce:pure:heap:unroll:vectorize"
 
-    def test_vectorize_basic(self):
+    def test_basic(self):
         ops = """
         [p0, p1, p2, i0, i1, i2]
         assert_aligned(p0, i0)
         """
         self.optimize_loop(ops, expected)
 
-    def test_vectorize_unfit_trees(self):
+    def test_basic_sub(self):
+        ops = """
+        [p0, p1, p2, i0, i1, i2]
+        assert_aligned(p0, i0)
+        assert_aligned(p1, i1)
+        assert_aligned(p1, i2)
+        f0 = getarrayitem_raw(p0, i0, descr=arraydescr)
+        f1 = getarrayitem_raw(p1, i1, descr=arraydescr)
+        f2 = float_sub(f0, f1)
+        setarrayitem_raw(p2, i2, f2, descr=arraydescr)
+        i0_1 = int_add(i0, 1)
+        i1_1 = int_add(1, i1)
+        i3 = int_sub(i1_1, 2)
+        i2_1 = int_add(i2, 1)
+        f0_1 = getarrayitem_raw(p0, i0_1, descr=arraydescr)
+        f1_1 = getarrayitem_raw(p1, i1_1, descr=arraydescr)
+        f2_1 = float_sub(f0_1, f1_1)
+        setarrayitem_raw(p2, i2_1, f2_1, descr=arraydescr)
+        finish(p0, p1, p2, i0_1, i1_1, i2_1, i3)
+        """
+        expected = """
+        [p0, p1, p2, i0, i1, i2]
+        i0_1 = int_add(i0, 1)
+        i1_1 = int_add(1, i1)
+        i3 = int_sub(i1_1, 2)
+        i2_1 = int_add(i2, 1)
+        vec0 = getarrayitem_vector_raw(p0, i0, descr=arraydescr)
+        vec1 = getarrayitem_vector_raw(p1, i1, descr=arraydescr)
+        vec2 = float_vector_sub(vec0, vec1)
+        setarrayitem_vector_raw(p2, i2, vec2, descr=arraydescr)
+        finish(p0, p1, p2, i0_1, i1_1, i2_1, i3)
+        """
+        self.optimize_loop(ops, expected)
+
+    def test_unfit_trees(self):
         ops = """
         [p0, p1, p2, i0, i1, i2]
         assert_aligned(p0, i0)
         finish(p0, p1, p2, i0_1, i1_1, i2_1)
         """
         self.optimize_loop(ops, expected)
+
+    def test_unfit_trees_2(self):
+        ops = """
+        [p0, p1, p2, i0, i1, i2]
+        assert_aligned(p0, i0)
+        assert_aligned(p1, i1)
+        assert_aligned(p1, i2)
+        f0 = getarrayitem_raw(p0, i0, descr=arraydescr)
+        f1 = getarrayitem_raw(p1, i1, descr=arraydescr)
+        f2 = float_add(f0, f1)
+        setarrayitem_raw(p2, i2, f2, descr=arraydescr)
+        i0_1 = int_add(i0, 1)
+        i1_1 = int_add(1, i1)
+        i2_1 = int_add(i2, 1)
+        f0_1 = getarrayitem_raw(p0, i0_1, descr=arraydescr)
+        setarrayitem_raw(p2, i2_1, f0_1, descr=arraydescr)
+        finish(p0, p1, p2, i0_1, i1_1, i2_1)
+        """
+        expected = """
+        [p0, p1, p2, i0, i1, i2]
+        i0_1 = int_add(i0, 1)
+        i1_1 = int_add(1, i1)
+        i2_1 = int_add(i2, 1)
+        f0 = getarrayitem_raw(p0, i0, descr=arraydescr)
+        f1 = getarrayitem_raw(p1, i1, descr=arraydescr)
+        f2 = float_add(f0, f1)
+        setarrayitem_raw(p2, i2, f2, descr=arraydescr)
+        f0_1 = getarrayitem_raw(p0, i0_1, descr=arraydescr)
+        setarrayitem_raw(p2, i2_1, f0_1, descr=arraydescr)
+        finish(p0, p1, p2, i0_1, i1_1, i2_1)
+        """
+        self.optimize_loop(ops, expected)
+
+    def test_unfit_trees_3(self):
+        ops = """
+        [p0, p1, p2, i0, i1, i2]
+        assert_aligned(p0, i0)
+        assert_aligned(p1, i1)
+        assert_aligned(p1, i2)
+        f0 = getarrayitem_raw(p0, i0, descr=arraydescr)
+        f1 = getarrayitem_raw(p1, i1, descr=arraydescr)
+        f2 = float_add(f0, f1)
+        setarrayitem_raw(p2, i2, f2, descr=arraydescr)
+        i0_1 = int_add(i0, 1)
+        i1_1 = int_add(1, i1)
+        i2_1 = int_add(i2, 1)
+        f0_1 = getarrayitem_raw(p0, i0_1, descr=arraydescr)
+        f1_1 = getarrayitem_raw(p1, i1_1, descr=arraydescr)
+        f2_1 = float_sub(f0_1, f1_1)
+        setarrayitem_raw(p2, i2_1, f2_1, descr=arraydescr)
+        finish(p0, p1, p2, i0_1, i1_1, i2_1)
+        """
+        expected = """
+        [p0, p1, p2, i0, i1, i2]
+        i0_1 = int_add(i0, 1)
+        i1_1 = int_add(1, i1)
+        i2_1 = int_add(i2, 1)
+        f0 = getarrayitem_raw(p0, i0, descr=arraydescr)
+        f1 = getarrayitem_raw(p1, i1, descr=arraydescr)
+        f2 = float_add(f0, f1)
+        setarrayitem_raw(p2, i2, f2, descr=arraydescr)
+        f0_1 = getarrayitem_raw(p0, i0_1, descr=arraydescr)
+        f1_1 = getarrayitem_raw(p1, i1_1, descr=arraydescr)
+        f2_1 = float_sub(f0_1, f1_1)
+        setarrayitem_raw(p2, i2_1, f2_1, descr=arraydescr)
+        finish(p0, p1, p2, i0_1, i1_1, i2_1)
+        """
+        self.optimize_loop(ops, expected)
+        

File pypy/jit/metainterp/optimizeopt/vectorize.py

View file
  • Ignore whitespace
 from pypy.jit.metainterp.history import BoxVector
 
 VECTOR_SIZE = 2
-VEC_MAP = {rop.FLOAT_ADD: rop.FLOAT_VECTOR_ADD}
+VEC_MAP = {rop.FLOAT_ADD: rop.FLOAT_VECTOR_ADD,
+           rop.FLOAT_SUB: rop.FLOAT_VECTOR_SUB}
 
 class BaseTrack(object):
     pass
             return
         self.tracked_indexes[self.getvalue(op.result)] = self.tracked_indexes[index].advance()
 
-    def optimize_FLOAT_ADD(self, op):
+    def _optimize_binop(self, op):
         left = self.getvalue(op.getarg(0))
         right = self.getvalue(op.getarg(1))
         if left not in self.track or right not in self.track:
             rt = self.track[right]
             self.track[self.getvalue(op.result)] = BinOp(lt, rt, op)
 
+    optimize_FLOAT_ADD = _optimize_binop
+    optimize_FLOAT_SUB = _optimize_binop
+
     def optimize_SETARRAYITEM_RAW(self, op):
         index = self.getvalue(op.getarg(1))
         val = self.getvalue(op.getarg(2))
             self.emit_vector_ops(op.getarglist())
         elif op.is_guard():
             xxx
+        elif op.is_always_pure():
+            # in theory no side effect ops, but stuff like malloc
+            # can go in the way
+            pass
         else:
             self.reset()
         self.emit_operation(op)

File pypy/jit/metainterp/resoperation.py

View file
  • Ignore whitespace
     'FLOAT_NEG/1',
     'FLOAT_ABS/1',
     'FLOAT_VECTOR_ADD/2',
+    'FLOAT_VECTOR_SUB/2',
     'CAST_FLOAT_TO_INT/1',          # don't use for unsigned ints; we would
     'CAST_INT_TO_FLOAT/1',          # need some messy code in the backend
     'CAST_FLOAT_TO_SINGLEFLOAT/1',