From 35026a6ce3ec44e541cf7063b34cd8b55583d289 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 13 Jul 2018 20:20:17 -0400 Subject: [PATCH] emit_x64_vector: Vectorize fallback path for EmitVectorMaxU32() --- src/backend_x64/emit_x64_vector.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/backend_x64/emit_x64_vector.cpp b/src/backend_x64/emit_x64_vector.cpp index 52cfd95c..f2c56455 100644 --- a/src/backend_x64/emit_x64_vector.cpp +++ b/src/backend_x64/emit_x64_vector.cpp @@ -1270,9 +1270,25 @@ void EmitX64::EmitVectorMaxU32(EmitContext& ctx, IR::Inst* inst) { return; } - EmitTwoArgumentFallback(code, ctx, inst, [](std::array& result, const std::array& a, const std::array& b){ - std::transform(a.begin(), a.end(), b.begin(), result.begin(), [](auto x, auto y) { return std::max(x, y); }); - }); + auto args = ctx.reg_alloc.GetArgumentInfo(inst); + const Xbyak::Xmm a = ctx.reg_alloc.UseScratchXmm(args[0]); + const Xbyak::Xmm b = ctx.reg_alloc.UseXmm(args[1]); + + const Xbyak::Xmm tmp = ctx.reg_alloc.ScratchXmm(); + code.movdqa(tmp, code.MConst(xword, 0x8000000080000000, 0x8000000080000000)); + + const Xbyak::Xmm tmp_b = ctx.reg_alloc.ScratchXmm(); + code.movdqa(tmp_b, b); + + code.pxor(tmp_b, tmp); + code.pxor(tmp, a); + + code.pcmpgtd(tmp, tmp_b); + code.pand(a, tmp); + code.pandn(tmp, b); + code.por(a, tmp); + + ctx.reg_alloc.DefineValue(inst, a); } void EmitX64::EmitVectorMaxU64(EmitContext& ctx, IR::Inst* inst) {