From bbc066a266d75b87f0b0260e9437dc197ab2381f Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 23 Sep 2018 10:01:59 +0100 Subject: [PATCH] emit_x64_vector: AVX2 implementation of EmitVectorLogicalVShiftU32() --- src/backend/x64/emit_x64_vector.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/backend/x64/emit_x64_vector.cpp b/src/backend/x64/emit_x64_vector.cpp index 92629510..539d6f5d 100644 --- a/src/backend/x64/emit_x64_vector.cpp +++ b/src/backend/x64/emit_x64_vector.cpp @@ -1401,6 +1401,28 @@ void EmitX64::EmitVectorLogicalVShiftU16(EmitContext& ctx, IR::Inst* inst) { } void EmitX64::EmitVectorLogicalVShiftU32(EmitContext& ctx, IR::Inst* inst) { + if (code.DoesCpuSupport(Xbyak::util::Cpu::tAVX2)) { + auto args = ctx.reg_alloc.GetArgumentInfo(inst); + + const Xbyak::Xmm result = ctx.reg_alloc.UseScratchXmm(args[0]); + const Xbyak::Xmm left_shift = ctx.reg_alloc.UseScratchXmm(args[1]); + const Xbyak::Xmm right_shift = ctx.reg_alloc.ScratchXmm(); + const Xbyak::Xmm tmp = ctx.reg_alloc.ScratchXmm(); + + code.vmovdqa(tmp, code.MConst(xword, 0x000000FF000000FF, 0x000000FF000000FF)); + code.vpxor(right_shift, right_shift, right_shift); + code.vpsubd(right_shift, right_shift, left_shift); + code.vpand(left_shift, left_shift, tmp); + code.vpand(right_shift, right_shift, tmp); + + code.vpsllvd(tmp, result, left_shift); + code.vpsrlvd(result, result, right_shift); + code.vpor(result, result, tmp); + + ctx.reg_alloc.DefineValue(inst, result); + return; + } + EmitTwoArgumentFallback(code, ctx, inst, [](VectorArray& result, const VectorArray& a, const VectorArray& b) { std::transform(a.begin(), a.end(), b.begin(), result.begin(), LogicalVShift); });