emit_x64_data_processing: Reduce codesize of ArithmeticShiftRight32 for carry case

This commit is contained in:
MerryMage 2021-04-26 21:57:08 +01:00
parent a2a687f208
commit f77b98de36

View file

@ -626,32 +626,18 @@ void EmitX64::EmitArithmeticShiftRight32(EmitContext& ctx, IR::Inst* inst) {
ctx.EraseInstruction(carry_inst); ctx.EraseInstruction(carry_inst);
ctx.reg_alloc.DefineValue(inst, result); ctx.reg_alloc.DefineValue(inst, result);
} else { } else {
ctx.reg_alloc.Use(shift_arg, HostLoc::RCX); ctx.reg_alloc.UseScratch(shift_arg, HostLoc::RCX);
const Xbyak::Reg32 result = ctx.reg_alloc.UseScratchGpr(operand_arg).cvt32(); const Xbyak::Reg32 operand = ctx.reg_alloc.UseGpr(operand_arg).cvt32();
const Xbyak::Reg8 carry = ctx.reg_alloc.UseScratchGpr(carry_arg).cvt8(); const Xbyak::Reg32 result = ctx.reg_alloc.ScratchGpr().cvt32();
const Xbyak::Reg32 carry = ctx.reg_alloc.UseScratchGpr(carry_arg).cvt32();
// TODO: Optimize this. code.mov(result, 63);
code.cmp(code.cl, 63);
code.inLocalLabel(); code.cmovnb(code.ecx, result);
code.movsxd(result.cvt64(), operand);
code.cmp(code.cl, u32(31)); code.bt(carry.cvt32(), 0);
code.ja(".Rs_gt31"); code.sar(result.cvt64(), code.cl);
// if (Rs & 0xFF == 0) goto end; code.setc(carry.cvt8());
code.test(code.cl, code.cl);
code.jz(".end");
// if (Rs & 0xFF <= 31) {
code.sar(result, code.cl);
code.setc(carry);
code.jmp(".end");
// } else if (Rs & 0xFF > 31) {
code.L(".Rs_gt31");
code.sar(result, 31); // 31 produces the same results as anything above 31
code.bt(result, 31);
code.setc(carry);
// }
code.L(".end");
code.outLocalLabel();
ctx.reg_alloc.DefineValue(carry_inst, carry); ctx.reg_alloc.DefineValue(carry_inst, carry);
ctx.EraseInstruction(carry_inst); ctx.EraseInstruction(carry_inst);