JitArm64: MultiplyImmediate - Handle -(2^n)

ARM64's flexible shifting of input registers also allows us to calculate
a negative power of two in one instruction; shift the input of a NEG
instruction.

Before:
0x128001f7   mov    w23, #-0x10
0x1b1a7efa   mul    w26, w23, w26
0x93407f58   sxtw   x24, w26

After:
0x4b1a13fa   neg    w26, w26, lsl #4
0x93407f58   sxtw   x24, w26
This commit is contained in:
Bram Speeckaert 2022-11-02 21:33:47 +01:00
parent 1c87f040a3
commit 7073a135c6
1 changed files with 10 additions and 0 deletions

View File

@ -917,6 +917,16 @@ bool JitArm64::MultiplyImmediate(u32 imm, int a, int d, bool rc)
if (rc)
ComputeRC0(gpr.R(d));
}
else if (MathUtil::IsPow2(~imm + 1))
{
// Multiplication by a negative power of two (-(2^n)).
const int shift = IntLog2(~imm + 1);
gpr.BindToRegister(d, d == a);
NEG(gpr.R(d), gpr.R(a), ArithOption(gpr.R(a), ShiftType::LSL, shift));
if (rc)
ComputeRC0(gpr.R(d));
}
else
{
// Immediate did not match any known special cases.