Skip to content

Commit d3695ab

Browse files
committed
ZJIT: Emit MulHighBits before Mul to avoid input clobbering
1 parent e7b5202 commit d3695ab

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

zjit/src/codegen.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,11 +1982,13 @@ fn gen_fixnum_mult(jit: &mut JITState, asm: &mut Assembler, left: lir::Opnd, rig
19821982
// x * y is translated to (x >> 1) * (y - 1) + 1
19831983
let left_untag = asm.rshift(left, Opnd::UImm(1));
19841984
let right_untag = asm.sub(right, Opnd::UImm(1));
1985+
// Emit MulHighBits before Mul: smulh needs the original inputs,
1986+
// but mul may clobber a shared input register.
1987+
let high = asm.mul_high_bits(left_untag, right_untag);
19851988
let out_val = asm.mul(left_untag, right_untag);
19861989

1987-
// Test for overflow: on ARM64, compare smulh (high bits) with sign-extended
1990+
// Test for overflow: on ARM64, compare high bits with sign-extended
19881991
// low bits. On x86, mul_high_bits is a no-op and jo_mul just reads OF.
1989-
let high = asm.mul_high_bits(left_untag, right_untag);
19901992
asm.jo_mul(high, out_val, side_exit(jit, state, FixnumMultOverflow));
19911993
asm.add(out_val, Opnd::UImm(1))
19921994
}

0 commit comments

Comments
 (0)