From 7e0c415473b063f7cb7c10e8ee1137cf3e848b85 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Mon, 6 Apr 2020 15:45:15 +0100 Subject: [PATCH] block_of_code: Always specify codeptr to run from --- src/backend/x64/a32_interface.cpp | 2 +- src/backend/x64/a64_interface.cpp | 2 +- src/backend/x64/block_of_code.cpp | 32 ++++++++++--------------------- src/backend/x64/block_of_code.h | 10 +++------- 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/backend/x64/a32_interface.cpp b/src/backend/x64/a32_interface.cpp index 18b04e81..62ca2f0b 100644 --- a/src/backend/x64/a32_interface.cpp +++ b/src/backend/x64/a32_interface.cpp @@ -70,7 +70,7 @@ struct Jit::Impl { return GetCurrentBlock(); }(); - block_of_code.RunCodeFrom(&jit_state, current_codeptr); + block_of_code.RunCode(&jit_state, current_codeptr); } void Step() { diff --git a/src/backend/x64/a64_interface.cpp b/src/backend/x64/a64_interface.cpp index 5ac60112..90e031d8 100644 --- a/src/backend/x64/a64_interface.cpp +++ b/src/backend/x64/a64_interface.cpp @@ -64,7 +64,7 @@ public: return GetCurrentBlock(); }(); - block_of_code.RunCodeFrom(&jit_state, current_code_ptr); + block_of_code.RunCode(&jit_state, current_code_ptr); PerformRequestedCacheInvalidation(); } diff --git a/src/backend/x64/block_of_code.cpp b/src/backend/x64/block_of_code.cpp index c69c94df..0f2b9099 100644 --- a/src/backend/x64/block_of_code.cpp +++ b/src/backend/x64/block_of_code.cpp @@ -134,12 +134,8 @@ size_t BlockOfCode::SpaceRemaining() const { return std::min(TOTAL_CODE_SIZE - far_code_offset, FAR_CODE_OFFSET - near_code_offset); } -void BlockOfCode::RunCode(void* jit_state) const { - run_code(jit_state); -} - -void BlockOfCode::RunCodeFrom(void* jit_state, CodePtr code_ptr) const { - run_code_from(jit_state, code_ptr); +void BlockOfCode::RunCode(void* jit_state, CodePtr code_ptr) const { + run_code(jit_state, code_ptr); } void BlockOfCode::StepCode(void* jit_state, CodePtr code_ptr) const { @@ -164,8 +160,12 @@ void BlockOfCode::GenRunCode() { Xbyak::Label loop, enter_mxcsr_then_loop; align(); - run_code_from = getCurr(); + run_code = getCurr(); + // This serves two purposes: + // 1. It saves all the registers we as a callee need to save. + // 2. It aligns the stack so that the code the JIT emits can assume + // that the stack is appropriately aligned for CALLs. ABI_PushCalleeSaveRegistersAndAdjustStack(*this); mov(r15, ABI_PARAM1); @@ -179,7 +179,7 @@ void BlockOfCode::GenRunCode() { jmp(r14); align(); - step_code = getCurr(); + step_code = getCurr(); ABI_PushCalleeSaveRegistersAndAdjustStack(*this); @@ -192,25 +192,13 @@ void BlockOfCode::GenRunCode() { jmp(ABI_PARAM2); align(); - run_code = getCurr(); - // This serves two purposes: - // 1. It saves all the registers we as a callee need to save. - // 2. It aligns the stack so that the code the JIT emits can assume - // that the stack is appropriately aligned for CALLs. - ABI_PushCalleeSaveRegistersAndAdjustStack(*this); - - mov(r15, ABI_PARAM1); - - cb.GetTicksRemaining->EmitCall(*this); - mov(qword[r15 + jsi.offsetof_cycles_to_run], ABI_RETURN); - mov(qword[r15 + jsi.offsetof_cycles_remaining], ABI_RETURN); + // Dispatcher loop L(enter_mxcsr_then_loop); SwitchMxcsrOnEntry(); L(loop); cb.LookupBlock->EmitCall(*this); - jmp(ABI_RETURN); // Return from run code variants @@ -249,7 +237,7 @@ void BlockOfCode::GenRunCode() { return_from_run_code[MXCSR_ALREADY_EXITED | FORCE_RETURN] = getCurr(); emit_return_from_run_code(true, true); - PerfMapRegister(run_code_from, getCurr(), "dynarmic_dispatcher"); + PerfMapRegister(run_code, getCurr(), "dynarmic_dispatcher"); } void BlockOfCode::SwitchMxcsrOnEntry() { diff --git a/src/backend/x64/block_of_code.h b/src/backend/x64/block_of_code.h index 6380bb7c..b17086e2 100644 --- a/src/backend/x64/block_of_code.h +++ b/src/backend/x64/block_of_code.h @@ -47,10 +47,8 @@ public: /// Calculates how much space is remaining to use. This is the minimum of near code and far code. size_t SpaceRemaining() const; - /// Runs emulated code. - void RunCode(void* jit_state) const; /// Runs emulated code from code_ptr. - void RunCodeFrom(void* jit_state, CodePtr code_ptr) const; + void RunCode(void* jit_state, CodePtr code_ptr) const; /// Runs emulated code from code_ptr for a single cycle. void StepCode(void* jit_state, CodePtr code_ptr) const; /// Code emitter: Returns to dispatcher @@ -157,11 +155,9 @@ private: CodePtr near_code_ptr; CodePtr far_code_ptr; - using RunCodeFuncType = void(*)(void*); - using RunCodeFromFuncType = void(*)(void*, CodePtr); + using RunCodeFuncType = void(*)(void*, CodePtr); RunCodeFuncType run_code = nullptr; - RunCodeFromFuncType step_code = nullptr; - RunCodeFromFuncType run_code_from = nullptr; + RunCodeFuncType step_code = nullptr; static constexpr size_t MXCSR_ALREADY_EXITED = 1 << 0; static constexpr size_t FORCE_RETURN = 1 << 1; std::array return_from_run_code;