Skip to content

Commit

Permalink
Merge pull request #4579 from lioncash/namespace
Browse files Browse the repository at this point in the history
DSP: Namespace the interpreter and JIT
  • Loading branch information
degasus committed Dec 29, 2016
2 parents 10b4f6a + 2aefa29 commit 15759c4
Show file tree
Hide file tree
Showing 30 changed files with 476 additions and 308 deletions.
16 changes: 8 additions & 8 deletions Source/Core/Core/DSP/DSPCore.cpp
Expand Up @@ -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<DSPEmitter> g_dsp_jit;
std::unique_ptr<DSP::JIT::x86::DSPEmitter> g_dsp_jit;
std::unique_ptr<DSPCaptureLogger> g_dsp_cap;
static Common::Event step_event;

Expand Down Expand Up @@ -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<DSPEmitter>();
g_dsp_jit = std::make_unique<DSP::JIT::x86::DSPEmitter>();

g_dsp_cap.reset(opts.capture_logger);

Expand Down Expand Up @@ -193,7 +193,7 @@ void DSPCore_SetExternalInterrupt(bool val)
// Coming from the CPU
void DSPCore_CheckExternalInterrupt()
{
if (!dsp_SR_is_flag_set(SR_EXT_INT_ENABLE))
if (!DSP::Interpreter::dsp_SR_is_flag_set(SR_EXT_INT_ENABLE))
return;

// Signal the SPU about new mail
Expand All @@ -213,7 +213,7 @@ void DSPCore_CheckExceptions()
// Seems exp int are not masked by sr_int_enable
if (g_dsp.exceptions & (1 << i))
{
if (dsp_SR_is_flag_set(SR_INT_ENABLE) || (i == EXP_INT))
if (DSP::Interpreter::dsp_SR_is_flag_set(SR_INT_ENABLE) || (i == EXP_INT))
{
// store pc and sr until RTI
dsp_reg_store_stack(DSP_STACK_C, g_dsp.pc);
Expand Down Expand Up @@ -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)
Expand All @@ -267,9 +267,9 @@ int DSPCore_RunCycles(int cycles)
case DSPCORE_RUNNING:
// Seems to slow things down
#if defined(_DEBUG) || defined(DEBUGFAST)
cycles = DSPInterpreter::RunCyclesDebug(cycles);
cycles = DSP::Interpreter::RunCyclesDebug(cycles);
#else
cycles = DSPInterpreter::RunCycles(cycles);
cycles = DSP::Interpreter::RunCycles(cycles);
#endif
break;

Expand All @@ -278,7 +278,7 @@ int DSPCore_RunCycles(int cycles)
if (core_state != DSPCORE_STEPPING)
continue;

DSPInterpreter::Step();
DSP::Interpreter::Step();
cycles--;

DSPHost::UpdateDebugger();
Expand Down
11 changes: 10 additions & 1 deletion Source/Core/Core/DSP/DSPCore.h
Expand Up @@ -14,7 +14,16 @@
#include "Core/DSP/DSPBreakpoints.h"
#include "Core/DSP/DSPCaptureLogger.h"

namespace DSP
{
namespace JIT
{
namespace x86
{
class DSPEmitter;
}
}
}

enum : u32
{
Expand Down Expand Up @@ -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<DSPEmitter> g_dsp_jit;
extern std::unique_ptr<DSP::JIT::x86::DSPEmitter> g_dsp_jit;
extern std::unique_ptr<DSPCaptureLogger> g_dsp_cap;

struct DSPInitOptions
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/DSP/DSPDisassembler.cpp
Expand Up @@ -194,7 +194,7 @@ bool DSPDisassembler::DisassembleOpcode(const u16* binbuf, int base_addr, int pa
break;
}
}
const DSPOPCTemplate fake_op = {"CW", 0x0000, 0x0000, DSPInterpreter::nop,
const DSPOPCTemplate fake_op = {"CW", 0x0000, 0x0000, DSP::Interpreter::nop,
nullptr, 1, 1, {{P_VAL, 2, 0, 0, 0xffff}},
false, false, false, false,
false};
Expand Down
520 changes: 261 additions & 259 deletions Source/Core/Core/DSP/DSPTables.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Source/Core/Core/DSP/DSPTables.h
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions Source/Core/Core/DSP/Interpreter/DSPIntArithmetic.cpp
Expand Up @@ -12,7 +12,9 @@

// Arithmetic and accumulator control.

namespace DSPInterpreter
namespace DSP
{
namespace Interpreter
{
// CLR $acR
// 1000 r001 xxxx xxxx
Expand Down Expand Up @@ -1158,4 +1160,5 @@ void asrnr(const UDSPInstruction opc)
Update_SR_Register64(dsp_get_long_acc(dreg));
}

} // namespace
} // namespace Interpreter
} // namespace DSP
7 changes: 5 additions & 2 deletions Source/Core/Core/DSP/Interpreter/DSPIntBranch.cpp
Expand Up @@ -11,7 +11,9 @@
#include "Core/DSP/Interpreter/DSPIntUtil.h"
#include "Core/DSP/Interpreter/DSPInterpreter.h"

namespace DSPInterpreter
namespace DSP
{
namespace Interpreter
{
// Generic call implementation
// CALLcc addressA
Expand Down Expand Up @@ -262,4 +264,5 @@ void bloopi(const UDSPInstruction opc)
}
}

} // namespace
} // namespace Interpreter
} // namespace DSP
7 changes: 5 additions & 2 deletions Source/Core/Core/DSP/Interpreter/DSPIntCCUtil.cpp
Expand Up @@ -9,7 +9,9 @@
#include "Core/DSP/Interpreter/DSPIntCCUtil.h"
#include "Core/DSP/DSPCore.h"

