Author: Richard Plangger <planri...@gmail.com> Branch: s390x-backend Changeset: r80701:f2281bea8745 Date: 2015-11-16 08:56 +0100 http://bitbucket.org/pypy/pypy/changeset/f2281bea8745/
Log: guard overflow is behaving properly for int_add_ovf/int_sub_ovf diff --git a/rpython/jit/backend/zarch/conditions.py b/rpython/jit/backend/zarch/conditions.py --- a/rpython/jit/backend/zarch/conditions.py +++ b/rpython/jit/backend/zarch/conditions.py @@ -16,9 +16,11 @@ @specialize.arg(1) def negate(cond, inv_overflow=False): + if cond is OF: + return NO + if cond is NO: + return OF overflow = cond.value & 0x1 - if inv_overflow: - assert False value = (~cond.value) & 0xe return loc.imm(value | overflow) @@ -28,3 +30,5 @@ assert negate(LE).value == GT.value assert negate(GT).value == LE.value assert negate(GE).value == LT.value +assert negate(OF).value == NO.value +assert negate(NO).value == OF.value diff --git a/rpython/jit/backend/zarch/helper/assembler.py b/rpython/jit/backend/zarch/helper/assembler.py --- a/rpython/jit/backend/zarch/helper/assembler.py +++ b/rpython/jit/backend/zarch/helper/assembler.py @@ -72,27 +72,25 @@ def f(self, op, arglocs, regalloc): l0, l1 = arglocs if not l1.is_imm() or l1.is_in_pool(): - assert "shift imm must NOT reside in pool!" + assert 0, "shift imm must NOT reside in pool!" getattr(self.mc, func)(l0, l0, l1) return f -def gen_emit_rr_or_rpool(rr_func, rp_func, overflow=False): +def gen_emit_rr_or_rpool(rr_func, rp_func): """ the parameters can either be both in registers or the first is in the register, second in literal pool. """ def f(self, op, arglocs, regalloc): l0, l1 = arglocs - if l1.is_imm(): - assert "logical imm must reside in pool!" + if l1.is_imm() and not l1.is_in_pool(): + assert 0, "logical imm must reside in pool!" elif l1.is_in_pool(): getattr(self.mc, rp_func)(l0, l1) else: getattr(self.mc, rr_func)(l0, l1) - if overflow: - self.guard_success_cc = c.OF return f -def gen_emit_imm_pool_rr(imm_func, pool_func, rr_func, overflow=False): +def gen_emit_imm_pool_rr(imm_func, pool_func, rr_func): def emit(self, op, arglocs, regalloc): l0, l1 = arglocs if l1.is_in_pool(): @@ -101,8 +99,6 @@ getattr(self.mc, imm_func)(l0, l1) else: getattr(self.mc, rr_func)(l0, l1) - if overflow: - self.guard_success_cc = c.OF return emit def gen_emit_pool_or_rr_evenodd(pool_func, rr_func): diff --git a/rpython/jit/backend/zarch/opassembler.py b/rpython/jit/backend/zarch/opassembler.py --- a/rpython/jit/backend/zarch/opassembler.py +++ b/rpython/jit/backend/zarch/opassembler.py @@ -11,9 +11,9 @@ _mixin_ = True emit_int_add = gen_emit_imm_pool_rr('AGFI','AG','AGR') - emit_int_add_ovf = gen_emit_imm_pool_rr('AGFI','AG','AGR', overflow=True) + emit_int_add_ovf = emit_int_add emit_int_sub = gen_emit_rr_or_rpool('SGR', 'SG') - emit_int_sub_ovf = gen_emit_rr_or_rpool('SGR', 'SG', overflow=True) + emit_int_sub_ovf = emit_int_sub emit_int_mul = gen_emit_imm_pool_rr('MSGFI', 'MSG', 'MSGR') emit_int_floordiv = gen_emit_pool_or_rr_evenodd('DSG','DSGR') @@ -121,11 +121,11 @@ self._emit_guard(op, arglocs) def emit_guard_overflow(self, op, arglocs, regalloc): - self.guard_success_cc = c.NO + self.guard_success_cc = c.OF self._emit_guard(op, arglocs) def emit_guard_no_overflow(self, op, arglocs, regalloc): - self.guard_success_cc = c.OF + self.guard_success_cc = c.NO self._emit_guard(op, arglocs) def emit_guard_value(self, op, arglocs, regalloc): diff --git a/rpython/jit/backend/zarch/test/test_runner.py b/rpython/jit/backend/zarch/test/test_runner.py --- a/rpython/jit/backend/zarch/test/test_runner.py +++ b/rpython/jit/backend/zarch/test/test_runner.py @@ -68,16 +68,23 @@ assert fail.identifier == 1 @py.test.mark.parametrize('value,opcode,result,guard', - [ (-2**63, 'i1 = int_add_ovf(i0, 1)', -2**63, 'guard_no_overflow'), - (-2**63+1,'i1 = int_add_ovf(i0, 1)', -2**63, 'guard_no_overflow'), - (-2**63+1,'i1 = int_add_ovf(i0, 1)', -2**63+1, 'guard_overflow'), + [ (2**63-1,'i1 = int_add_ovf(i0, 1)',1,'guard_no_overflow'), + (2**63-2,'i1 = int_add_ovf(i0, 1)',0,'guard_no_overflow'), + (2**63-2,'i1 = int_add_ovf(i0, 1)',1,'guard_overflow'), + (2**63-1,'i1 = int_add_ovf(i0, 1)',0,'guard_overflow'), + (-2**63, 'i1 = int_sub_ovf(i0, 1)',1,'guard_no_overflow'), + (-2**63+1,'i1 = int_sub_ovf(i0, 1)',0,'guard_no_overflow'), + (-2**63+1,'i1 = int_sub_ovf(i0, 1)',1,'guard_overflow'), + (-2**63, 'i1 = int_sub_ovf(i0, 1)',0,'guard_overflow'), ]) def test_int_arithmetic_overflow(self, value, opcode, result, guard): + # result == 1 means branch has been taken of the guard code = """ [i0] {opcode} {guard}() [i0] - finish(i1, descr=faildescr) + i2 = int_xor(i1,i1) + finish(i2, descr=faildescr) """.format(opcode=opcode,guard=guard) loop = parse(code, namespace={"faildescr": BasicFinalDescr(1)}) looptoken = JitCellToken() @@ -85,8 +92,10 @@ deadframe = self.cpu.execute_token(looptoken, value) fail = self.cpu.get_latest_descr(deadframe) res = self.cpu.get_int_value(deadframe, 0) - assert res == result - #assert fail.identifier == 1 + if result == 1: + assert res == value + else: + assert res == 0 def test_double_evenodd_pair(self): # TODO _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit