Author: Richard Plangger <planri...@gmail.com> Branch: vecopt-merge Changeset: r79881:8a8e13743c1e Date: 2015-09-28 15:09 +0200 http://bitbucket.org/pypy/pypy/changeset/8a8e13743c1e/
Log: pushing forward test_zjit on llgraph diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py --- a/pypy/module/micronumpy/test/test_zjit.py +++ b/pypy/module/micronumpy/test/test_zjit.py @@ -7,6 +7,7 @@ from rpython.jit.backend.x86.test.test_basic import Jit386Mixin from rpython.jit.metainterp.warmspot import reset_jit, get_stats from rpython.jit.metainterp.jitprof import Profiler +from rpython.jit.metainterp import counter from rpython.rlib.jit import Counters from rpython.rlib.rarithmetic import intmask from pypy.module.micronumpy import boxes @@ -17,7 +18,13 @@ from rpython.jit.metainterp import pyjitpl return pyjitpl._warmrunnerdesc.metainterp_sd.profiler -class TestNumpyJit(Jit386Mixin): +class TestNumPyLL(LLJitMixin): + llgraph = True + +class TestNumPyX86(Jit386Mixin): + llgraph = False + +class TestNumpyJit(LLJitMixin): enable_opts = "intbounds:rewrite:virtualize:string:earlyforce:pure:heap:unroll" graph = None interp = None @@ -98,11 +105,11 @@ backendopt=True, graph_and_interp_only=True, ProfilerClass=Profiler, - translate_support_code=True, - translationoptions={'gc':'minimark', - 'gcrootfinder': 'asmgcc', - 'gcremovetypeptr': False - }, + #translate_support_code=True, + #translationoptions={'gc':'minimark', + # 'gcrootfinder': 'asmgcc', + # 'gcremovetypeptr': False + # }, vec=True) self.__class__.interp = interp self.__class__.graph = graph @@ -119,6 +126,8 @@ self.compile_graph() profiler = get_profiler() profiler.start() + from rpython.jit.metainterp import pyjitpl + pyjitpl._warmrunnerdesc.jitcounter = counter.DeterministicJitCounter() reset_jit() i = self.code_mapping[name] retval = self.interp.eval_graph(self.graph, [i]) @@ -162,7 +171,7 @@ def test_float32_add(self): result = self.run("float32_add") self.assert_float_equal(result, 15.0 + 15.0) - self.check_vectorized(2, 2) + self.check_vectorized(1, 1) def define_float_add(): return """ @@ -195,7 +204,7 @@ def test_float32_add_const(self): result = self.run("float32_add_const") self.assert_float_equal(result, 29.0 + 77.345) - self.check_vectorized(2, 2) + self.check_vectorized(1, 1) def define_float_add_const(): return """ @@ -237,7 +246,7 @@ def test_int_expand(self): result = self.run("int_expand") assert int(result) == 7+16+8+16 - self.check_vectorized(2, 2) + self.check_vectorized(1, 1) def define_int32_expand(): return """ @@ -303,7 +312,7 @@ def test_int32_add_const(self): result = self.run("int32_add_const") assert int(result) == 7+1+8+1+11+2+12+2 - self.check_vectorized(2, 2) + self.check_vectorized(1, 1) def define_float_mul_array(): return """ @@ -335,7 +344,7 @@ def test_int32_mul_array(self): result = self.run("int32_mul_array") assert int(result) == 7*7+8*8+11*11+12*12 - self.check_vectorized(2, 2) + self.check_vectorized(1, 1) def define_float32_mul_array(): return """ @@ -363,7 +372,7 @@ def test_conversion(self): result = self.run("conversion") assert result == sum(range(30)) + sum(range(30)) - self.check_vectorized(4, 2) # only sum and astype(int) succeed + self.check_vectorized(2, 2) # only sum and astype(int) succeed def define_sum(): return """ @@ -393,7 +402,7 @@ def test_sum_int(self): result = self.run("sum_int") assert result == sum(range(65)) - self.check_vectorized(2, 2) # 1 sum, 1 for type conversion + self.check_vectorized(1, 1) def define_sum_multi(): return """ @@ -501,7 +510,7 @@ retval = self.interp.eval_graph(self.graph, [i]) # check that we got only one loop assert len(get_stats().loops) == 1 - self.check_vectorized(3, 1) + self.check_vectorized(2, 1) def define_prod(): return """ diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py --- a/rpython/jit/backend/llgraph/runner.py +++ b/rpython/jit/backend/llgraph/runner.py @@ -839,7 +839,22 @@ return [int(x) ^ int(y) for x,y in zip(vx,vy)] def bh_vec_cast_float_to_singlefloat(self, vx, count): - return vx + from rpython.rlib.rarithmetic import r_singlefloat + return [longlong.singlefloat2int(r_singlefloat(longlong.getrealfloat(v))) + for v in vx] + + def bh_vec_cast_singlefloat_to_float(self, vx, count): + return [longlong.getfloatstorage(float(longlong.int2singlefloat(v))) + for v in vx] + + a = float(a) + return longlong.getfloatstorage(a) + + def bh_vec_cast_float_to_int(self, vx, count): + return [int(x) for x in vx] + + def bh_vec_cast_int_to_float(self, vx, count): + return [float(x) for x in vx] def bh_vec_f(self, count): return [0.0] * count @@ -847,7 +862,8 @@ def bh_vec_i(self, count): return [0] * count - def _bh_vec_pack(self, tv, sv, index, count, _): + def _bh_vec_pack(self, tv, sv, index, count, newcount): + while len(tv) < newcount: tv.append(None) if not isinstance(sv, list): tv[index] = sv return tv @@ -858,7 +874,7 @@ bh_vec_pack_f = _bh_vec_pack bh_vec_pack_i = _bh_vec_pack - def _bh_vec_unpack(self, vx, index, count): + def _bh_vec_unpack(self, vx, index, count, newcount): return vx[index:index+count] bh_vec_unpack_f = _bh_vec_unpack @@ -966,14 +982,15 @@ return hash(self) def setenv(self, box, arg): - if box.is_vector(): + if box.is_vector() and box.count > 1: if box.datatype == INT: - _type = lltype.Signed for i,a in enumerate(arg): if isinstance(a, bool): arg[i] = int(a) + assert all([lltype.typeOf(a) == lltype.Signed for a in arg]) elif box.datatype == FLOAT: - _type = longlong.FLOATSTORAGE + assert all([lltype.typeOf(a) == longlong.FLOATSTORAGE or \ + lltype.typeOf(a) == lltype.Signed for a in arg]) else: raise AssertionError(box) elif box.type == INT: @@ -1429,10 +1446,20 @@ else: new_args = args if opname.startswith('vec_'): + # pre vector op count = self.current_op.count - assert count > 1 + assert count >= 1 new_args = new_args + (count,) - return getattr(self.cpu, 'bh_' + opname)(*new_args) + result = getattr(self.cpu, 'bh_' + opname)(*new_args) + if isinstance(result, list): + # post vector op + count = self.current_op.count + if len(result) > count: + assert count > 0 + result = result[:count] + if count == 1: + result = result[0] + return result execute.func_name = 'execute_' + opname return execute diff --git a/rpython/jit/metainterp/optimizeopt/test/test_dependency.py b/rpython/jit/metainterp/optimizeopt/test/test_dependency.py --- a/rpython/jit/metainterp/optimizeopt/test/test_dependency.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_dependency.py @@ -12,6 +12,7 @@ from rpython.rtyper.lltypesystem import rffi from rpython.rtyper.lltypesystem import lltype from rpython.conftest import option +from rpython.jit.metainterp.compile import invent_fail_descr_for_op class FakeDependencyGraph(DependencyGraph): """ A dependency graph that is able to emit every instruction @@ -45,6 +46,9 @@ def parse_loop(self, ops, add_label=True): loop = self.parse(ops, postprocess=self.postprocess) loop.operations = filter(lambda op: op.getopnum() != rop.DEBUG_MERGE_POINT, loop.operations) + #for op in loop.operations: + # if op.is_guard() and op.getdescr() is None: + # op.setdescr(invent_fail_descr_for_op(op.opnum, None)) token = JitCellToken() if add_label: label = ResOperation(rop.LABEL, loop.inputargs, descr=TargetToken(token)) diff --git a/rpython/jit/metainterp/optimizeopt/vector.py b/rpython/jit/metainterp/optimizeopt/vector.py --- a/rpython/jit/metainterp/optimizeopt/vector.py +++ b/rpython/jit/metainterp/optimizeopt/vector.py @@ -555,7 +555,6 @@ self.mark_guard(guard_node, loop) for node in zero_deps.keys(): assert not node.is_imaginary() - print "edge to", node earlyexit.edge_to(node) if one_valid: return graph 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 @@ -116,11 +116,6 @@ _mixin_ = True def inittype(self): - if self.returns_void(): - self.bytesize = 0 - self.datatype = 'v' - return - if self.is_primitive_array_access(): from rpython.jit.backend.llsupport.descr import ArrayDescr descr = self.getdescr() @@ -149,31 +144,24 @@ self.setdatatype(tt, self.cast_to_bytesize(), tt == 'i') else: # pass through the type of the first input argument - if self.numargs() == 0: - if self.type == 'i': - self.setdatatype('i', INT_WORD, True) - elif self.type == 'f': - self.setdatatype('f', FLOAT_WORD, False) - return - i = 0 - arg = self.getarg(i) - while arg.is_constant() and i+1 < self.numargs(): - i += 1 + type = self.type + signed = type == 'i' + bytesize = -1 + if self.numargs() > 0: + i = 0 arg = self.getarg(i) - if arg.is_constant() or arg.datatype == '\x00': - if arg.type == 'i': - self.setdatatype('i', INT_WORD, True) - elif arg.type == 'f': - self.setdatatype('f', FLOAT_WORD, False) - else: - assert arg.type == 'r' - self.setdatatype('r', INT_WORD, False) - return - self.setdatatype(arg.datatype, arg.bytesize, arg.signed) + while arg.is_constant() and i+1 < self.numargs(): + i += 1 + arg = self.getarg(i) + if arg.datatype != '\x00' and \ + arg.bytesize != -1: + type = arg.datatype + signed = arg.signed + bytesize = arg.bytesize if self.returns_bool_result(): - self.datatype = 'i' + type = 'i' + self.setdatatype(type, bytesize, signed) assert self.datatype != '\x00' - #assert self.bytesize > 0 def setdatatype(self, data_type, bytesize, signed): self.datatype = data_type @@ -182,6 +170,8 @@ bytesize = INT_WORD elif data_type == 'f': bytesize = FLOAT_WORD + elif data_type == 'v': + bytesize = 0 self.bytesize = bytesize self.signed = signed @@ -1190,10 +1180,10 @@ 'VEC_CAST_FLOAT_TO_INT': ('f', 8, 'i', 4, 2), 'CAST_INT_TO_FLOAT': ('i', 4, 'f', 8, 2), 'VEC_CAST_INT_TO_FLOAT': ('i', 4, 'f', 8, 2), - 'CAST_FLOAT_TO_SINGLEFLOAT': ('f', 8, 'f', 4, 2), - 'VEC_CAST_FLOAT_TO_SINGLEFLOAT': ('f', 8, 'f', 4, 2), - 'CAST_SINGLEFLOAT_TO_FLOAT': ('f', 4, 'f', 8, 2), - 'VEC_CAST_SINGLEFLOAT_TO_FLOAT': ('f', 4, 'f', 8, 2), + 'CAST_FLOAT_TO_SINGLEFLOAT': ('f', 8, 'i', 4, 2), + 'VEC_CAST_FLOAT_TO_SINGLEFLOAT': ('f', 8, 'i', 4, 2), + 'CAST_SINGLEFLOAT_TO_FLOAT': ('i', 4, 'f', 8, 2), + 'VEC_CAST_SINGLEFLOAT_TO_FLOAT': ('i', 4, 'f', 8, 2), 'INT_SIGNEXT': ('i', 0, 'i', 0, 0), 'VEC_INT_SIGNEXT': ('i', 0, 'i', 0, 0), } diff --git a/rpython/jit/metainterp/test/test_resoperation.py b/rpython/jit/metainterp/test/test_resoperation.py --- a/rpython/jit/metainterp/test/test_resoperation.py +++ b/rpython/jit/metainterp/test/test_resoperation.py @@ -3,6 +3,8 @@ from rpython.jit.metainterp import resoperation as rop from rpython.jit.metainterp.history import AbstractDescr, AbstractFailDescr from rpython.jit.metainterp.history import ConstInt +from rpython.jit.backend.llsupport.symbolic import (WORD as INT_WORD, + SIZEOF_FLOAT as FLOAT_WORD) def test_arity_mixins(): cases = [ @@ -91,3 +93,13 @@ op = rop.ResOperation(rop.rop.CAST_FLOAT_TO_INT, ['a'], 'c') assert op.casts_box() assert isinstance(op, rop.CastResOp) + +def test_types(): + op = rop.ResOperation(rop.rop.INT_ADD, [ConstInt(0),ConstInt(1)]) + assert op.type == 'i' + assert op.datatype == 'i' + assert op.bytesize == INT_WORD + op = rop.ResOperation(rop.rop.VEC_CAST_FLOAT_TO_SINGLEFLOAT, [op]) + assert op.type == 'i' + assert op.datatype == 'i' + assert op.bytesize == 4 diff --git a/rpython/jit/metainterp/test/test_resume.py b/rpython/jit/metainterp/test/test_resume.py --- a/rpython/jit/metainterp/test/test_resume.py +++ b/rpython/jit/metainterp/test/test_resume.py @@ -1417,7 +1417,8 @@ assert not storage.rd_pendingfields # class FieldDescr(AbstractDescr): - pass + def is_array_of_primitives(self): + return False field_a = FieldDescr() storage = Storage() modifier = ResumeDataVirtualAdder(None, storage, storage, None) 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 @@ -177,7 +177,6 @@ def reset_jit(): """Helper for some tests (see micronumpy/test/test_zjit.py)""" - from rpython.jit.metainterp import counter reset_stats() pyjitpl._warmrunnerdesc.memory_manager.alive_loops.clear() pyjitpl._warmrunnerdesc.jitcounter._clear_all() _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit