From 1c87f040a3b0771f9b5d231eb5dee620d15b7ed6 Mon Sep 17 00:00:00 2001 From: Bram Speeckaert Date: Tue, 1 Nov 2022 21:28:41 +0100 Subject: [PATCH] JitArm64: mulli - Only allocate reg when necessary If the destination register doesn't equal the input register, using it to temporarily hold the immediate value is fair game as it'll be overwritten with the result of the multiplication anyway. This can slightly reduce register pressure. Before: 0x52800659 mov w25, #0x32 0x1b197f5b mul w27, w26, w25 After: 0x5280065b mov w27, #0x32 0x1b1b7f5b mul w27, w26, w27 --- .../Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp index 7d0e797340..6cd902d0c9 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp @@ -944,11 +944,16 @@ void JitArm64::mulli(UGeckoInstruction inst) } else { - gpr.BindToRegister(d, d == a); - ARM64Reg WA = gpr.GetReg(); + const bool allocate_reg = d == a; + gpr.BindToRegister(d, allocate_reg); + + // Reuse d to hold the immediate if possible, allocate a register otherwise. + ARM64Reg WA = allocate_reg ? gpr.GetReg() : gpr.R(d); + MOVI2R(WA, (u32)(s32)inst.SIMM_16); MUL(gpr.R(d), gpr.R(a), WA); - gpr.Unlock(WA); + if (allocate_reg) + gpr.Unlock(WA); } }