From c79cc3f4709e5426eff34a7404452e7de25bf1e8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 28 Dec 2016 18:45:12 -0500 Subject: [PATCH] DSP: Namespace the JIT --- Source/Core/Core/DSP/DSPCore.cpp | 6 +++--- Source/Core/Core/DSP/DSPCore.h | 11 ++++++++++- Source/Core/Core/DSP/DSPTables.cpp | 2 ++ Source/Core/Core/DSP/DSPTables.h | 2 +- Source/Core/Core/DSP/Jit/DSPEmitter.cpp | 14 ++++++++++++-- Source/Core/Core/DSP/Jit/DSPEmitter.h | 10 ++++++++++ Source/Core/Core/DSP/Jit/DSPJitArithmetic.cpp | 12 +++++++++--- Source/Core/Core/DSP/Jit/DSPJitBranch.cpp | 10 ++++++++++ Source/Core/Core/DSP/Jit/DSPJitCCUtil.cpp | 10 ++++++++++ Source/Core/Core/DSP/Jit/DSPJitExtOps.cpp | 10 ++++++++++ Source/Core/Core/DSP/Jit/DSPJitLoadStore.cpp | 10 ++++++++++ Source/Core/Core/DSP/Jit/DSPJitMisc.cpp | 10 ++++++++++ Source/Core/Core/DSP/Jit/DSPJitMultiplier.cpp | 10 ++++++++++ Source/Core/Core/DSP/Jit/DSPJitRegCache.cpp | 10 ++++++++++ Source/Core/Core/DSP/Jit/DSPJitRegCache.h | 10 ++++++++++ Source/Core/Core/DSP/Jit/DSPJitUtil.cpp | 10 ++++++++++ 16 files changed, 137 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/DSP/DSPCore.cpp b/Source/Core/Core/DSP/DSPCore.cpp index f3ff8d6642..a1e3f0361d 100644 --- a/Source/Core/Core/DSP/DSPCore.cpp +++ b/Source/Core/Core/DSP/DSPCore.cpp @@ -29,7 +29,7 @@ DSPBreakpoints g_dsp_breakpoints; static DSPCoreState core_state = DSPCORE_STOP; u16 g_cycles_left = 0; 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; @@ -148,7 +148,7 @@ bool DSPCore_Init(const DSPInitOptions& opts) // Initialize JIT, if necessary if (opts.core_type == DSPInitOptions::CORE_JIT) - g_dsp_jit = std::make_unique(); + g_dsp_jit = std::make_unique(); g_dsp_cap.reset(opts.capture_logger); @@ -251,7 +251,7 @@ int DSPCore_RunCycles(int cycles) } g_cycles_left = cycles; - auto exec_addr = (DSPEmitter::DSPCompiledCode)g_dsp_jit->enterDispatcher; + auto exec_addr = (DSP::JIT::x86::DSPEmitter::DSPCompiledCode)g_dsp_jit->enterDispatcher; exec_addr(); if (g_dsp.reset_dspjit_codespace) diff --git a/Source/Core/Core/DSP/DSPCore.h b/Source/Core/Core/DSP/DSPCore.h index f53a860b97..93b58290d4 100644 --- a/Source/Core/Core/DSP/DSPCore.h +++ b/Source/Core/Core/DSP/DSPCore.h @@ -14,7 +14,16 @@ #include "Core/DSP/DSPBreakpoints.h" #include "Core/DSP/DSPCaptureLogger.h" +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ class DSPEmitter; +} +} +} enum : u32 { @@ -302,7 +311,7 @@ extern SDSP g_dsp; extern DSPBreakpoints g_dsp_breakpoints; extern u16 g_cycles_left; 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/DSPTables.cpp b/Source/Core/Core/DSP/DSPTables.cpp index 60458252d1..02bc5a7212 100644 --- a/Source/Core/Core/DSP/DSPTables.cpp +++ b/Source/Core/Core/DSP/DSPTables.cpp @@ -12,6 +12,8 @@ #include "Core/DSP/Interpreter/DSPInterpreter.h" #include "Core/DSP/Jit/DSPEmitter.h" +using DSP::JIT::x86::DSPEmitter; + // clang-format off const DSPOPCTemplate opcodes[] = { diff --git a/Source/Core/Core/DSP/DSPTables.h b/Source/Core/Core/DSP/DSPTables.h index b96d70cfdd..9bb63a0167 100644 --- a/Source/Core/Core/DSP/DSPTables.h +++ b/Source/Core/Core/DSP/DSPTables.h @@ -66,7 +66,7 @@ struct param2_t struct DSPOPCTemplate { using InterpreterFunction = void (*)(UDSPInstruction); - using JITFunction = void (DSPEmitter::*)(UDSPInstruction); + using JITFunction = void (DSP::JIT::x86::DSPEmitter::*)(UDSPInstruction); const char* name; u16 opcode; diff --git a/Source/Core/Core/DSP/Jit/DSPEmitter.cpp b/Source/Core/Core/DSP/Jit/DSPEmitter.cpp index f7beb223bd..df597cf71c 100644 --- a/Source/Core/Core/DSP/Jit/DSPEmitter.cpp +++ b/Source/Core/Core/DSP/Jit/DSPEmitter.cpp @@ -18,12 +18,18 @@ #include "Core/DSP/DSPMemoryMap.h" #include "Core/DSP/DSPTables.h" +using namespace Gen; + +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ constexpr size_t COMPILED_CODE_SIZE = 2097152; constexpr size_t MAX_BLOCK_SIZE = 250; constexpr u16 DSP_IDLE_SKIP_CYCLES = 0x1000; -using namespace Gen; - DSPEmitter::DSPEmitter() : blockLinks(MAX_BLOCKS), blockSize(MAX_BLOCKS), blocks(MAX_BLOCKS), compileSR{SR_INT_ENABLE | SR_EXT_INT_ENABLE} @@ -415,3 +421,7 @@ void DSPEmitter::CompileDispatcher() ABI_PopRegistersAndAdjustStack(registers_used, 8); RET(); } + +} // namespace x86 +} // namespace JIT +} // namespace DSP diff --git a/Source/Core/Core/DSP/Jit/DSPEmitter.h b/Source/Core/Core/DSP/Jit/DSPEmitter.h index 6eab333f0a..9c51e5b530 100644 --- a/Source/Core/Core/DSP/Jit/DSPEmitter.h +++ b/Source/Core/Core/DSP/Jit/DSPEmitter.h @@ -15,6 +15,12 @@ #include "Core/DSP/DSPCommon.h" #include "Core/DSP/Jit/DSPJitRegCache.h" +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ class DSPEmitter : public Gen::X64CodeBlock { public: @@ -281,3 +287,7 @@ private: void get_ax_h(int _reg, Gen::X64Reg acc = Gen::EAX); void get_long_acc(int _reg, Gen::X64Reg acc = Gen::EAX); }; + +} // namespace x86 +} // namespace JIT +} // namespace DSP diff --git a/Source/Core/Core/DSP/Jit/DSPJitArithmetic.cpp b/Source/Core/Core/DSP/Jit/DSPJitArithmetic.cpp index b647327a92..238120215c 100644 --- a/Source/Core/Core/DSP/Jit/DSPJitArithmetic.cpp +++ b/Source/Core/Core/DSP/Jit/DSPJitArithmetic.cpp @@ -12,6 +12,12 @@ using namespace Gen; +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ // CLR $acR // 1000 r001 xxxx xxxx // Clears accumulator $acR @@ -1672,6 +1678,6 @@ void DSPEmitter::asrnr(const UDSPInstruction opc) } } -//} // namespace - -// +} // namespace x86 +} // namespace JIT +} // namespace DSP diff --git a/Source/Core/Core/DSP/Jit/DSPJitBranch.cpp b/Source/Core/Core/DSP/Jit/DSPJitBranch.cpp index 97e0a26a35..8bb260dcf2 100644 --- a/Source/Core/Core/DSP/Jit/DSPJitBranch.cpp +++ b/Source/Core/Core/DSP/Jit/DSPJitBranch.cpp @@ -12,6 +12,12 @@ using namespace Gen; +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ template static void ReJitConditional(const UDSPInstruction opc, DSPEmitter& emitter) { @@ -452,3 +458,7 @@ void DSPEmitter::bloopi(const UDSPInstruction opc) WriteBranchExit(*this); } } + +} // namespace x86 +} // namespace JIT +} // namespace DSP diff --git a/Source/Core/Core/DSP/Jit/DSPJitCCUtil.cpp b/Source/Core/Core/DSP/Jit/DSPJitCCUtil.cpp index 3d7657a074..4a32d7a933 100644 --- a/Source/Core/Core/DSP/Jit/DSPJitCCUtil.cpp +++ b/Source/Core/Core/DSP/Jit/DSPJitCCUtil.cpp @@ -9,6 +9,12 @@ using namespace Gen; +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ // In: RAX: s64 _Value // Clobbers RDX void DSPEmitter::Update_SR_Register(Gen::X64Reg val) @@ -164,3 +170,7 @@ void DSPEmitter::Update_SR_Register16_OverS32(Gen::X64Reg val) // AND(32, R(val), Imm32(0xc0000000)); Update_SR_Register16(val); } + +} // namespace x86 +} // namespace JIT +} // namespace DSP diff --git a/Source/Core/Core/DSP/Jit/DSPJitExtOps.cpp b/Source/Core/Core/DSP/Jit/DSPJitExtOps.cpp index 1dc75e43d4..31eee39147 100644 --- a/Source/Core/Core/DSP/Jit/DSPJitExtOps.cpp +++ b/Source/Core/Core/DSP/Jit/DSPJitExtOps.cpp @@ -25,6 +25,12 @@ using namespace Gen; sign extension. */ +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ // DR $arR // xxxx xxxx 0000 01rr // Decrement addressing register $arR. @@ -691,3 +697,7 @@ void DSPEmitter::popExtValueToReg() storeIndex2 = -1; } + +} // namespace x86 +} // namespace JIT +} // namespace DSP diff --git a/Source/Core/Core/DSP/Jit/DSPJitLoadStore.cpp b/Source/Core/Core/DSP/Jit/DSPJitLoadStore.cpp index 645fdbcaa7..89ce0163c5 100644 --- a/Source/Core/Core/DSP/Jit/DSPJitLoadStore.cpp +++ b/Source/Core/Core/DSP/Jit/DSPJitLoadStore.cpp @@ -13,6 +13,12 @@ using namespace Gen; +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ // SRS @M, $(0x18+S) // 0010 1sss mmmm mmmm // Move value from register $(0x18+D) to data memory pointed by address @@ -349,3 +355,7 @@ void DSPEmitter::ilrrn(const UDSPInstruction opc) dsp_conditional_extend_accum(dreg + DSP_REG_ACM0); increase_addr_reg(reg, reg); } + +} // namespace x86 +} // namespace JIT +} // namespace DSP diff --git a/Source/Core/Core/DSP/Jit/DSPJitMisc.cpp b/Source/Core/Core/DSP/Jit/DSPJitMisc.cpp index 0b064047a2..b2b629d1d4 100644 --- a/Source/Core/Core/DSP/Jit/DSPJitMisc.cpp +++ b/Source/Core/Core/DSP/Jit/DSPJitMisc.cpp @@ -11,6 +11,12 @@ using namespace Gen; +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ // MRR $D, $S // 0001 11dd ddds ssss // Move value from register $S to register $D. @@ -191,3 +197,7 @@ void DSPEmitter::srbith(const UDSPInstruction opc) break; } } + +} // namespace x86 +} // namespace JIT +} // namespace DSP diff --git a/Source/Core/Core/DSP/Jit/DSPJitMultiplier.cpp b/Source/Core/Core/DSP/Jit/DSPJitMultiplier.cpp index 63047f6d83..5c6eb5cf7f 100644 --- a/Source/Core/Core/DSP/Jit/DSPJitMultiplier.cpp +++ b/Source/Core/Core/DSP/Jit/DSPJitMultiplier.cpp @@ -13,6 +13,12 @@ using namespace Gen; +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ // Returns s64 in RAX // In: RCX = s16 a, RAX = s16 b void DSPEmitter::multiply() @@ -770,3 +776,7 @@ void DSPEmitter::msub(const UDSPInstruction opc) // dsp_set_long_prod(prod); set_long_prod(); } + +} // namespace x86 +} // namespace JIT +} // namespace DSP diff --git a/Source/Core/Core/DSP/Jit/DSPJitRegCache.cpp b/Source/Core/Core/DSP/Jit/DSPJitRegCache.cpp index 63b91c424b..162352a063 100644 --- a/Source/Core/Core/DSP/Jit/DSPJitRegCache.cpp +++ b/Source/Core/Core/DSP/Jit/DSPJitRegCache.cpp @@ -15,6 +15,12 @@ using namespace Gen; +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ // Ordered in order of prefered use. // Not all of these are actually available const std::array DSPJitRegCache::m_allocation_order = { @@ -1008,3 +1014,7 @@ void DSPJitRegCache::PutXReg(X64Reg reg) xregs[reg].guest_reg = DSP_REG_NONE; } + +} // namespace x86 +} // namespace JIT +} // namespace DSP diff --git a/Source/Core/Core/DSP/Jit/DSPJitRegCache.h b/Source/Core/Core/DSP/Jit/DSPJitRegCache.h index 8f6e33e146..2c1e3c50b8 100644 --- a/Source/Core/Core/DSP/Jit/DSPJitRegCache.h +++ b/Source/Core/Core/DSP/Jit/DSPJitRegCache.h @@ -7,6 +7,12 @@ #include #include "Common/x64Emitter.h" +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ class DSPEmitter; enum DSPJitRegSpecial @@ -179,3 +185,7 @@ private: int use_ctr; }; + +} // namespace x86 +} // namespace JIT +} // namespace DSP diff --git a/Source/Core/Core/DSP/Jit/DSPJitUtil.cpp b/Source/Core/Core/DSP/Jit/DSPJitUtil.cpp index 9b273e619b..de953d0402 100644 --- a/Source/Core/Core/DSP/Jit/DSPJitUtil.cpp +++ b/Source/Core/Core/DSP/Jit/DSPJitUtil.cpp @@ -10,6 +10,12 @@ using namespace Gen; +namespace DSP +{ +namespace JIT +{ +namespace x86 +{ // clobbers: // EAX = (s8)g_dsp.reg_stack_ptr[stack_reg] // expects: @@ -806,3 +812,7 @@ void DSPEmitter::get_ax_h(int _reg, X64Reg axh) // return (s16)g_dsp.r[DSP_REG_AXH0 + _reg]; gpr.ReadReg(_reg + DSP_REG_AXH0, axh, SIGN); } + +} // namespace x86 +} // namespace JIT +} // namespace DSP