From b7301bee29bba0d71963931b227679485153c6fd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 21 Jun 2018 04:37:57 -0400 Subject: [PATCH] DSP: Replace x64 JIT pointer with a pointer to an architecture-agnostic base This adds a base class that is used to replace the concrete instance of the x64 JIT pointer within DSPCore. This fully removes the direct use (read: non-ifdefed) usage of x86-64-specifics within the main DSP code. Said base can also be used for creating JITs for other architectures, such as AArch64, etc. --- Source/Core/Core/CMakeLists.txt | 13 ++++---- Source/Core/Core/Core.vcxproj | 10 +++--- Source/Core/Core/Core.vcxproj.filters | 6 ++++ Source/Core/Core/DSP/DSPCore.cpp | 7 ++--- Source/Core/Core/DSP/DSPCore.h | 5 +-- Source/Core/Core/DSP/Jit/DSPEmitterBase.cpp | 23 ++++++++++++++ Source/Core/Core/DSP/Jit/DSPEmitterBase.h | 35 +++++++++++++++++++++ Source/Core/Core/DSP/Jit/x64/DSPEmitter.h | 12 +++---- Source/Core/Core/HW/DSPLLE/DSPLLE.cpp | 2 +- 9 files changed, 88 insertions(+), 25 deletions(-) create mode 100644 Source/Core/Core/DSP/Jit/DSPEmitterBase.cpp create mode 100644 Source/Core/Core/DSP/Jit/DSPEmitterBase.h diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 4959f00c85..ca0b61bc4d 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -38,18 +38,18 @@ add_library(core Debugger/Dump.cpp Debugger/PPCDebugInterface.cpp Debugger/RSO.cpp - DSP/DSPAssembler.cpp - DSP/DSPDisassembler.cpp DSP/DSPAccelerator.cpp + DSP/DSPAnalyzer.cpp + DSP/DSPAssembler.cpp DSP/DSPCaptureLogger.cpp + DSP/DSPCodeUtil.cpp + DSP/DSPCore.cpp + DSP/DSPDisassembler.cpp DSP/DSPHWInterface.cpp DSP/DSPMemoryMap.cpp DSP/DSPStacks.cpp - DSP/DSPAnalyzer.cpp - DSP/DSPCodeUtil.cpp - DSP/LabelMap.cpp - DSP/DSPCore.cpp DSP/DSPTables.cpp + DSP/LabelMap.cpp DSP/Interpreter/DSPIntArithmetic.cpp DSP/Interpreter/DSPIntBranch.cpp DSP/Interpreter/DSPIntCCUtil.cpp @@ -59,6 +59,7 @@ add_library(core DSP/Interpreter/DSPIntMisc.cpp DSP/Interpreter/DSPIntMultiplier.cpp DSP/Interpreter/DSPIntTables.cpp + DSP/Jit/DSPEmitterBase.cpp DSP/Jit/x64/DSPEmitter.cpp DSP/Jit/x64/DSPJitRegCache.cpp DSP/Jit/x64/DSPJitExtOps.cpp diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index 892bfcac35..2045848739 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -62,13 +62,13 @@ - - + + @@ -82,6 +82,7 @@ + @@ -326,15 +327,15 @@ - - + + @@ -345,6 +346,7 @@ + diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index def8175d35..5f561a8a44 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -243,6 +243,9 @@ DSPCore\Interpreter + + DSPCore\Jit + DSPCore\Jit\x64 @@ -972,6 +975,9 @@ DSPCore\Interpreter + + DSPCore\Jit + DSPCore\Jit\x64 diff --git a/Source/Core/Core/DSP/DSPCore.cpp b/Source/Core/Core/DSP/DSPCore.cpp index 3f9769aeea..7ed550a59e 100644 --- a/Source/Core/Core/DSP/DSPCore.cpp +++ b/Source/Core/Core/DSP/DSPCore.cpp @@ -22,8 +22,7 @@ #include "Core/DSP/DSPHost.h" #include "Core/DSP/Interpreter/DSPIntUtil.h" #include "Core/DSP/Interpreter/DSPInterpreter.h" -#include "Core/DSP/Jit/x64/DSPEmitter.h" -#include "Core/HW/DSP.h" +#include "Core/DSP/Jit/DSPEmitterBase.h" namespace DSP { @@ -31,7 +30,7 @@ SDSP g_dsp; DSPBreakpoints g_dsp_breakpoints; static State core_state = State::Stopped; bool g_init_hax = false; -std::unique_ptr g_dsp_jit; +std::unique_ptr g_dsp_jit; std::unique_ptr g_dsp_cap; static Common::Event step_event; @@ -172,7 +171,7 @@ bool DSPCore_Init(const DSPInitOptions& opts) // Initialize JIT, if necessary if (opts.core_type == DSPInitOptions::CoreType::JIT64) - g_dsp_jit = std::make_unique(); + g_dsp_jit = JIT::CreateDSPEmitter(); g_dsp_cap.reset(opts.capture_logger); diff --git a/Source/Core/Core/DSP/DSPCore.h b/Source/Core/Core/DSP/DSPCore.h index ab89ae6cf4..36eaf671c4 100644 --- a/Source/Core/Core/DSP/DSPCore.h +++ b/Source/Core/Core/DSP/DSPCore.h @@ -20,11 +20,8 @@ class Accelerator; namespace JIT { -namespace x64 -{ class DSPEmitter; } -} enum : u32 { @@ -317,7 +314,7 @@ struct SDSP extern SDSP g_dsp; extern DSPBreakpoints g_dsp_breakpoints; extern bool g_init_hax; -extern std::unique_ptr g_dsp_jit; +extern std::unique_ptr g_dsp_jit; extern std::unique_ptr g_dsp_cap; struct DSPInitOptions diff --git a/Source/Core/Core/DSP/Jit/DSPEmitterBase.cpp b/Source/Core/Core/DSP/Jit/DSPEmitterBase.cpp new file mode 100644 index 0000000000..be6208bdbe --- /dev/null +++ b/Source/Core/Core/DSP/Jit/DSPEmitterBase.cpp @@ -0,0 +1,23 @@ +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "Core/DSP/Jit/DSPEmitterBase.h" + +#if defined(_M_X86) || defined(_M_X86_64) +#include "Core/DSP/Jit/x64/DSPEmitter.h" +#endif + +namespace DSP::JIT +{ +DSPEmitter::~DSPEmitter() = default; + +std::unique_ptr CreateDSPEmitter() +{ +#if defined(_M_X86) || defined(_M_X86_64) + return std::make_unique(); +#else + return std::make_unique(); +#endif +} +} // namespace DSP::JIT diff --git a/Source/Core/Core/DSP/Jit/DSPEmitterBase.h b/Source/Core/Core/DSP/Jit/DSPEmitterBase.h new file mode 100644 index 0000000000..7120e1de68 --- /dev/null +++ b/Source/Core/Core/DSP/Jit/DSPEmitterBase.h @@ -0,0 +1,35 @@ +// Copyright 2018 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "Common/CommonTypes.h" + +class PointerWrap; + +namespace DSP::JIT +{ +class DSPEmitter +{ +public: + virtual ~DSPEmitter(); + + virtual u16 RunCycles(u16 cycles) = 0; + virtual void ClearIRAM() = 0; + + virtual void DoState(PointerWrap& p) = 0; +}; + +class DSPEmitterNull final : public DSPEmitter +{ +public: + u16 RunCycles(u16) override { return 0; } + void ClearIRAM() override {} + void DoState(PointerWrap&) override {} +}; + +std::unique_ptr CreateDSPEmitter(); +} // namespace DSP::JIT diff --git a/Source/Core/Core/DSP/Jit/x64/DSPEmitter.h b/Source/Core/Core/DSP/Jit/x64/DSPEmitter.h index 4c4efdd4e6..1d1566b288 100644 --- a/Source/Core/Core/DSP/Jit/x64/DSPEmitter.h +++ b/Source/Core/Core/DSP/Jit/x64/DSPEmitter.h @@ -14,6 +14,7 @@ #include "Common/x64Emitter.h" #include "Core/DSP/DSPCommon.h" +#include "Core/DSP/Jit/DSPEmitterBase.h" #include "Core/DSP/Jit/x64/DSPJitRegCache.h" class PointerWrap; @@ -24,7 +25,7 @@ enum class StackRegister; namespace JIT::x64 { -class DSPEmitter : public Gen::X64CodeBlock +class DSPEmitter final : public JIT::DSPEmitter, public Gen::X64CodeBlock { public: using DSPCompiledCode = u32 (*)(); @@ -33,14 +34,13 @@ public: static constexpr size_t MAX_BLOCKS = 0x10000; DSPEmitter(); - ~DSPEmitter(); + ~DSPEmitter() override; - u16 RunCycles(u16 cycles); - - void DoState(PointerWrap& p); + u16 RunCycles(u16 cycles) override; + void DoState(PointerWrap& p) override; + void ClearIRAM() override; void EmitInstruction(UDSPInstruction inst); - void ClearIRAM(); void ClearIRAMandDSPJITCodespaceReset(); void CompileDispatcher(); diff --git a/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp b/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp index 565440b866..2ea1f01628 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp +++ b/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp @@ -25,7 +25,7 @@ #include "Core/DSP/DSPHost.h" #include "Core/DSP/DSPTables.h" #include "Core/DSP/Interpreter/DSPInterpreter.h" -#include "Core/DSP/Jit/x64/DSPEmitter.h" +#include "Core/DSP/Jit/DSPEmitterBase.h" #include "Core/HW/DSPLLE/DSPLLEGlobals.h" #include "Core/HW/Memmap.h" #include "Core/Host.h"