JitArm64: MultiplyImmediate - Handle 2^n

Turn multiplications by a power of two into bitshifts.

Before:
0x52800817   mov    w23, #0x40
0x1b167ef6   mul    w22, w23, w22

After:
0x531a66d6   lsl    w22, w22, #6
This commit is contained in:
Bram Speeckaert 2022-11-01 20:58:16 +01:00
parent f25611f388
commit 3aaf1a2b8b
1 changed files with 10 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/BitUtils.h" #include "Common/BitUtils.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/MathUtil.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/CoreTiming.h" #include "Core/CoreTiming.h"
@ -894,6 +895,15 @@ bool JitArm64::MultiplyImmediate(u32 imm, int a, int d, bool rc)
if (rc) if (rc)
ComputeRC0(gpr.R(d)); ComputeRC0(gpr.R(d));
} }
else if (MathUtil::IsPow2(imm))
{
const int shift = IntLog2(imm);
gpr.BindToRegister(d, d == a);
LSL(gpr.R(d), gpr.R(a), shift);
if (rc)
ComputeRC0(gpr.R(d));
}
else else
{ {
// Immediate did not match any known special cases. // Immediate did not match any known special cases.