From b6e223fc581044aeb5fde546e8bdfee0b4c111ee Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 6 Jul 2018 16:55:01 -0400 Subject: [PATCH] emit_x64_vector: Deduplicate a bit of code within EmitVectorGetElement8() Given both branches use the same destination register size, we can hoist the common code out. --- src/backend_x64/emit_x64_vector.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/backend_x64/emit_x64_vector.cpp b/src/backend_x64/emit_x64_vector.cpp index ef9cab86..94496ff3 100644 --- a/src/backend_x64/emit_x64_vector.cpp +++ b/src/backend_x64/emit_x64_vector.cpp @@ -97,22 +97,21 @@ static void EmitTwoArgumentFallback(BlockOfCode& code, EmitContext& ctx, IR::Ins void EmitX64::EmitVectorGetElement8(EmitContext& ctx, IR::Inst* inst) { auto args = ctx.reg_alloc.GetArgumentInfo(inst); ASSERT(args[1].IsImmediate()); - u8 index = args[1].GetImmediateU8(); + const u8 index = args[1].GetImmediateU8(); - Xbyak::Xmm source = ctx.reg_alloc.UseXmm(args[0]); + const Xbyak::Xmm source = ctx.reg_alloc.UseXmm(args[0]); + const Xbyak::Reg32 dest = ctx.reg_alloc.ScratchGpr().cvt32(); if (code.DoesCpuSupport(Xbyak::util::Cpu::tSSE41)) { - Xbyak::Reg32 dest = ctx.reg_alloc.ScratchGpr().cvt32(); code.pextrb(dest, source, index); - ctx.reg_alloc.DefineValue(inst, dest); } else { - Xbyak::Reg32 dest = ctx.reg_alloc.ScratchGpr().cvt32(); code.pextrw(dest, source, index / 2); if (index % 2 == 1) { code.shr(dest, 8); } - ctx.reg_alloc.DefineValue(inst, dest); } + + ctx.reg_alloc.DefineValue(inst, dest); } void EmitX64::EmitVectorGetElement16(EmitContext& ctx, IR::Inst* inst) {