DSP: Namespace the JIT

This commit is contained in:
Lioncash 2016-12-28 18:45:12 -05:00
parent 10b4f6a250
commit c79cc3f470
16 changed files with 137 additions and 10 deletions

View File

@ -29,7 +29,7 @@ DSPBreakpoints g_dsp_breakpoints;
static DSPCoreState core_state = DSPCORE_STOP; static DSPCoreState core_state = DSPCORE_STOP;
u16 g_cycles_left = 0; u16 g_cycles_left = 0;
bool g_init_hax = false; bool g_init_hax = false;
std::unique_ptr<DSPEmitter> g_dsp_jit; std::unique_ptr<DSP::JIT::x86::DSPEmitter> g_dsp_jit;
std::unique_ptr<DSPCaptureLogger> g_dsp_cap; std::unique_ptr<DSPCaptureLogger> g_dsp_cap;
static Common::Event step_event; static Common::Event step_event;
@ -148,7 +148,7 @@ bool DSPCore_Init(const DSPInitOptions& opts)
// Initialize JIT, if necessary // Initialize JIT, if necessary
if (opts.core_type == DSPInitOptions::CORE_JIT) if (opts.core_type == DSPInitOptions::CORE_JIT)
g_dsp_jit = std::make_unique<DSPEmitter>(); g_dsp_jit = std::make_unique<DSP::JIT::x86::DSPEmitter>();
g_dsp_cap.reset(opts.capture_logger); g_dsp_cap.reset(opts.capture_logger);
@ -251,7 +251,7 @@ int DSPCore_RunCycles(int cycles)
} }
g_cycles_left = 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(); exec_addr();
if (g_dsp.reset_dspjit_codespace) if (g_dsp.reset_dspjit_codespace)

View File

