diff --git a/src/backend/x64/emit_x64_data_processing.cpp b/src/backend/x64/emit_x64_data_processing.cpp index 0f9c67c9..4af9c645 100644 --- a/src/backend/x64/emit_x64_data_processing.cpp +++ b/src/backend/x64/emit_x64_data_processing.cpp @@ -492,38 +492,18 @@ void EmitX64::EmitLogicalShiftRight32(EmitContext& ctx, IR::Inst* inst) { ctx.EraseInstruction(carry_inst); ctx.reg_alloc.DefineValue(inst, result); } else { - ctx.reg_alloc.Use(shift_arg, HostLoc::RCX); - const Xbyak::Reg32 result = ctx.reg_alloc.UseScratchGpr(operand_arg).cvt32(); + ctx.reg_alloc.UseScratch(shift_arg, HostLoc::RCX); + const Xbyak::Reg32 operand = ctx.reg_alloc.UseGpr(operand_arg).cvt32(); + const Xbyak::Reg32 result = ctx.reg_alloc.ScratchGpr().cvt32(); const Xbyak::Reg32 carry = ctx.reg_alloc.UseScratchGpr(carry_arg).cvt32(); - // TODO: Optimize this. - - code.inLocalLabel(); - - code.cmp(code.cl, 32); - code.ja(".Rs_gt32"); - code.je(".Rs_eq32"); - // if (Rs & 0xFF == 0) goto end; - code.test(code.cl, code.cl); - code.jz(".end"); - // if (Rs & 0xFF < 32) { - code.shr(result, code.cl); + code.mov(result, 63); + code.cmp(code.cl, 63); + code.cmovnb(code.ecx, result); + code.mov(result, operand); + code.bt(carry.cvt32(), 0); + code.shr(result.cvt64(), code.cl); code.setc(carry.cvt8()); - code.jmp(".end"); - // } else if (Rs & 0xFF > 32) { - code.L(".Rs_gt32"); - code.xor_(result, result); - code.xor_(carry, carry); - code.jmp(".end"); - // } else if (Rs & 0xFF == 32) { - code.L(".Rs_eq32"); - code.bt(result, 31); - code.setc(carry.cvt8()); - code.xor_(result, result); - // } - code.L(".end"); - - code.outLocalLabel(); ctx.reg_alloc.DefineValue(carry_inst, carry); ctx.EraseInstruction(carry_inst);