summaryrefslogtreecommitdiff
path: root/Source/Core/Common/x64Emitter.cpp
diff options
context:
space:
mode:
authorMartino Fontana <tinozzo123@gmail.com>2025-10-05 21:46:41 +0200
committerMartino Fontana <tinozzo123@gmail.com>2025-10-08 00:15:57 +0200
commitf6e5448b43f74fffab22eca2f96b281ef0f662d3 (patch)
tree0535a3a960584695b0a73462c309dd01875e9e25 /Source/Core/Common/x64Emitter.cpp
parent70bd0943a7a271606367ac129eb39cbdcd659e42 (diff)
Jit64: Dynamic length of regular jump instruction (for known addresses)
Conditional jumps already do that, so let's be consistent.
Diffstat (limited to 'Source/Core/Common/x64Emitter.cpp')
-rw-r--r--Source/Core/Common/x64Emitter.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/Source/Core/Common/x64Emitter.cpp b/Source/Core/Common/x64Emitter.cpp
index 3db669e9b2..46b117a87f 100644
--- a/Source/Core/Common/x64Emitter.cpp
+++ b/Source/Core/Common/x64Emitter.cpp
@@ -412,27 +412,31 @@ void XEmitter::Rex(int w, int r, int x, int b)
Write8(rx);
}
-void XEmitter::JMP(const u8* addr, const Jump jump)
+void XEmitter::JMP(const u8* addr, bool force_near_padding)
{
u64 fn = (u64)addr;
- if (jump == Jump::Short)
- {
- s64 distance = (s64)(fn - ((u64)code + 2));
- ASSERT_MSG(DYNA_REC, distance >= -0x80 && distance < 0x80,
- "Jump::Short target too far away ({}), needs Jump::Near", distance);
- // 8 bits will do
- Write8(0xEB);
- Write8((u8)(s8)distance);
- }
- else
+ s64 distance = (s64)(fn - ((u64)code + SHORT_JMP_LEN));
+ if (distance < -0x80 || distance >= 0x80)
{
- s64 distance = (s64)(fn - ((u64)code + 5));
-
+ distance = (s64)(fn - ((u64)code + NEAR_JMP_LEN));
ASSERT_MSG(DYNA_REC, distance >= -0x80000000LL && distance < 0x80000000LL,
- "Jump::Near target too far away ({}), needs indirect register", distance);
+ "Jump target too far away ({}), needs indirect register", distance);
Write8(0xE9);
Write32((u32)(s32)distance);
}
+ else
+ {
+ Write8(0xEB);
+ Write8((u8)(s8)distance);
+ if (force_near_padding)
+ {
+ for (int i = 0; i < NEAR_JMP_LEN - SHORT_JMP_LEN; i++)
+ {
+ // INT3 is more efficient than NOP if never executed, as it stops CPU speculation.
+ INT3();
+ }
+ }
+ }
}
void XEmitter::JMPptr(const OpArg& arg2)