@ -14,7 +14,16 @@
#include "Core/DSP/DSPBreakpoints.h" #include "Core/DSP/DSPBreakpoints.h"
#include "Core/DSP/DSPCaptureLogger.h" #include "Core/DSP/DSPCaptureLogger.h"
namespace DSP
{
namespace JIT
{
namespace x86
{
class DSPEmitter; class DSPEmitter;
}
}
}
enum : u32 enum : u32
{ {
@ -302,7 +311,7 @@ extern SDSP g_dsp;
extern DSPBreakpoints g_dsp_breakpoints; extern DSPBreakpoints g_dsp_breakpoints;
extern u16 g_cycles_left; extern u16 g_cycles_left;
extern bool g_init_hax; extern bool g_init_hax;
extern std::unique_ptr<DSPEmitter> g_dsp_jit; extern std::unique_ptr<DSP::JIT::x86::DSPEmitter> g_dsp_jit;
extern std::unique_ptr<DSPCaptureLogger> g_dsp_cap; extern std::unique_ptr<DSPCaptureLogger> g_dsp_cap;
struct DSPInitOptions struct DSPInitOptions

View File

@ -12,6 +12,8 @@
#include "Core/DSP/Interpreter/DSPInterpreter.h" #include "Core/DSP/Interpreter/DSPInterpreter.h"
#include "Core/DSP/Jit/DSPEmitter.h" #include "Core/DSP/Jit/DSPEmitter.h"
using DSP::JIT::x86::DSPEmitter;
// clang-format off // clang-format off
const DSPOPCTemplate opcodes[] = const DSPOPCTemplate opcodes[] =
{ {

View File

@ -66,7 +66,7 @@ struct param2_t
struct DSPOPCTemplate struct DSPOPCTemplate
{ {
using InterpreterFunction = void (*)(UDSPInstruction); using InterpreterFunction = void (*)(UDSPInstruction);
using JITFunction = void (DSPEmitter::*)(UDSPInstruction); using JITFunction = void (DSP::JIT::x86::DSPEmitter::*)(UDSPInstruction);
const char* name; const char* name;
u16 opcode; u16 opcode;

View File

@ -18,12 +18,18 @@
#include "Core/DSP/DSPMemoryMap.h" #include "Core/DSP/DSPMemoryMap.h"
#include "Core/DSP/DSPTables.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 COMPILED_CODE_SIZE = 2097152;
constexpr size_t MAX_BLOCK_SIZE = 250; constexpr size_t MAX_BLOCK_SIZE = 250;
constexpr u16 DSP_IDLE_SKIP_CYCLES = 0x1000; constexpr u16 DSP_IDLE_SKIP_CYCLES = 0x1000;
using namespace Gen;
DSPEmitter::DSPEmitter() DSPEmitter::DSPEmitter()
: blockLinks(MAX_BLOCKS), blockSize(MAX_BLOCKS), blocks(MAX_BLOCKS), : blockLinks(MAX_BLOCKS), blockSize(MAX_BLOCKS), blocks(MAX_BLOCKS),
compileSR{SR_INT_ENABLE | SR_EXT_INT_ENABLE} compileSR{SR_INT_ENABLE | SR_EXT_INT_ENABLE}
@ -415,3 +421,7 @@ void DSPEmitter::CompileDispatcher()
ABI_PopRegistersAndAdjustStack(registers_used, 8); ABI_PopRegistersAndAdjustStack(registers_used, 8);
RET(); RET();
} }
} // namespace x86
} // namespace JIT
} // namespace DSP

View File

@ -15,6 +15,12 @@
#include "Core/DSP/DSPCommon.h" #include "Core/DSP/DSPCommon.h"
#include "Core/DSP/Jit/DSPJitRegCache.h" #include "Core/DSP/Jit/DSPJitRegCache.h"
namespace DSP
{
namespace JIT
{
namespace x86
{
class DSPEmitter : public Gen::X64CodeBlock class DSPEmitter : public Gen::X64CodeBlock
{ {
public: public:
@ -281,3 +287,7 @@ private:
void get_ax_h(int _reg, Gen::X64Reg acc = Gen::EAX); void get_ax_h(int _reg, Gen::X64Reg acc = Gen::EAX);
void get_long_acc(int _reg, Gen::X64Reg acc = Gen::EAX); void get_long_acc(int _reg, Gen::X64Reg acc = Gen::EAX);
}; };
} // namespace x86
} // namespace JIT
} // namespace DSP

View File

@ -12,6 +12,12 @@
using namespace Gen; using namespace Gen;
namespace DSP
{
namespace JIT
{
namespace x86
{
// CLR $acR // CLR $acR
// 1000 r001 xxxx xxxx // 1000 r001 xxxx xxxx
// Clears accumulator $acR // Clears accumulator $acR
@ -1672,6 +1678,6 @@ void DSPEmitter::asrnr(const UDSPInstruction opc)
} }
} }
//} // namespace } // namespace x86
} // namespace JIT
// } // namespace DSP

View File

@ -12,6 +12,12 @@
using namespace Gen; using namespace Gen;
namespace DSP
{
namespace JIT
{
namespace x86
{
template <void (*jitCode)(const UDSPInstruction, DSPEmitter&)> template <void (*jitCode)(const UDSPInstruction, DSPEmitter&)>
static void ReJitConditional(const UDSPInstruction opc, DSPEmitter& emitter) static void ReJitConditional(const UDSPInstruction opc, DSPEmitter& emitter)
{ {
@ -452,3 +458,7 @@ void DSPEmitter::bloopi(const UDSPInstruction opc)
WriteBranchExit(*this); WriteBranchExit(*this);
} }
} }
} // namespace x86
} // namespace JIT
} // namespace DSP

View File

@ -9,6 +9,12 @@
using namespace Gen; using namespace Gen;
namespace DSP
{
namespace JIT
{
namespace x86
{
// In: RAX: s64 _Value // In: RAX: s64 _Value
// Clobbers RDX // Clobbers RDX
void DSPEmitter::Update_SR_Register(Gen::X64Reg val) 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)); // AND(32, R(val), Imm32(0xc0000000));
Update_SR_Register16(val); Update_SR_Register16(val);
} }
} // namespace x86
} // namespace JIT
} // namespace DSP

View File

@ -25,6 +25,12 @@ using namespace Gen;
sign extension. sign extension.
*/ */
namespace DSP
{
namespace JIT
{
namespace x86
{
// DR $arR // DR $arR
// xxxx xxxx 0000 01rr // xxxx xxxx 0000 01rr
// Decrement addressing register $arR. // Decrement addressing register $arR.
@ -691,3 +697,7 @@ void DSPEmitter::popExtValueToReg()
storeIndex2 = -1; storeIndex2 = -1;
} }
} // namespace x86
} // namespace JIT
} // namespace DSP

