From 43407c4bb46f3aa9368d79565476aa793295ebd1 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Tue, 24 Jul 2018 22:44:55 +0100 Subject: [PATCH] emit_x64_vector: Simplify VectorShuffleImpl --- src/backend_x64/emit_x64_vector.cpp | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/backend_x64/emit_x64_vector.cpp b/src/backend_x64/emit_x64_vector.cpp index 60b135bb..8de618b6 100644 --- a/src/backend_x64/emit_x64_vector.cpp +++ b/src/backend_x64/emit_x64_vector.cpp @@ -2053,40 +2053,28 @@ void EmitX64::EmitVectorRoundingHalvingAddU32(EmitContext& ctx, IR::Inst* inst) EmitVectorRoundingHalvingAddUnsigned(32, ctx, inst, code); } -enum class ShuffleType { - LowHalfwords, - HighHalfwords, - Words -}; - -static void VectorShuffleImpl(ShuffleType type, EmitContext& ctx, IR::Inst* inst, BlockOfCode& code) { +static void VectorShuffleImpl(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst, void (Xbyak::CodeGenerator::*fn)(const Xbyak::Mmx&, const Xbyak::Operand&, u8)) { auto args = ctx.reg_alloc.GetArgumentInfo(inst); - const Xbyak::Xmm operand = ctx.reg_alloc.UseScratchXmm(args[0]); + const Xbyak::Xmm operand = ctx.reg_alloc.UseXmm(args[0]); const Xbyak::Xmm result = ctx.reg_alloc.ScratchXmm(); const u8 mask = args[1].GetImmediateU8(); - if (type == ShuffleType::LowHalfwords) { - code.pshuflw(result, operand, mask); - } else if (type == ShuffleType::HighHalfwords) { - code.pshufhw(result, operand, mask); - } else { - code.pshufd(result, operand, mask); - } + (code.*fn)(result, operand, mask); ctx.reg_alloc.DefineValue(inst, result); } void EmitX64::EmitVectorShuffleHighHalfwords(EmitContext& ctx, IR::Inst* inst) { - VectorShuffleImpl(ShuffleType::HighHalfwords, ctx, inst, code); + VectorShuffleImpl(code, ctx, inst, &Xbyak::CodeGenerator::pshufhw); } void EmitX64::EmitVectorShuffleLowHalfwords(EmitContext& ctx, IR::Inst* inst) { - VectorShuffleImpl(ShuffleType::LowHalfwords, ctx, inst, code); + VectorShuffleImpl(code, ctx, inst, &Xbyak::CodeGenerator::pshuflw); } void EmitX64::EmitVectorShuffleWords(EmitContext& ctx, IR::Inst* inst) { - VectorShuffleImpl(ShuffleType::Words, ctx, inst, code); + VectorShuffleImpl(code, ctx, inst, &Xbyak::CodeGenerator::pshufd); } void EmitX64::EmitVectorSignExtend8(EmitContext& ctx, IR::Inst* inst) {