From a2a687f2080e443c77d69a8459890bd6ed55c4a6 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Mon, 26 Apr 2021 21:45:10 +0100 Subject: [PATCH] emit_x64_data_processing: Reduce codesize of LogicalShiftRight32 for carry case --- src/backend/x64/emit_x64_data_processing.cpp | 38 +++++--------------- 1 file changed, 9 insertions(+), 29 deletions(-) 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);