Skip to content

Commit 7073a13

Browse files
committed
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
1 parent 1c87f04 commit 7073a13

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Source/Core/Core/PowerPC/JitArm64/JitArm64_Integer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,16 @@ bool JitArm64::MultiplyImmediate(u32 imm, int a, int d, bool rc)
917917
if (rc)
918918
ComputeRC0(gpr.R(d));
919919
}
920+
else if (MathUtil::IsPow2(~imm + 1))
921+
{
922+
// Multiplication by a negative power of two (-(2^n)).
923+
const int shift = IntLog2(~imm + 1);
924+
925+
gpr.BindToRegister(d, d == a);
926+
NEG(gpr.R(d), gpr.R(a), ArithOption(gpr.R(a), ShiftType::LSL, shift));
927+
if (rc)
928+
ComputeRC0(gpr.R(d));
929+
}
920930
else
921931
{
922932
// Immediate did not match any known special cases.

0 commit comments

Comments
 (0)