Author: Armin Rigo <ar...@tunes.org> Branch: ffi-backend Changeset: r56552:6b362edf145b Date: 2012-08-03 12:25 +0200 http://bitbucket.org/pypy/pypy/changeset/6b362edf145b/
Log: hg merge default diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py --- a/pypy/jit/backend/x86/assembler.py +++ b/pypy/jit/backend/x86/assembler.py @@ -998,6 +998,24 @@ getattr(self.mc, asmop)(arglocs[0], arglocs[1]) return genop_binary + def _binaryop_or_lea(asmop, is_add): + def genop_binary_or_lea(self, op, arglocs, result_loc): + # use a regular ADD or SUB if result_loc is arglocs[0], + # and a LEA only if different. + if result_loc is arglocs[0]: + getattr(self.mc, asmop)(arglocs[0], arglocs[1]) + else: + loc = arglocs[0] + argloc = arglocs[1] + assert isinstance(loc, RegLoc) + assert isinstance(argloc, ImmedLoc) + assert isinstance(result_loc, RegLoc) + delta = argloc.value + if not is_add: # subtraction + delta = -delta + self.mc.LEA_rm(result_loc.value, (loc.value, delta)) + return genop_binary_or_lea + def _cmpop(cond, rev_cond): def genop_cmp(self, op, arglocs, result_loc): rl = result_loc.lowest8bits() @@ -1224,8 +1242,8 @@ genop_int_neg = _unaryop("NEG") genop_int_invert = _unaryop("NOT") - genop_int_add = _binaryop("ADD", True) - genop_int_sub = _binaryop("SUB") + genop_int_add = _binaryop_or_lea("ADD", True) + genop_int_sub = _binaryop_or_lea("SUB", False) genop_int_mul = _binaryop("IMUL", True) genop_int_and = _binaryop("AND", True) genop_int_or = _binaryop("OR", True) @@ -1721,15 +1739,15 @@ guard_op.getopname()) def genop_guard_int_add_ovf(self, op, guard_op, guard_token, arglocs, result_loc): - self.genop_int_add(op, arglocs, result_loc) + self.mc.ADD(arglocs[0], arglocs[1]) return self._gen_guard_overflow(guard_op, guard_token) def genop_guard_int_sub_ovf(self, op, guard_op, guard_token, arglocs, result_loc): - self.genop_int_sub(op, arglocs, result_loc) + self.mc.SUB(arglocs[0], arglocs[1]) return self._gen_guard_overflow(guard_op, guard_token) def genop_guard_int_mul_ovf(self, op, guard_op, guard_token, arglocs, result_loc): - self.genop_int_mul(op, arglocs, result_loc) + self.mc.IMUL(arglocs[0], arglocs[1]) return self._gen_guard_overflow(guard_op, guard_token) def genop_guard_guard_false(self, ign_1, guard_op, guard_token, locs, ign_2): diff --git a/pypy/jit/backend/x86/regalloc.py b/pypy/jit/backend/x86/regalloc.py --- a/pypy/jit/backend/x86/regalloc.py +++ b/pypy/jit/backend/x86/regalloc.py @@ -23,6 +23,7 @@ TempBox from pypy.jit.backend.x86.arch import WORD, FRAME_FIXED_SIZE from pypy.jit.backend.x86.arch import IS_X86_32, IS_X86_64, MY_COPY_OF_REGS +from pypy.jit.backend.x86 import rx86 from pypy.rlib.rarithmetic import r_longlong class X86RegisterManager(RegisterManager): @@ -610,9 +611,31 @@ loc, argloc = self._consider_binop_part(op) self.Perform(op, [loc, argloc], loc) - consider_int_add = _consider_binop + def _consider_lea(self, op, loc): + argloc = self.loc(op.getarg(1)) + self.rm.possibly_free_var(op.getarg(0)) + resloc = self.force_allocate_reg(op.result) + self.Perform(op, [loc, argloc], resloc) + + def consider_int_add(self, op): + loc = self.loc(op.getarg(0)) + y = op.getarg(1) + if (isinstance(loc, RegLoc) and + isinstance(y, ConstInt) and rx86.fits_in_32bits(y.value)): + self._consider_lea(op, loc) + else: + self._consider_binop(op) + + def consider_int_sub(self, op): + loc = self.loc(op.getarg(0)) + y = op.getarg(1) + if (isinstance(loc, RegLoc) and + isinstance(y, ConstInt) and rx86.fits_in_32bits(-y.value)): + self._consider_lea(op, loc) + else: + self._consider_binop(op) + consider_int_mul = _consider_binop - consider_int_sub = _consider_binop consider_int_and = _consider_binop consider_int_or = _consider_binop consider_int_xor = _consider_binop diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -3797,6 +3797,7 @@ assert res == 3 def test_float_bytes(self): + from pypy.rlib.rfloat import isnan def f(n): ll = float2longlong(n) return longlong2float(ll) @@ -3804,7 +3805,7 @@ for x in [2.5, float("nan"), -2.5, float("inf")]: # There are tests elsewhere to verify the correctness of this. res = self.interp_operations(f, [x]) - assert res == x or math.isnan(x) and math.isnan(res) + assert res == x or isnan(x) and isnan(res) class TestLLtype(BaseLLtypeTests, LLJitMixin): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit