Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize large sign-extended constants #3655

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions FEXCore/Source/Interface/Core/ArchHelpers/Arm64Emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,17 @@ void Arm64Emitter::LoadConstant(ARMEmitter::Size s, ARMEmitter::Register Reg, ui
}
}

// If we can't handle negatives with the orr, try with movn+movk
if (Is64Bit && ((~Constant) >> 32) == 0) {
movn(s, Reg, (~Constant) & 0xFFFF);
movk(s, Reg, (Constant >> 16) & 0xFFFF, 16);
if (NOPPad) {
nop();
nop();
}
return;
}

// ADRP+ADD is specifically optimized in hardware
// Check if we can use this
auto PC = GetCursorAddress<uint64_t>();
Expand Down
13 changes: 13 additions & 0 deletions unittests/InstructionCountCI/FlagM/Secondary.json
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,19 @@
"ccmn xzr, #0, #nzCV, eq"
]
},
"imul rsi, rax, 0xffffffff8646c299": {
"ExpectedInstructionCount": 7,
"Comment": "0x0f 0xaf",
"ExpectedArm64ASM": [
"mov x20, #0xffffffffffffc299",
"movk x20, #0x8646, lsl #16",
"smulh x21, x4, x20",
"mul x10, x4, x20",
"asr x20, x10, #63",
"cmp x21, x20",
"ccmn xzr, #0, #nzCV, eq"
]
},
"cmpxchg cl, bl": {
"ExpectedInstructionCount": 11,
"ExpectedArm64ASM": [
Expand Down
Loading