Author: Richard Plangger <[email protected]>
Branch: vecopt2
Changeset: r77077:3a769fdc9cec
Date: 2015-03-13 10:08 +0100
http://bitbucket.org/pypy/pypy/changeset/3a769fdc9cec/
Log: added missing vectorize flag for test cases. all passed in
jit/metainterp
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py
b/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_vectorize.py
@@ -301,8 +301,8 @@
vopt.find_adjacent_memory_refs()
mref1 = vopt.vec_info.memory_refs[1]
assert isinstance(mref1, MemoryRef)
- assert mref1.factor_c == 1
- assert mref1.factor_d == 0
+ assert mref1.coefficient_mul == 1
+ assert mref1.constant == 0
def test_array_memory_ref_2(self):
ops = """
@@ -316,8 +316,8 @@
vopt.find_adjacent_memory_refs()
mref1 = vopt.vec_info.memory_refs[2]
assert isinstance(mref1, MemoryRef)
- assert mref1.factor_c == 1
- assert mref1.factor_d == 1
+ assert mref1.coefficient_mul == 1
+ assert mref1.constant == 1
def test_array_memory_ref_sub_index(self):
ops = """
@@ -331,8 +331,8 @@
vopt.find_adjacent_memory_refs()
mref1 = vopt.vec_info.memory_refs[2]
assert isinstance(mref1, MemoryRef)
- assert mref1.factor_c == 1
- assert mref1.factor_d == -1
+ assert mref1.coefficient_mul == 1
+ assert mref1.constant == -1
def test_array_memory_ref_add_mul_index(self):
ops = """
@@ -347,8 +347,8 @@
vopt.find_adjacent_memory_refs()
mref1 = vopt.vec_info.memory_refs[3]
assert isinstance(mref1, MemoryRef)
- assert mref1.factor_c == 3
- assert mref1.factor_d == 3
+ assert mref1.coefficient_mul == 3
+ assert mref1.constant == 3
def test_array_memory_ref_add_mul_index_interleaved(self):
ops = """
@@ -365,8 +365,8 @@
vopt.find_adjacent_memory_refs()
mref1 = vopt.vec_info.memory_refs[5]
assert isinstance(mref1, MemoryRef)
- assert mref1.factor_c == 18
- assert mref1.factor_d == 48
+ assert mref1.coefficient_mul == 18
+ assert mref1.constant == 48
ops = """
[p0,i0]
@@ -384,8 +384,9 @@
vopt.find_adjacent_memory_refs()
mref1 = vopt.vec_info.memory_refs[7]
assert isinstance(mref1, MemoryRef)
- assert mref1.factor_c == 1026
- assert mref1.factor_d == 57*(30) + 57*6*(5) + 57*6*3*(1)
+ assert mref1.coefficient_mul == 1026
+ assert mref1.coefficient_div == 1
+ assert mref1.constant == 57*(30) + 57*6*(5) + 57*6*3*(1)
def test_array_memory_ref_sub_mul_index_interleaved(self):
ops = """
@@ -402,8 +403,9 @@
vopt.find_adjacent_memory_refs()
mref1 = vopt.vec_info.memory_refs[5]
assert isinstance(mref1, MemoryRef)
- assert mref1.factor_c == 6
- assert mref1.factor_d == 0
+ assert mref1.coefficient_mul == 6
+ assert mref1.coefficient_div == 1
+ assert mref1.constant == 0
def test_array_memory_ref_not_adjacent_1(self):
ops = """
@@ -439,6 +441,94 @@
self.assert_memory_ref_not_adjacent(mref1, mref3)
self.assert_memory_ref_not_adjacent(mref1, mref7)
self.assert_memory_ref_adjacent(mref3, mref7)
+ assert mref1.is_adjacent_after(mref5)
+
+ def test_array_memory_ref_div(self):
+ ops = """
+ [p0,i0]
+ i1 = int_floordiv(i0,2)
+ i2 = int_floordiv(i1,8)
+ i3 = raw_load(p0,i2,descr=chararraydescr)
+ jump(p0,i2)
+ """
+ vopt = self.vec_optimizer_unrolled(self.parse_loop(ops),1)
+ vopt.build_dependency_graph()
+ vopt.find_adjacent_memory_refs()
+ mref = vopt.vec_info.memory_refs[3]
+ assert mref.coefficient_div == 16
+ ops = """
+ [p0,i0]
+ i1 = int_add(i0,8)
+ i2 = uint_floordiv(i1,2)
+ i3 = raw_load(p0,i2,descr=chararraydescr)
+ jump(p0,i2)
+ """
+ vopt = self.vec_optimizer_unrolled(self.parse_loop(ops),1)
+ vopt.build_dependency_graph()
+ vopt.find_adjacent_memory_refs()
+ mref = vopt.vec_info.memory_refs[3]
+ assert mref.coefficient_div == 2
+ assert mref.constant == 4
+ ops = """
+ [p0,i0]
+ i1 = int_add(i0,8)
+ i2 = int_floordiv(i1,2)
+ i3 = raw_load(p0,i2,descr=chararraydescr)
+ i4 = int_add(i0,4)
+ i5 = int_mul(i4,2)
+ i6 = raw_load(p0,i5,descr=chararraydescr)
+ jump(p0,i2)
+ """
+ vopt = self.vec_optimizer_unrolled(self.parse_loop(ops),1)
+ vopt.build_dependency_graph()
+ vopt.find_adjacent_memory_refs()
+ mref = vopt.vec_info.memory_refs[3]
+ mref2 = vopt.vec_info.memory_refs[6]
+
+ self.assert_memory_ref_not_adjacent(mref, mref2)
+ assert mref != mref2
+
+ def test_array_memory_ref_diff_calc_but_equal(self):
+ ops = """
+ [p0,i0]
+ i1 = int_add(i0,4)
+ i2 = int_mul(i1,2)
+ i3 = raw_load(p0,i2,descr=chararraydescr)
+ i4 = int_add(i0,2)
+ i5 = int_mul(i4,2)
+ i6 = int_add(i5,4)
+ i7 = raw_load(p0,i6,descr=chararraydescr)
+ jump(p0,i2)
+ """
+ vopt = self.vec_optimizer_unrolled(self.parse_loop(ops),1)
+ vopt.build_dependency_graph()
+ vopt.find_adjacent_memory_refs()
+ mref = vopt.vec_info.memory_refs[3]
+ mref2 = vopt.vec_info.memory_refs[7]
+
+ self.assert_memory_ref_not_adjacent(mref, mref2)
+ assert mref == mref2
+
+ def test_array_memory_ref_diff_calc_but_equal(self):
+ ops = """
+ [p0,i0]
+ i1 = int_add(i0,4)
+ i2 = int_floor(i1,2)
+ i3 = raw_load(p0,i2,descr=chararraydescr)
+ i4 = int_add(i0,2)
+ i5 = int_mul(i4,2)
+ i6 = int_add(i5,4)
+ i7 = raw_load(p0,i6,descr=chararraydescr)
+ jump(p0,i2)
+ """
+ vopt = self.vec_optimizer_unrolled(self.parse_loop(ops),1)
+ vopt.build_dependency_graph()
+ vopt.find_adjacent_memory_refs()
+ mref = vopt.vec_info.memory_refs[3]
+ mref2 = vopt.vec_info.memory_refs[7]
+
+ self.assert_memory_ref_not_adjacent(mref, mref2)
+ assert mref == mref2
class TestLLtype(BaseTestDependencyGraph, LLtypeMixin):
diff --git a/rpython/jit/metainterp/optimizeopt/vectorize.py
b/rpython/jit/metainterp/optimizeopt/vectorize.py
--- a/rpython/jit/metainterp/optimizeopt/vectorize.py
+++ b/rpython/jit/metainterp/optimizeopt/vectorize.py
@@ -1,5 +1,5 @@
import sys
-
+import py
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.jit.metainterp.optimizeopt.optimizer import Optimizer,
Optimization
from rpython.jit.metainterp.optimizeopt.util import make_dispatcher_method
@@ -206,6 +206,10 @@
return False
class IntegralMod(object):
+ """ Calculates integral modifications on an integer object.
+ The operations must be provided in backwards direction and of one
+ variable only. Call reset() to reuse this object for other variables.
+ """
def __init__(self, optimizer):
self.optimizer = optimizer
@@ -213,8 +217,9 @@
def reset(self):
self.is_const_mod = False
- self.factor_c = 1
- self.factor_d = 0
+ self.coefficient_mul = 1
+ self.coefficient_div = 1
+ self.constant = 0
self.used_box = None
def operation_INT_SUB(self, op):
@@ -222,61 +227,86 @@
box_a1 = op.getarg(1)
a0 = self.optimizer.getvalue(box_a0)
a1 = self.optimizer.getvalue(box_a1)
+ self.is_const_mod = True
if a0.is_constant() and a1.is_constant():
raise NotImplementedError()
elif a0.is_constant():
- self.is_const_mod = True
- self.factor_d -= box_a0.getint() * self.factor_c
+ self.constant -= box_a0.getint() * self.coefficient_mul
self.used_box = box_a1
elif a1.is_constant():
- self.is_const_mod = True
- self.factor_d -= box_a1.getint() * self.factor_c
+ self.constant -= box_a1.getint() * self.coefficient_mul
self.used_box = box_a0
+ else:
+ self.is_const_mod = False
- def operation_INT_ADD(self, op):
+ def _update_additive(self, i):
+ return (i * self.coefficient_mul) / self.coefficient_div
+
+ additive_func_source = """
+ def operation_{name}(self, op):
box_a0 = op.getarg(0)
box_a1 = op.getarg(1)
a0 = self.optimizer.getvalue(box_a0)
a1 = self.optimizer.getvalue(box_a1)
+ self.is_const_mod = True
if a0.is_constant() and a1.is_constant():
- # this means that the overall array offset is not
- # added to a variable, but is constant
- raise NotImplementedError()
+ self.used_box = None
+ self.constant += self._update_additive(box_a0.getint() {op} \
+ box_a1.getint())
elif a0.is_constant():
- self.is_const_mod = True
- self.factor_d += box_a0.getint() * self.factor_c
+ self.constant {op}= self._update_additive(box_a0.getint())
self.used_box = box_a1
elif a1.is_constant():
- self.is_const_mod = True
- print('add', box_a1.getint(), self.factor_c)
- self.factor_d += box_a1.getint() * self.factor_c
+ self.constant {op}= self._update_additive(box_a1.getint())
self.used_box = box_a0
+ else:
+ self.is_const_mod = False
+ """
+ exec py.code.Source(additive_func_source.format(name='INT_ADD',
+ op='+')).compile()
+ exec py.code.Source(additive_func_source.format(name='INT_SUB',
+ op='-')).compile()
+ del additive_func_source
- def operation_INT_MUL(self, op):
- """ Whenever a multiplication occurs this only alters the
- factor_c. When later a plus occurs, factor_c multiplies the added
- operand. """
+ multiplicative_func_source = """
+ def operation_{name}(self, op):
box_a0 = op.getarg(0)
box_a1 = op.getarg(1)
a0 = self.optimizer.getvalue(box_a0)
a1 = self.optimizer.getvalue(box_a1)
+ self.is_const_mod = True
if a0.is_constant() and a1.is_constant():
- # this means that the overall array offset is not
- # added to a variable, but is constant
- raise NotImplementedError()
+ # here these factor becomes a constant, thus it is
+ # handled like any other additive operation
+ self.used_box = None
+ self.constant += self._update_additive(box_a0.getint() {cop} \
+ box_a1.getint())
elif a0.is_constant():
- self.is_const_mod = True
- self.factor_c *= box_a0.getint()
+ self.coefficient_{tgt} {op}= box_a0.getint()
self.used_box = box_a1
elif a1.is_constant():
- self.is_const_mod = True
- self.factor_c *= box_a1.getint()
+ self.coefficient_{tgt} {op}= box_a1.getint()
self.used_box = box_a0
+ else:
+ self.is_const_mod = False
+ """
+ exec py.code.Source(multiplicative_func_source.format(name='INT_MUL',
+ op='*', tgt='mul',
+ cop='*')).compile()
+ exec py.code.Source(multiplicative_func_source.format(name='INT_FLOORDIV',
+ op='*', tgt='div',
+ cop='/')).compile()
+ exec py.code.Source(multiplicative_func_source.format(name='UINT_FLOORDIV',
+ op='*', tgt='div',
+ cop='/')).compile()
+ del multiplicative_func_source
+
def update_memory_ref(self, memref):
#print("updating memory ref pre: ", memref)
- memref.factor_d = self.factor_d
- memref.factor_c = self.factor_c
+ memref.constant = self.constant
+ memref.coefficient_mul = self.coefficient_mul
+ memref.coefficient_div = self.coefficient_div
memref.origin = self.used_box
#print("updating memory ref post: ", memref)
@@ -334,18 +364,43 @@
self.array = array
self.origin = origin
self.descr = descr
- self.factor_c = 1
- self.factor_d = 0
+ self.coefficient_mul = 1
+ self.coefficient_div = 1
+ self.constant = 0
def is_adjacent_to(self, other):
""" this is a symmetric relation """
+ match, off = self.calc_difference(other)
+ if match:
+ return off == 1 or off == -1
+ return False
+
+ def is_adjacent_after(self, other):
+ """ the asymetric relation to is_adjacent_to """
+ match, off = self.calc_difference(other)
+ if match:
+ return off == 1
+ return False
+
+ def __eq__(self, other):
+ match, off = self.calc_difference(other)
+ if match:
+ return off == 0
+ return False
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+
+ def calc_difference(self, other):
if self.array == other.array \
and self.origin == other.origin:
- my_off = (self.factor_c * self.factor_d)
- other_off = (other.factor_c * other.factor_d)
- diff = my_off - other_off
- return diff == 1 or diff == -1
- return False
+ mycoeff = self.coefficient_mul // self.coefficient_div
+ othercoeff = other.coefficient_mul // other.coefficient_div
+ diff = other.constant - self.constant
+ return mycoeff == othercoeff, diff
+ return False, 0
def __repr__(self):
- return 'MemoryRef(%s,%s,%s)' % (self.origin, self.factor_c,
self.factor_d)
+ return 'MemoryRef(%s*(%s/%s)+%s)' % (self.origin, self.coefficient_mul,
+ self.coefficient_div,
self.constant)
diff --git a/rpython/jit/metainterp/test/support.py
b/rpython/jit/metainterp/test/support.py
--- a/rpython/jit/metainterp/test/support.py
+++ b/rpython/jit/metainterp/test/support.py
@@ -66,6 +66,7 @@
greenfield_info = None
result_type = result_kind
portal_runner_ptr = "???"
+ vectorize = False
stats = history.Stats()
cpu = CPUClass(rtyper, stats, None, False)
diff --git a/rpython/jit/metainterp/test/test_compile.py
b/rpython/jit/metainterp/test/test_compile.py
--- a/rpython/jit/metainterp/test/test_compile.py
+++ b/rpython/jit/metainterp/test/test_compile.py
@@ -61,6 +61,7 @@
class jitdriver_sd:
warmstate = FakeState()
virtualizable_info = None
+ vectorize = False
def test_compile_loop():
cpu = FakeCPU()
diff --git a/rpython/jit/metainterp/warmspot.py
b/rpython/jit/metainterp/warmspot.py
--- a/rpython/jit/metainterp/warmspot.py
+++ b/rpython/jit/metainterp/warmspot.py
@@ -393,7 +393,6 @@
graph.func._jit_unroll_safe_ = True
jd.jitdriver = block.operations[pos].args[1].value
jd.vectorize = jd.jitdriver.vectorize
- del jd.jitdriver.vectorize
jd.portal_runner_ptr = "<not set so far>"
jd.result_type = history.getkind(jd.portal_graph.getreturnvar()
.concretetype)[0]
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit