Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11696 from AdmiralCurtiss/jit-interface-class
JitInterface: Refactor to class, move to System.
  • Loading branch information
lioncash committed Mar 27, 2023
2 parents 0de2890 + 7f50c07 commit c096ee6
Show file tree
Hide file tree
Showing 21 changed files with 247 additions and 180 deletions.
8 changes: 5 additions & 3 deletions Source/Android/jni/MainAndroid.cpp
Expand Up @@ -397,8 +397,9 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling
{
std::lock_guard<std::mutex> guard(s_host_identity_lock);
Core::SetState(Core::State::Paused);
JitInterface::ClearCache();
JitInterface::SetProfilingState(enable ? JitInterface::ProfilingState::Enabled :
auto& jit_interface = Core::System::GetInstance().GetJitInterface();
jit_interface.ClearCache();
jit_interface.SetProfilingState(enable ? JitInterface::ProfilingState::Enabled :
JitInterface::ProfilingState::Disabled);
Core::SetState(Core::State::Running);
}
Expand All @@ -409,7 +410,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfile
std::lock_guard<std::mutex> guard(s_host_identity_lock);
std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt";
File::CreateFullPath(filename);
JitInterface::WriteProfileResults(filename);
auto& jit_interface = Core::System::GetInstance().GetJitInterface();
jit_interface.WriteProfileResults(filename);
}

// Surface Handling
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Core.cpp
Expand Up @@ -986,7 +986,7 @@ void UpdateWantDeterminism(bool initial)

// We need to clear the cache because some parts of the JIT depend on want_determinism,
// e.g. use of FMA.
JitInterface::ClearCache();
system.GetJitInterface().ClearCache();
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/GPFifo.cpp
Expand Up @@ -132,7 +132,7 @@ void GPFifoManager::CheckGatherPipe()
UpdateGatherPipe();

// Profile where slow FIFO writes are occurring.
JitInterface::CompileExceptionCheck(JitInterface::ExceptionType::FIFOWrite);
m_system.GetJitInterface().CompileExceptionCheck(JitInterface::ExceptionType::FIFOWrite);
}
}

Expand Down
16 changes: 9 additions & 7 deletions Source/Core/Core/MemTools.cpp
Expand Up @@ -16,6 +16,7 @@

#include "Core/MachineContext.h"
#include "Core/PowerPC/JitInterface.h"
#include "Core/System.h"

#if defined(__FreeBSD__) || defined(__NetBSD__)
#include <signal.h>
Expand Down Expand Up @@ -60,7 +61,7 @@ static LONG NTAPI Handler(PEXCEPTION_POINTERS pPtrs)
uintptr_t fault_address = (uintptr_t)pPtrs->ExceptionRecord->ExceptionInformation[1];
SContext* ctx = pPtrs->ContextRecord;

if (JitInterface::HandleFault(fault_address, ctx))
if (Core::System::GetInstance().GetJitInterface().HandleFault(fault_address, ctx))
{
return EXCEPTION_CONTINUE_EXECUTION;
}
Expand All @@ -72,7 +73,7 @@ static LONG NTAPI Handler(PEXCEPTION_POINTERS pPtrs)
}

case EXCEPTION_STACK_OVERFLOW:
if (JitInterface::HandleStackFault())
if (Core::System::GetInstance().GetJitInterface().HandleStackFault())
return EXCEPTION_CONTINUE_EXECUTION;
else
return EXCEPTION_CONTINUE_SEARCH;
Expand Down Expand Up @@ -190,7 +191,8 @@ static void ExceptionThread(mach_port_t port)

thread_state64_t* state = (thread_state64_t*)msg_in.old_state;

bool ok = JitInterface::HandleFault((uintptr_t)msg_in.code[1], state);
bool ok =
Core::System::GetInstance().GetJitInterface().HandleFault((uintptr_t)msg_in.code[1], state);

// Set up the reply.
msg_out.Head.msgh_bits = MACH_MSGH_BITS(MACH_MSGH_BITS_REMOTE(msg_in.Head.msgh_bits), 0);
Expand Down Expand Up @@ -281,13 +283,13 @@ static void sigsegv_handler(int sig, siginfo_t* info, void* raw_context)
mcontext_t* ctx = &context->uc_mcontext;
#endif
// assume it's not a write
if (!JitInterface::HandleFault(bad_address,
if (!Core::System::GetInstance().GetJitInterface().HandleFault(bad_address,
#ifdef __APPLE__
*ctx
*ctx
#else
ctx
ctx
#endif
))
))
{
// retry and crash
// According to the sigaction man page, if sa_flags "SA_SIGINFO" is set to the sigaction
Expand Down
17 changes: 9 additions & 8 deletions Source/Core/Core/PowerPC/BreakPoints.cpp
Expand Up @@ -16,6 +16,7 @@
#include "Core/PowerPC/Expression.h"
#include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/MMU.h"
#include "Core/System.h"

bool BreakPoints::IsAddressBreakPoint(u32 address) const
{
Expand Down Expand Up @@ -105,7 +106,7 @@ void BreakPoints::Add(TBreakPoint bp)
if (IsAddressBreakPoint(bp.address))
return;

JitInterface::InvalidateICache(bp.address, 4, true);
Core::System::GetInstance().GetJitInterface().InvalidateICache(bp.address, 4, true);

m_breakpoints.emplace_back(std::move(bp));
}
Expand Down Expand Up @@ -141,7 +142,7 @@ void BreakPoints::Add(u32 address, bool temp, bool break_on_hit, bool log_on_hit
m_breakpoints.emplace_back(std::move(bp));
}

JitInterface::InvalidateICache(address, 4, true);
Core::System::GetInstance().GetJitInterface().InvalidateICache(address, 4, true);
}

bool BreakPoints::ToggleBreakPoint(u32 address)
Expand All @@ -165,14 +166,14 @@ void BreakPoints::Remove(u32 address)
return;

m_breakpoints.erase(iter);
JitInterface::InvalidateICache(address, 4, true);
Core::System::GetInstance().GetJitInterface().InvalidateICache(address, 4, true);
}

void BreakPoints::Clear()
{
for (const TBreakPoint& bp : m_breakpoints)
{
JitInterface::InvalidateICache(bp.address, 4, true);
Core::System::GetInstance().GetJitInterface().InvalidateICache(bp.address, 4, true);
}

m_breakpoints.clear();
Expand All @@ -185,7 +186,7 @@ void BreakPoints::ClearAllTemporary()
{
if (bp->is_temporary)
{
JitInterface::InvalidateICache(bp->address, 4, true);
Core::System::GetInstance().GetJitInterface().InvalidateICache(bp->address, 4, true);
bp = m_breakpoints.erase(bp);
}
else
Expand Down Expand Up @@ -278,7 +279,7 @@ void MemChecks::Add(TMemCheck memory_check)
// If this is the first one, clear the JIT cache so it can switch to
// watchpoint-compatible code.
if (!had_any)
JitInterface::ClearCache();
Core::System::GetInstance().GetJitInterface().ClearCache();
PowerPC::DBATUpdated();
});
}
Expand Down Expand Up @@ -307,7 +308,7 @@ void MemChecks::Remove(u32 address)
Core::RunAsCPUThread([&] {
m_mem_checks.erase(iter);
if (!HasAny())
JitInterface::ClearCache();
Core::System::GetInstance().GetJitInterface().ClearCache();
PowerPC::DBATUpdated();
});
}
Expand All @@ -316,7 +317,7 @@ void MemChecks::Clear()
{
Core::RunAsCPUThread([&] {
m_mem_checks.clear();
JitInterface::ClearCache();
Core::System::GetInstance().GetJitInterface().ClearCache();
PowerPC::DBATUpdated();
});
}
Expand Down
Expand Up @@ -16,6 +16,7 @@
#include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"

static u32 Helper_Get_EA(const PowerPC::PowerPCState& ppcs, const UGeckoInstruction inst)
{
Expand Down Expand Up @@ -473,7 +474,7 @@ void Interpreter::dcbf(Interpreter& interpreter, UGeckoInstruction inst)
// Invalidate the JIT cache here as a heuristic to compensate for
// the lack of precise L1 icache emulation in the JIT. (Portable software
// should use icbi consistently, but games aren't portable.)
JitInterface::InvalidateICacheLine(address);
interpreter.m_system.GetJitInterface().InvalidateICacheLine(address);
return;
}

Expand All @@ -495,7 +496,7 @@ void Interpreter::dcbi(Interpreter& interpreter, UGeckoInstruction inst)
// Invalidate the JIT cache here as a heuristic to compensate for
// the lack of precise L1 icache emulation in the JIT. (Portable software
// should use icbi consistently, but games aren't portable.)
JitInterface::InvalidateICacheLine(address);
interpreter.m_system.GetJitInterface().InvalidateICacheLine(address);
return;
}

Expand All @@ -511,7 +512,7 @@ void Interpreter::dcbst(Interpreter& interpreter, UGeckoInstruction inst)
// Invalidate the JIT cache here as a heuristic to compensate for
// the lack of precise L1 icache emulation in the JIT. (Portable software
// should use icbi consistently, but games aren't portable.)
JitInterface::InvalidateICacheLine(address);
interpreter.m_system.GetJitInterface().InvalidateICacheLine(address);
return;
}

Expand Down
8 changes: 4 additions & 4 deletions Source/Core/Core/PowerPC/Jit64/Jit.cpp
Expand Up @@ -877,8 +877,8 @@ bool Jit64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
const u8* target = GetCodePtr();
MOV(32, PPCSTATE(pc), Imm32(js.blockStart));
ABI_PushRegistersAndAdjustStack({}, 0);
ABI_CallFunctionC(JitInterface::CompileExceptionCheck,
static_cast<u32>(JitInterface::ExceptionType::PairedQuantize));
ABI_CallFunctionPC(JitInterface::CompileExceptionCheckFromJIT, &m_system.GetJitInterface(),
static_cast<u32>(JitInterface::ExceptionType::PairedQuantize));
ABI_PopRegistersAndAdjustStack({}, 0);
JMP(asm_routines.dispatcher_no_check, true);
SwitchToNearCode();
Expand Down Expand Up @@ -1193,8 +1193,8 @@ void Jit64::IntializeSpeculativeConstants()
target = GetCodePtr();
MOV(32, PPCSTATE(pc), Imm32(js.blockStart));
ABI_PushRegistersAndAdjustStack({}, 0);
ABI_CallFunctionC(JitInterface::CompileExceptionCheck,
static_cast<u32>(JitInterface::ExceptionType::SpeculativeConstants));
ABI_CallFunctionPC(JitInterface::CompileExceptionCheckFromJIT, &m_system.GetJitInterface(),
static_cast<u32>(JitInterface::ExceptionType::SpeculativeConstants));
ABI_PopRegistersAndAdjustStack({}, 0);
JMP(asm_routines.dispatcher_no_check, true);
SwitchToNearCode();
Expand Down
7 changes: 5 additions & 2 deletions Source/Core/Core/PowerPC/Jit64/Jit_LoadStore.cpp
Expand Up @@ -22,6 +22,7 @@
#include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"

using namespace Gen;

Expand Down Expand Up @@ -362,12 +363,14 @@ void Jit64::dcbx(UGeckoInstruction inst)
{
MOV(32, R(ABI_PARAM1), R(effective_address));
MOV(32, R(ABI_PARAM2), R(loop_counter));
ABI_CallFunction(JitInterface::InvalidateICacheLines);
MOV(64, R(ABI_PARAM3), Imm64(reinterpret_cast<u64>(&m_system.GetJitInterface())));
ABI_CallFunction(JitInterface::InvalidateICacheLinesFromJIT);
}
else
{
MOV(32, R(ABI_PARAM1), R(effective_address));
ABI_CallFunction(JitInterface::InvalidateICacheLine);
MOV(64, R(ABI_PARAM3), Imm64(reinterpret_cast<u64>(&m_system.GetJitInterface())));
ABI_CallFunction(JitInterface::InvalidateICacheLineFromJIT);
}
ABI_PopRegistersAndAdjustStack(registersInUse, 0);
asm_routines.ResetStack(*this);
Expand Down
12 changes: 7 additions & 5 deletions Source/Core/Core/PowerPC/JitArm64/Jit.cpp
Expand Up @@ -327,8 +327,9 @@ void JitArm64::IntializeSpeculativeConstants()
fail = GetCodePtr();
MOVI2R(DISPATCHER_PC, js.blockStart);
STR(IndexType::Unsigned, DISPATCHER_PC, PPC_REG, PPCSTATE_OFF(pc));
MOVP2R(ARM64Reg::X8, &JitInterface::CompileExceptionCheck);
MOVI2R(ARM64Reg::W0, static_cast<u32>(JitInterface::ExceptionType::SpeculativeConstants));
MOVP2R(ARM64Reg::X8, &JitInterface::CompileExceptionCheckFromJIT);
MOVP2R(ARM64Reg::X0, &m_system.GetJitInterface());
MOVI2R(ARM64Reg::W1, static_cast<u32>(JitInterface::ExceptionType::SpeculativeConstants));
BLR(ARM64Reg::X8);
B(dispatcher_no_check);
SwitchToNearCode();
Expand Down Expand Up @@ -866,9 +867,10 @@ bool JitArm64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
SetJumpTarget(fail);
MOVI2R(DISPATCHER_PC, js.blockStart);
STR(IndexType::Unsigned, DISPATCHER_PC, PPC_REG, PPCSTATE_OFF(pc));
MOVI2R(ARM64Reg::W0, static_cast<u32>(JitInterface::ExceptionType::PairedQuantize));
MOVP2R(ARM64Reg::X1, &JitInterface::CompileExceptionCheck);
BLR(ARM64Reg::X1);
MOVP2R(ARM64Reg::X0, &m_system.GetJitInterface());
MOVI2R(ARM64Reg::W1, static_cast<u32>(JitInterface::ExceptionType::PairedQuantize));
MOVP2R(ARM64Reg::X2, &JitInterface::CompileExceptionCheckFromJIT);
BLR(ARM64Reg::X2);
B(dispatcher_no_check);
SwitchToNearCode();
SetJumpTarget(no_fail);
Expand Down
7 changes: 4 additions & 3 deletions Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp
Expand Up @@ -770,11 +770,12 @@ void JitArm64::dcbx(UGeckoInstruction inst)
ABI_PushRegisters(gprs_to_push);
m_float_emit.ABI_PushRegisters(fprs_to_push, WA);

// The function call arguments are already in the correct registers
// The first two function call arguments are already in the correct registers
MOVP2R(ARM64Reg::X2, &m_system.GetJitInterface());
if (make_loop)
MOVP2R(ARM64Reg::X8, &JitInterface::InvalidateICacheLines);
MOVP2R(ARM64Reg::X8, &JitInterface::InvalidateICacheLinesFromJIT);
else
MOVP2R(ARM64Reg::X8, &JitInterface::InvalidateICacheLine);
MOVP2R(ARM64Reg::X8, &JitInterface::InvalidateICacheLineFromJIT);
BLR(ARM64Reg::X8);

m_float_emit.ABI_PopRegisters(fprs_to_push, WA);
Expand Down

0 comments on commit c096ee6

Please sign in to comment.