From 5cc646ffed2798a85b6e206a066b780227109a6f Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Wed, 28 Oct 2020 06:32:11 -0700 Subject: [PATCH] emit_x64_vector: GNFI implementation of EmitVectorLogicalShiftRight8 Bitshifts of the GFNI identity matrix generates a new matrix that applies lane-wise bitshifts as well. This allows for a fast single-instruction implementation of a byte-lane bitshift. --- 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 6b288b98..0cfc3e0c 100644 --- a/src/backend/x64/emit_x64_vector.cpp +++ b/src/backend/x64/emit_x64_vector.cpp @@ -1510,11 +1510,17 @@ void EmitX64::EmitVectorLogicalShiftRight8(EmitContext& ctx, IR::Inst* inst) { const u8 shift_amount = args[1].GetImmediateU8(); if (shift_amount > 0) { - const u64 replicand = 0xFEULL >> shift_amount; - 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 = 0xFEULL >> shift_amount; + const u64 mask = Common::Replicate(replicand, Common::BitSize()); - code.psrlw(result, shift_amount); - code.pand(result, code.MConst(xword, mask, mask)); + code.psrlw(result, shift_amount); + code.pand(result, code.MConst(xword, mask, mask)); + } } ctx.reg_alloc.DefineValue(inst, result);