From 7df235aefbcae9dd38be8139533cd02cffdcf228 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Wed, 28 Oct 2020 06:41:57 -0700 Subject: [PATCH] emit_x64_vector: GNFI implementation of EmitVectorLogicalShiftLeft8 Same principle as EmitVectorLogicalShiftRight8. An 8x8 galois identity matrix is bit-shfited to allow for arbitrary 8-bit-lane shifts. --- src/backend/x64/emit_x64_vector.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/backend/x64/emit_x64_vector.cpp b/src/backend/x64/emit_x64_vector.cpp index 0cfc3e0c..9ca8f0d2 100644 --- a/src/backend/x64/emit_x64_vector.cpp +++ b/src/backend/x64/emit_x64_vector.cpp @@ -1460,11 +1460,17 @@ void EmitX64::EmitVectorLogicalShiftLeft8(EmitContext& ctx, IR::Inst* inst) { if (shift_amount == 1) { code.paddb(result, result); } else if (shift_amount > 0) { - const u64 replicand = (0xFFULL << shift_amount) & 0xFF; - const u64 mask = Common::Replicate(replicand, Common::BitSize()); + if (code.HasAVX512_Icelake()) { + // Galois 8x8 identity matrix, bit-shifted by the shift-amount + const u64 shift_matrix = 0x0102040810204080 >> (shift_amount * 8); + code.vgf2p8affineqb(result, result, code.MConst(xword_b, shift_matrix), 0); + } else { + const u64 replicand = (0xFFULL << shift_amount) & 0xFF; + const u64 mask = Common::Replicate(replicand, Common::BitSize()); - code.psllw(result, shift_amount); - code.pand(result, code.MConst(xword, mask, mask)); + code.psllw(result, shift_amount); + code.pand(result, code.MConst(xword, mask, mask)); + } } ctx.reg_alloc.DefineValue(inst, result);