View File

@ -13,6 +13,12 @@
using namespace Gen; using namespace Gen;
namespace DSP
{
namespace JIT
{
namespace x86
{
// SRS @M, $(0x18+S) // SRS @M, $(0x18+S)
// 0010 1sss mmmm mmmm // 0010 1sss mmmm mmmm
// Move value from register $(0x18+D) to data memory pointed by address // 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); dsp_conditional_extend_accum(dreg + DSP_REG_ACM0);
increase_addr_reg(reg, reg); increase_addr_reg(reg, reg);
} }
} // namespace x86
} // namespace JIT
} // namespace DSP

View File

@ -11,6 +11,12 @@
using namespace Gen; using namespace Gen;
namespace DSP
{
namespace JIT
{
namespace x86
{
// MRR $D, $S // MRR $D, $S
// 0001 11dd ddds ssss // 0001 11dd ddds ssss
// Move value from register $S to register $D. // Move value from register $S to register $D.
@ -191,3 +197,7 @@ void DSPEmitter::srbith(const UDSPInstruction opc)
break; break;
} }
} }
} // namespace x86
} // namespace JIT
} // namespace DSP

View File

@ -13,6 +13,12 @@
using namespace Gen; using namespace Gen;
namespace DSP
{
namespace JIT
{
namespace x86
{
// Returns s64 in RAX // Returns s64 in RAX
// In: RCX = s16 a, RAX = s16 b // In: RCX = s16 a, RAX = s16 b
void DSPEmitter::multiply() void DSPEmitter::multiply()
@ -770,3 +776,7 @@ void DSPEmitter::msub(const UDSPInstruction opc)
// dsp_set_long_prod(prod); // dsp_set_long_prod(prod);
set_long_prod(); set_long_prod();
} }
} // namespace x86
} // namespace JIT
} // namespace DSP

View File

@ -15,6 +15,12 @@
using namespace Gen; using namespace Gen;
namespace DSP
{
namespace JIT
{
namespace x86
{
// Ordered in order of prefered use. // Ordered in order of prefered use.
// Not all of these are actually available // Not all of these are actually available
const std::array<X64Reg, 15> DSPJitRegCache::m_allocation_order = { const std::array<X64Reg, 15> DSPJitRegCache::m_allocation_order = {
@ -1008,3 +1014,7 @@ void DSPJitRegCache::PutXReg(X64Reg reg)
xregs[reg].guest_reg = DSP_REG_NONE; xregs[reg].guest_reg = DSP_REG_NONE;
} }
} // namespace x86
} // namespace JIT
} // namespace DSP

View File

@ -7,6 +7,12 @@
#include <array> #include <array>
#include "Common/x64Emitter.h" #include "Common/x64Emitter.h"
namespace DSP
{
namespace JIT
{
namespace x86
{
class DSPEmitter; class DSPEmitter;
enum DSPJitRegSpecial enum DSPJitRegSpecial
@ -179,3 +185,7 @@ private:
int use_ctr; int use_ctr;
}; };
} // namespace x86
} // namespace JIT
} // namespace DSP

View File

@ -10,6 +10,12 @@
using namespace Gen; using namespace Gen;
namespace DSP
{
namespace JIT
{
namespace x86
{
// clobbers: // clobbers:
// EAX = (s8)g_dsp.reg_stack_ptr[stack_reg] // EAX = (s8)g_dsp.reg_stack_ptr[stack_reg]
// expects: // expects:
@ -806,3 +812,7 @@ void DSPEmitter::get_ax_h(int _reg, X64Reg axh)
// return (s16)g_dsp.r[DSP_REG_AXH0 + _reg]; // return (s16)g_dsp.r[DSP_REG_AXH0 + _reg];
gpr.ReadReg(_reg + DSP_REG_AXH0, axh, SIGN); gpr.ReadReg(_reg + DSP_REG_AXH0, axh, SIGN);
} }
} // namespace x86
} // namespace JIT
} // namespace DSP