From 3bbcca8757e4161aeff25026c7241f2e67b3e7f9 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 19 Aug 2018 21:32:54 +0100 Subject: [PATCH] emit_x64_vector: Special-case is_defaults_zero && table_size == 2 in EmitVectorTableLookup --- src/backend_x64/emit_x64_vector.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/backend_x64/emit_x64_vector.cpp b/src/backend_x64/emit_x64_vector.cpp index 4391396b..640a1b50 100644 --- a/src/backend_x64/emit_x64_vector.cpp +++ b/src/backend_x64/emit_x64_vector.cpp @@ -2741,6 +2741,26 @@ void EmitX64::EmitVectorTableLookup(EmitContext& ctx, IR::Inst* inst) { return; } + if (code.DoesCpuSupport(Xbyak::util::Cpu::tSSE41) && is_defaults_zero && table_size == 2) { + const Xbyak::Xmm indicies = ctx.reg_alloc.UseScratchXmm(args[2]); + const Xbyak::Xmm xmm_table0 = ctx.reg_alloc.UseScratchXmm(table[0]); + const Xbyak::Xmm xmm_table1 = ctx.reg_alloc.UseScratchXmm(table[1]); + + if (code.DoesCpuSupport(Xbyak::util::Cpu::tAVX)) { + code.vpaddusb(xmm0, indicies, code.MConst(xword, 0x7070707070707070, 0x7070707070707070)); + } else { + code.movaps(xmm0, indicies); + code.paddusb(xmm0, code.MConst(xword, 0x7070707070707070, 0x7070707070707070)); + } + code.paddusb(indicies, code.MConst(xword, 0x6060606060606060, 0x6060606060606060)); + code.pshufb(xmm_table0, xmm0); + code.pshufb(xmm_table1, indicies); + code.pblendvb(xmm_table0, xmm_table1); + + ctx.reg_alloc.DefineValue(inst, xmm_table0); + return; + } + if (code.DoesCpuSupport(Xbyak::util::Cpu::tSSE41)) { const Xbyak::Xmm indicies = ctx.reg_alloc.UseXmm(args[2]); const Xbyak::Xmm result = ctx.reg_alloc.UseScratchXmm(args[0]);