mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-03-14 14:36:28 +00:00
Add AddTicks and GetTicksRemaining callbacks
This commit is contained in:
@@ -57,13 +57,13 @@ void BlockOfCode::ClearCache() {
|
||||
SetCodePtr(near_code_begin);
|
||||
}
|
||||
|
||||
size_t BlockOfCode::RunCode(JitState* jit_state, size_t cycles_to_run) const {
|
||||
void BlockOfCode::RunCode(JitState* jit_state, size_t cycles_to_run) const {
|
||||
constexpr size_t max_cycles_to_run = static_cast<size_t>(std::numeric_limits<decltype(jit_state->cycles_remaining)>::max());
|
||||
ASSERT(cycles_to_run <= max_cycles_to_run);
|
||||
|
||||
jit_state->cycles_to_run = cycles_to_run;
|
||||
jit_state->cycles_remaining = cycles_to_run;
|
||||
run_code(jit_state);
|
||||
return cycles_to_run - jit_state->cycles_remaining; // Return number of cycles actually run.
|
||||
}
|
||||
|
||||
void BlockOfCode::ReturnFromRunCode(bool MXCSR_switch) {
|
||||
@@ -118,6 +118,10 @@ void BlockOfCode::GenRunCode() {
|
||||
jg(loop);
|
||||
}
|
||||
|
||||
mov(ABI_PARAM1, qword[r15 + offsetof(JitState, cycles_to_run)]);
|
||||
sub(ABI_PARAM1, qword[r15 + offsetof(JitState, cycles_remaining)]);
|
||||
CallFunction(cb.AddTicks);
|
||||
|
||||
ABI_PopCalleeSaveRegistersAndAdjustStack(this);
|
||||
ret();
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
void ClearCache();
|
||||
|
||||
/// Runs emulated code for approximately `cycles_to_run` cycles.
|
||||
size_t RunCode(JitState* jit_state, size_t cycles_to_run) const;
|
||||
void RunCode(JitState* jit_state, size_t cycles_to_run) const;
|
||||
/// Code emitter: Returns to dispatcher
|
||||
void ReturnFromRunCode(bool MXCSR_switch = true);
|
||||
/// Code emitter: Returns to dispatcher, forces return to host
|
||||
|
||||
@@ -421,11 +421,21 @@ void EmitX64::EmitBXWritePC(RegAlloc& reg_alloc, IR::Block&, IR::Inst* inst) {
|
||||
}
|
||||
|
||||
void EmitX64::EmitCallSupervisor(RegAlloc& reg_alloc, IR::Block&, IR::Inst* inst) {
|
||||
auto args = reg_alloc.GetArgumentInfo(inst);
|
||||
reg_alloc.HostCall(nullptr, args[0]);
|
||||
using namespace Xbyak::util;
|
||||
|
||||
reg_alloc.HostCall(nullptr);
|
||||
|
||||
code->SwitchMxcsrOnExit();
|
||||
code->mov(code->ABI_PARAM1, qword[r15 + offsetof(JitState, cycles_to_run)]);
|
||||
code->sub(code->ABI_PARAM1, qword[r15 + offsetof(JitState, cycles_remaining)]);
|
||||
code->CallFunction(cb.AddTicks);
|
||||
reg_alloc.EndOfAllocScope();
|
||||
auto args = reg_alloc.GetArgumentInfo(inst);
|
||||
reg_alloc.HostCall(nullptr, args[0]);
|
||||
code->CallFunction(cb.CallSVC);
|
||||
code->CallFunction(cb.GetTicksRemaining);
|
||||
code->mov(qword[r15 + offsetof(JitState, cycles_to_run)], code->ABI_RETURN);
|
||||
code->mov(qword[r15 + offsetof(JitState, cycles_remaining)], code->ABI_RETURN);
|
||||
code->SwitchMxcsrOnEntry();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,8 @@ struct Jit::Impl {
|
||||
std::deque<Common::AddressRange> invalid_cache_ranges;
|
||||
bool invalidate_entire_cache = false;
|
||||
|
||||
size_t Execute(size_t cycle_count) {
|
||||
return block_of_code.RunCode(&jit_state, cycle_count);
|
||||
void Execute(size_t cycle_count) {
|
||||
block_of_code.RunCode(&jit_state, cycle_count);
|
||||
}
|
||||
|
||||
std::string Disassemble(const IR::LocationDescriptor& descriptor) {
|
||||
@@ -155,18 +155,16 @@ Jit::Jit(UserCallbacks callbacks) : impl(std::make_unique<Impl>(this, callbacks)
|
||||
|
||||
Jit::~Jit() {}
|
||||
|
||||
size_t Jit::Run(size_t cycle_count) {
|
||||
void Jit::Run(size_t cycle_count) {
|
||||
ASSERT(!is_executing);
|
||||
is_executing = true;
|
||||
SCOPE_EXIT({ this->is_executing = false; });
|
||||
|
||||
impl->jit_state.halt_requested = false;
|
||||
|
||||
size_t cycles_executed = impl->Execute(cycle_count);
|
||||
impl->Execute(cycle_count);
|
||||
|
||||
impl->PerformCacheInvalidation();
|
||||
|
||||
return cycles_executed;
|
||||
}
|
||||
|
||||
void Jit::ClearCache() {
|
||||
|
||||
@@ -36,6 +36,7 @@ struct JitState {
|
||||
// For internal use (See: BlockOfCode::RunCode)
|
||||
u32 guest_MXCSR = 0x00001f80;
|
||||
u32 save_host_MXCSR = 0;
|
||||
s64 cycles_to_run = 0;
|
||||
s64 cycles_remaining = 0;
|
||||
bool halt_requested = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user