emit_x64_vector: Simplify EmitVectorLogicalShiftRight8()

We can generate the mask and AND it against the result of a halfword
shift instead of looping.
This commit is contained in:
Lioncash 2018-08-31 09:07:05 -04:00 committed by MerryMage
parent 2952b46b16
commit 135107279d

View file

@ -1102,18 +1102,15 @@ void EmitX64::EmitVectorLogicalShiftLeft64(EmitContext& ctx, IR::Inst* inst) {
void EmitX64::EmitVectorLogicalShiftRight8(EmitContext& ctx, IR::Inst* inst) { void EmitX64::EmitVectorLogicalShiftRight8(EmitContext& ctx, IR::Inst* inst) {
auto args = ctx.reg_alloc.GetArgumentInfo(inst); auto args = ctx.reg_alloc.GetArgumentInfo(inst);
Xbyak::Xmm result = ctx.reg_alloc.UseScratchXmm(args[0]); const Xbyak::Xmm result = ctx.reg_alloc.UseScratchXmm(args[0]);
Xbyak::Xmm zeros = ctx.reg_alloc.ScratchXmm();
Xbyak::Xmm mask = ctx.reg_alloc.ScratchXmm();
const u8 shift_amount = args[1].GetImmediateU8(); const u8 shift_amount = args[1].GetImmediateU8();
// TODO: Optimize if (shift_amount > 0) {
code.pcmpeqb(mask, mask); // mask = 0xFF const u64 replicand = 0xFEULL >> shift_amount;
code.paddb(mask, mask); // mask = 0xFE const u64 mask = Common::Replicate(replicand, Common::BitSize<u8>());
code.pxor(zeros, zeros);
for (size_t i = 0; i < shift_amount; ++i) { code.psrlw(result, shift_amount);
code.pand(result, mask); code.pand(result, code.MConst(xword, mask, mask));
code.pavgb(result, zeros);
} }
ctx.reg_alloc.DefineValue(inst, result); ctx.reg_alloc.DefineValue(inst, result);