From 2cac6ad129561b28d7194fa96b0beafd420c101c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 31 Aug 2018 11:14:51 -0400 Subject: [PATCH] emit_x64_vector: Simplify EmitVectorLogicalLeftShift8() Similar to EmitVectorLogicalRightShift8(), we can determine a mask ahead of time and just and the results of a halfword left shift. --- src/backend/x64/emit_x64_vector.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/x64/emit_x64_vector.cpp b/src/backend/x64/emit_x64_vector.cpp index 6a771069..0fece599 100644 --- a/src/backend/x64/emit_x64_vector.cpp +++ b/src/backend/x64/emit_x64_vector.cpp @@ -1055,12 +1055,17 @@ void EmitX64::EmitVectorInterleaveUpper64(EmitContext& ctx, IR::Inst* inst) { void EmitX64::EmitVectorLogicalShiftLeft8(EmitContext& ctx, IR::Inst* inst) { auto args = ctx.reg_alloc.GetArgumentInfo(inst); - Xbyak::Xmm result = ctx.reg_alloc.UseScratchXmm(args[0]); + const Xbyak::Xmm result = ctx.reg_alloc.UseScratchXmm(args[0]); const u8 shift_amount = args[1].GetImmediateU8(); - // TODO: Optimize - for (size_t i = 0; i < shift_amount; ++i) { + 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()); + + code.psllw(result, shift_amount); + code.pand(result, code.MConst(xword, mask, mask)); } ctx.reg_alloc.DefineValue(inst, result);