namespace DSPInterpreter
namespace DSP
{
namespace Interpreter
{
void Update_SR_Register64(s64 _Value, bool carry, bool overflow)
{
Expand Down Expand Up @@ -181,4 +183,5 @@ bool CheckCondition(u8 _Condition)
}
}

} // namespace
} // namespace Interpreter
} // namespace DSP
7 changes: 5 additions & 2 deletions Source/Core/Core/DSP/Interpreter/DSPIntCCUtil.h
Expand Up @@ -10,7 +10,9 @@

#include "Common/CommonTypes.h"

namespace DSPInterpreter
namespace DSP
{
namespace Interpreter
{
bool CheckCondition(u8 _Condition);

Expand Down Expand Up @@ -39,4 +41,5 @@ inline bool isOverS32(s64 acc)
return (acc != (s32)acc) ? true : false;
}

} // namespace
} // namespace Interpreter
} // namespace DSP
20 changes: 12 additions & 8 deletions Source/Core/Core/DSP/Interpreter/DSPIntExtOps.cpp
Expand Up @@ -29,7 +29,9 @@ inline static void writeToBackLog(int i, int idx, u16 value)
writeBackLogIdx[i] = idx;
}

namespace DSPInterpreter
namespace DSP
{
namespace Interpreter
{
namespace Ext
{
Expand Down Expand Up @@ -496,8 +498,9 @@ void nop(const UDSPInstruction opc)
{
}

} // end namespace ext
} // end namespace DSPInterpeter
} // namespace Ext
} // namespace Interpeter
} // namespace DSP

// The ext ops are calculated in parallel with the actual op. That means that
// both the main op and the ext op see the same register state as input. The
Expand All @@ -513,11 +516,12 @@ void applyWriteBackLog()
// infinitive loops
for (int i = 0; writeBackLogIdx[i] != -1; i++)
{
u16 value = writeBackLog[i];
#ifdef PRECISE_BACKLOG
dsp_op_write_reg(writeBackLogIdx[i], dsp_op_read_reg(writeBackLogIdx[i]) | writeBackLog[i]);
#else
dsp_op_write_reg(writeBackLogIdx[i], writeBackLog[i]);
value |= DSP::Interpreter::dsp_op_read_reg(writeBackLogIdx[i]);
#endif
DSP::Interpreter::dsp_op_write_reg(writeBackLogIdx[i], value);

// Clear back log
writeBackLogIdx[i] = -1;
}
Expand All @@ -537,7 +541,7 @@ void zeroWriteBackLog()
// infinitive loops
for (int i = 0; writeBackLogIdx[i] != -1; i++)
{
dsp_op_write_reg(writeBackLogIdx[i], 0);
DSP::Interpreter::dsp_op_write_reg(writeBackLogIdx[i], 0);
}
#endif
}
Expand All @@ -559,7 +563,7 @@ void zeroWriteBackLogPreserveAcc(u8 acc)
(writeBackLogIdx[i] == DSP_REG_ACH1)))
continue;

dsp_op_write_reg(writeBackLogIdx[i], 0);
DSP::Interpreter::dsp_op_write_reg(writeBackLogIdx[i], 0);
}
#endif
}
9 changes: 6 additions & 3 deletions Source/Core/Core/DSP/Interpreter/DSPIntExtOps.h
Expand Up @@ -11,7 +11,9 @@
// Many opcode have the lower 0xFF (some only 0x7f) free - there, an opcode extension
// can be stored.

