From dc37fe6e2828f94c8e2daafacd955effd918b6e7 Mon Sep 17 00:00:00 2001 From: Merry Date: Sat, 27 Mar 2021 21:31:22 +0000 Subject: [PATCH] emit_x64_vector: Bugfix for ArithmeticShiftRightByte: shift_amount can be >= 8 --- src/backend/x64/emit_x64_vector.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend/x64/emit_x64_vector.cpp b/src/backend/x64/emit_x64_vector.cpp index 07f7f153..7e7f7160 100644 --- a/src/backend/x64/emit_x64_vector.cpp +++ b/src/backend/x64/emit_x64_vector.cpp @@ -440,13 +440,13 @@ void EmitX64::EmitVectorAnd(EmitContext& ctx, IR::Inst* inst) { static void ArithmeticShiftRightByte(EmitContext& ctx, BlockOfCode& code, const Xbyak::Xmm& result, u8 shift_amount) { if (code.HasAVX512_Icelake()) { - // Do a logical shift right upon the 8x8 bit-matrix, but shift in - // `0x80` bytes into the matrix to repeat the most significant bit. - const u64 zero_extend = ~(0xFFFFFFFFFFFFFFFF << (shift_amount * 8)) & 0x8080808080808080; - const u64 shift_matrix = (0x0102040810204080 >> (shift_amount * 8)) | zero_extend; + const u64 shift_matrix = shift_amount < 8 + ? (0x0102040810204080 << (shift_amount * 8)) | (0x8080808080808080 >> (64 - shift_amount * 8)) + : 0x8080808080808080; code.vgf2p8affineqb(result, result, code.MConst(xword_b, shift_matrix), 0); return; } + const Xbyak::Xmm tmp = ctx.reg_alloc.ScratchXmm(); code.punpckhbw(tmp, result);