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:
parent
2952b46b16
commit
135107279d
1 changed files with 7 additions and 10 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue