From 5267dbb8cf5cba71b6ac0dbf01ff351a24813ccc Mon Sep 17 00:00:00 2001 From: MerryMage Date: Fri, 12 Apr 2019 16:38:55 +0100 Subject: [PATCH] emit_x64_saturation: Prefer changeBit to setBit --- src/backend/x64/emit_x64_saturation.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/backend/x64/emit_x64_saturation.cpp b/src/backend/x64/emit_x64_saturation.cpp index c1cc141a..e33d8ab0 100644 --- a/src/backend/x64/emit_x64_saturation.cpp +++ b/src/backend/x64/emit_x64_saturation.cpp @@ -34,13 +34,9 @@ void EmitSignedSaturatedOp(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst) auto args = ctx.reg_alloc.GetArgumentInfo(inst); - Xbyak::Reg result = ctx.reg_alloc.UseScratchGpr(args[0]); - Xbyak::Reg addend = ctx.reg_alloc.UseGpr(args[1]); - Xbyak::Reg overflow = ctx.reg_alloc.ScratchGpr(); - - result.setBit(size); - addend.setBit(size); - overflow.setBit(size); + Xbyak::Reg result = ctx.reg_alloc.UseScratchGpr(args[0]).changeBit(size); + Xbyak::Reg addend = ctx.reg_alloc.UseGpr(args[1]).changeBit(size); + Xbyak::Reg overflow = ctx.reg_alloc.ScratchGpr().changeBit(size); constexpr u64 int_max = static_cast(std::numeric_limits>::max()); if constexpr (size < 64) { @@ -61,7 +57,7 @@ void EmitSignedSaturatedOp(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst) code.sub(result, addend); } - if constexpr (size < 64) { + if constexpr (size == 8) { code.cmovo(result.cvt32(), overflow.cvt32()); } else { code.cmovo(result, overflow); @@ -83,23 +79,18 @@ void EmitUnsignedSaturatedOp(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst auto args = ctx.reg_alloc.GetArgumentInfo(inst); - Xbyak::Reg op_result = ctx.reg_alloc.UseScratchGpr(args[0]); - Xbyak::Reg addend = ctx.reg_alloc.UseScratchGpr(args[1]); + Xbyak::Reg op_result = ctx.reg_alloc.UseScratchGpr(args[0]).changeBit(size); + Xbyak::Reg addend = ctx.reg_alloc.UseScratchGpr(args[1]).changeBit(size); - op_result.setBit(size); - addend.setBit(size); + constexpr u64 boundary = op == Op::Add ? std::numeric_limits>::max() : 0; if constexpr (op == Op::Add) { code.add(op_result, addend); } else { code.sub(op_result, addend); } - - constexpr u64 boundary = op == Op::Add ? std::numeric_limits>::max() - : 0; code.mov(addend, boundary); - - if constexpr (size < 64) { + if constexpr (size == 8) { code.cmovae(addend.cvt32(), op_result.cvt32()); } else { code.cmovae(addend, op_result);