emit_x64_saturation: Prefer changeBit to setBit

This commit is contained in:
MerryMage 2019-04-12 16:38:55 +01:00
parent 9d60d92692
commit 5267dbb8cf

View file

@ -34,13 +34,9 @@ void EmitSignedSaturatedOp(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst)
auto args = ctx.reg_alloc.GetArgumentInfo(inst); auto args = ctx.reg_alloc.GetArgumentInfo(inst);
Xbyak::Reg result = ctx.reg_alloc.UseScratchGpr(args[0]); Xbyak::Reg result = ctx.reg_alloc.UseScratchGpr(args[0]).changeBit(size);
Xbyak::Reg addend = ctx.reg_alloc.UseGpr(args[1]); Xbyak::Reg addend = ctx.reg_alloc.UseGpr(args[1]).changeBit(size);
Xbyak::Reg overflow = ctx.reg_alloc.ScratchGpr(); Xbyak::Reg overflow = ctx.reg_alloc.ScratchGpr().changeBit(size);
result.setBit(size);
addend.setBit(size);
overflow.setBit(size);
constexpr u64 int_max = static_cast<u64>(std::numeric_limits<mp::signed_integer_of_size<size>>::max()); constexpr u64 int_max = static_cast<u64>(std::numeric_limits<mp::signed_integer_of_size<size>>::max());
if constexpr (size < 64) { if constexpr (size < 64) {
@ -61,7 +57,7 @@ void EmitSignedSaturatedOp(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst)
code.sub(result, addend); code.sub(result, addend);
} }
if constexpr (size < 64) { if constexpr (size == 8) {
code.cmovo(result.cvt32(), overflow.cvt32()); code.cmovo(result.cvt32(), overflow.cvt32());
} else { } else {
code.cmovo(result, overflow); code.cmovo(result, overflow);
@ -83,23 +79,18 @@ void EmitUnsignedSaturatedOp(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst
auto args = ctx.reg_alloc.GetArgumentInfo(inst); auto args = ctx.reg_alloc.GetArgumentInfo(inst);
Xbyak::Reg op_result = ctx.reg_alloc.UseScratchGpr(args[0]); Xbyak::Reg op_result = ctx.reg_alloc.UseScratchGpr(args[0]).changeBit(size);
Xbyak::Reg addend = ctx.reg_alloc.UseScratchGpr(args[1]); Xbyak::Reg addend = ctx.reg_alloc.UseScratchGpr(args[1]).changeBit(size);
op_result.setBit(size); constexpr u64 boundary = op == Op::Add ? std::numeric_limits<mp::unsigned_integer_of_size<size>>::max() : 0;
addend.setBit(size);
if constexpr (op == Op::Add) { if constexpr (op == Op::Add) {
code.add(op_result, addend); code.add(op_result, addend);
} else { } else {
code.sub(op_result, addend); code.sub(op_result, addend);
} }
constexpr u64 boundary = op == Op::Add ? std::numeric_limits<mp::unsigned_integer_of_size<size>>::max()
: 0;
code.mov(addend, boundary); code.mov(addend, boundary);
if constexpr (size == 8) {
if constexpr (size < 64) {
code.cmovae(addend.cvt32(), op_result.cvt32()); code.cmovae(addend.cvt32(), op_result.cvt32());
} else { } else {
code.cmovae(addend, op_result); code.cmovae(addend, op_result);