namespace DSPInterpreter
namespace DSP
{
namespace Interpreter
{
namespace Ext
{
Expand Down Expand Up @@ -41,5 +43,6 @@ void ir(const UDSPInstruction opc);
void nr(const UDSPInstruction opc);
void nop(const UDSPInstruction opc);

} // end namespace Ext
} // end namespace DSPinterpeter
} // namespace Ext
} // namespace Interpeter
} // namespace DSP
7 changes: 5 additions & 2 deletions Source/Core/Core/DSP/Interpreter/DSPIntLoadStore.cpp
Expand Up @@ -8,7 +8,9 @@
#include "Core/DSP/Interpreter/DSPIntUtil.h"
#include "Core/DSP/Interpreter/DSPInterpreter.h"

namespace DSPInterpreter
namespace DSP
{
namespace Interpreter
{
// SRS @M, $(0x18+S)
// 0010 1sss mmmm mmmm
Expand Down Expand Up @@ -260,4 +262,5 @@ void ilrrn(const UDSPInstruction opc)
g_dsp.r.ar[reg] = dsp_increase_addr_reg(reg, (s16)g_dsp.r.ix[reg]);
}

} // namespace
} // namespace Interpreter
} // namespace DSP
7 changes: 5 additions & 2 deletions Source/Core/Core/DSP/Interpreter/DSPIntMisc.cpp
Expand Up @@ -10,7 +10,9 @@
#include "Core/DSP/Interpreter/DSPIntUtil.h"
#include "Core/DSP/Interpreter/DSPInterpreter.h"

namespace DSPInterpreter
namespace DSP
{
namespace Interpreter
{
// MRR $D, $S
// 0001 11dd ddds ssss
Expand Down Expand Up @@ -158,4 +160,5 @@ void srbith(const UDSPInstruction opc)
}
}

} // namespace
} // namespace Interpreter
} // namespace DSP
7 changes: 5 additions & 2 deletions Source/Core/Core/DSP/Interpreter/DSPIntMultiplier.cpp
Expand Up @@ -11,7 +11,9 @@
#include "Core/DSP/Interpreter/DSPIntUtil.h"
#include "Core/DSP/Interpreter/DSPInterpreter.h"

namespace DSPInterpreter
namespace DSP
{
namespace Interpreter
{
// Only MULX family instructions have unsigned/mixed support.
inline s64 dsp_get_multiply_prod(u16 a, u16 b, u8 sign)
Expand Down Expand Up @@ -592,4 +594,5 @@ void msub(const UDSPInstruction opc)
dsp_set_long_prod(prod);
}

} // namespace
} // namespace Interpreter
} // namespace DSP
7 changes: 7 additions & 0 deletions Source/Core/Core/DSP/Interpreter/DSPIntUtil.h
Expand Up @@ -11,6 +11,10 @@
#include "Core/DSP/DSPCore.h"
#include "Core/DSP/DSPStacks.h"

namespace DSP
{
namespace Interpreter
{
// ---------------------------------------------------------------------------------------
// --- SR
// ---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -375,3 +379,6 @@ inline s16 dsp_get_ax_h(int _reg)
{
return (s16)g_dsp.r.ax[_reg].h;
}

} // namespace Interpreter
} // namespace DSP
7 changes: 5 additions & 2 deletions Source/Core/Core/DSP/Interpreter/DSPInterpreter.cpp
Expand Up @@ -13,7 +13,9 @@
#include "Core/DSP/DSPMemoryMap.h"
#include "Core/DSP/DSPTables.h"

namespace DSPInterpreter
namespace DSP
{
namespace Interpreter
{
namespace
{
Expand Down Expand Up @@ -238,4 +240,5 @@ void nop(const UDSPInstruction opc)
ERROR_LOG(DSPLLE, "LLE: Unrecognized opcode 0x%04x", opc);
}

} // namespace
} // namespace Interpreter
} // namespace DSP
7 changes: 5 additions & 2 deletions Source/Core/Core/DSP/Interpreter/DSPInterpreter.h
Expand Up @@ -8,7 +8,9 @@

#define DSP_REG_MASK 0x1f

namespace DSPInterpreter
namespace DSP
{
namespace Interpreter
{
void Step();

Expand Down Expand Up @@ -146,4 +148,5 @@ void xorc(const UDSPInstruction opc);
void xori(const UDSPInstruction opc);
void xorr(const UDSPInstruction opc);

} // namespace
} // namespace Interpreter
} // namespace DSP
14 changes: 12 additions & 2 deletions Source/Core/Core/DSP/Jit/DSPEmitter.cpp
Expand Up @@ -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}
Expand Down Expand Up @@ -415,3 +421,7 @@ void DSPEmitter::CompileDispatcher()
ABI_PopRegistersAndAdjustStack(registers_used, 8);
RET();
}

} // namespace x86
} // namespace JIT
} // namespace DSP

0 comments on commit 15759c4

Please sign in to comment.