From 21df1fb5394fab4311263219d123ee8e208d3e9b Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 19 Aug 2018 21:33:33 +0100 Subject: [PATCH] emit_x64_vector: Don't load zero constant from memory in EmitVectorTableLookup --- src/backend_x64/emit_x64_vector.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/backend_x64/emit_x64_vector.cpp b/src/backend_x64/emit_x64_vector.cpp index 640a1b50..d8c9c3d4 100644 --- a/src/backend_x64/emit_x64_vector.cpp +++ b/src/backend_x64/emit_x64_vector.cpp @@ -2772,13 +2772,16 @@ void EmitX64::EmitVectorTableLookup(EmitContext& ctx, IR::Inst* inst) { for (size_t i = 0; i < table_size; ++i) { const Xbyak::Xmm xmm_table = ctx.reg_alloc.UseScratchXmm(table[i]); - const u64 max_index = Common::Replicate(i * 16, 8); + const u64 table_index = Common::Replicate(i * 16, 8); - if (code.DoesCpuSupport(Xbyak::util::Cpu::tAVX)) { - code.vpcmpeqb(xmm0, masked, code.MConst(xword, max_index, max_index)); + if (table_index == 0) { + code.pxor(xmm0, xmm0); + code.pcmpeqb(xmm0, masked); + } else if (code.DoesCpuSupport(Xbyak::util::Cpu::tAVX)) { + code.vpcmpeqb(xmm0, masked, code.MConst(xword, table_index, table_index)); } else { - code.movaps(xmm0, masked); - code.pcmpeqb(xmm0, code.MConst(xword, max_index, max_index)); + code.movaps(xmm0, code.MConst(xword, table_index, table_index)); + code.pcmpeqb(xmm0, masked); } code.pshufb(xmm_table, indicies); code.pblendvb(result, xmm_table);