[dynarmic] x86 direct immediate call for host calls within 2G (#3508)

Signed-off-by: lizzie <lizzie@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3508
Reviewed-by: DraVee <dravee@eden-emu.dev>
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Co-authored-by: lizzie <lizzie@eden-emu.dev>
Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie 2026-02-12 01:45:22 +01:00 committed by crueter
parent 7d81a724ef
commit 89bcb73d47
No known key found for this signature in database
GPG Key ID: 425ACD2D4830EBC6
1 changed files with 13 additions and 2 deletions

View File

@ -71,11 +71,22 @@ void EmitX64::EmitBreakpoint(EmitContext&, IR::Inst*) {
code.int3();
}
constexpr bool IsWithin2G(uintptr_t ref, uintptr_t target) {
const u64 distance = target - (ref + 5);
return !(distance >= 0x8000'0000ULL && distance <= ~0x8000'0000ULL);
}
void EmitX64::EmitCallHostFunction(EmitContext& ctx, IR::Inst* inst) {
auto args = ctx.reg_alloc.GetArgumentInfo(inst);
ctx.reg_alloc.HostCall(code, nullptr, args[1], args[2], args[3]);
code.mov(rax, args[0].GetImmediateU64());
auto target = args[0].GetImmediateU64();
if (IsWithin2G(uintptr_t(code.getCurr()), target)) {
auto const f = std::bit_cast<void(*)(void)>(target);
code.call(f);
} else {
code.mov(rax, target);
code.call(rax);
}
}
void EmitX64::PushRSBHelper(Xbyak::Reg64 loc_desc_reg, Xbyak::Reg64 index_reg, IR::LocationDescriptor target) {