From a8865d21b32f50b45f48cd1f8e4d1cafc5486585 Mon Sep 17 00:00:00 2001 From: "XTra.KrazzY" Date: Mon, 29 Mar 2010 01:18:05 +0000 Subject: [PATCH] DSPLLE: Opcode LUT Cleanup ABI: Far Call --> Call (thanks to correct vcproj settings) git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5250 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/ABI.cpp | 12 ++--- Source/Core/DSPCore/Src/DSPMemoryMap.h | 5 ++ Source/Core/DSPCore/Src/DSPTables.cpp | 38 ++++----------- Source/Core/DSPCore/Src/DSPTables.h | 46 +++++-------------- Source/Core/DSPCore/Src/DspIntBranch.cpp | 6 +-- .../Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj | 26 ++++++++--- 6 files changed, 54 insertions(+), 79 deletions(-) diff --git a/Source/Core/Common/Src/ABI.cpp b/Source/Core/Common/Src/ABI.cpp index b6857d79c2..6efe455f5b 100644 --- a/Source/Core/Common/Src/ABI.cpp +++ b/Source/Core/Common/Src/ABI.cpp @@ -190,17 +190,17 @@ void XEmitter::ABI_RestoreStack(unsigned int frameSize) { // Common functions void XEmitter::ABI_CallFunction(void *func) { // Far call - MOV(64, R(RAX), Imm64((u64)func)); - CALLptr(R(RAX)); - //CALL(func); + //MOV(64, R(RAX), Imm64((u64)func)); + //CALLptr(R(RAX)); + CALL(func); } void XEmitter::ABI_CallFunctionC16(void *func, u16 param1) { MOV(32, R(ABI_PARAM1), Imm32((u32)param1)); // Far call - MOV(64, R(RAX), Imm64((u64)func)); - CALLptr(R(RAX)); - //CALL(func); + //MOV(64, R(RAX), Imm64((u64)func)); + //CALLptr(R(RAX)); + CALL(func); } void XEmitter::ABI_CallFunctionC(void *func, u32 param1) { diff --git a/Source/Core/DSPCore/Src/DSPMemoryMap.h b/Source/Core/DSPCore/Src/DSPMemoryMap.h index 5e7d168678..8a8afa05f0 100644 --- a/Source/Core/DSPCore/Src/DSPMemoryMap.h +++ b/Source/Core/DSPCore/Src/DSPMemoryMap.h @@ -46,4 +46,9 @@ inline u16 dsp_peek_code() return dsp_imem_read(g_dsp.pc); } +inline void dsp_skip_inst() +{ + g_dsp.pc += opTable[dsp_peek_code()]->size; +} + #endif diff --git a/Source/Core/DSPCore/Src/DSPTables.cpp b/Source/Core/DSPCore/Src/DSPTables.cpp index cc67c717ba..2cdf0406d2 100644 --- a/Source/Core/DSPCore/Src/DSPTables.cpp +++ b/Source/Core/DSPCore/Src/DSPTables.cpp @@ -39,7 +39,7 @@ const DSPOPCTemplate opcodes[] = {"SUBARN", 0x000c, 0xfffc, DSPInterpreter::subarn, nop, 1, 1, {{P_REG, 1, 0, 0, 0x0003}}, false, false}, {"ADDARN", 0x0010, 0xfff0, DSPInterpreter::addarn, nop, 1, 2, {{P_REG, 1, 0, 0, 0x0003}, {P_REG04, 1, 0, 2, 0x000c}}, false, false}, - {"HALT", 0x0021, 0xffff, DSPInterpreter::halt, nop, 1, 0, {}, false, false}, + {"HALT", 0x0021, 0xffff, DSPInterpreter::halt, nop, 1, 0, {}, false, true}, {"RETGE", 0x02d0, 0xffff, DSPInterpreter::ret, nop, 1, 0, {}, false, true}, {"RETL", 0x02d1, 0xffff, DSPInterpreter::ret, nop, 1, 0, {}, false, true}, @@ -485,10 +485,8 @@ const pdlabel_t regnames[] = {0x23, "AX1", "Extra Accu 1",}, }; -u8 opSize[OPTABLE_SIZE]; -dspInstFunc opTable[OPTABLE_SIZE]; -dspInstFunc extOpTable[EXT_OPTABLE_SIZE]; -bool opTableUseExt[OPTABLE_SIZE]; +const DSPOPCTemplate *opTable[OPTABLE_SIZE]; +const DSPOPCTemplate *extOpTable[EXT_OPTABLE_SIZE]; u16 writeBackLog[WRITEBACKLOGSIZE]; int writeBackLogIdx[WRITEBACKLOGSIZE]; @@ -518,13 +516,7 @@ const char *pdregnamelong(int val) const DSPOPCTemplate *GetOpTemplate(const UDSPInstruction &inst) { - for (int i = 0; i < opcodes_size; i++) - { - u16 mask = opcodes[i].opcode_mask; - if ((mask & inst) == opcodes[i].opcode) - return &opcodes[i]; - } - return NULL; + return opTable[inst]; } @@ -534,7 +526,7 @@ void InitInstructionTable() { // ext op table for (int i = 0; i < EXT_OPTABLE_SIZE; i++) - extOpTable[i] = DSPInterpreter::unknown; + extOpTable[i] = &cw; for (int i = 0; i < EXT_OPTABLE_SIZE; i++) { @@ -543,8 +535,8 @@ void InitInstructionTable() u16 mask = opcodes_ext[j].opcode_mask; if ((mask & i) == opcodes_ext[j].opcode) { - if (extOpTable[i] == DSPInterpreter::unknown) - extOpTable[i] = opcodes_ext[j].interpFunc; + if (extOpTable[i] == &cw) + extOpTable[i] = &opcodes_ext[j]; else ERROR_LOG(DSPLLE, "opcode ext table place %d already in use for %s", i, opcodes_ext[j].name); } @@ -553,11 +545,7 @@ void InitInstructionTable() // op table for (int i = 0; i < OPTABLE_SIZE; i++) - { - opTable[i] = DSPInterpreter::unknown; - opTableUseExt[i] = false; - opSize[i] = 0; - } + opTable[i] = &cw; for (int i = 0; i < OPTABLE_SIZE; i++) { @@ -566,16 +554,10 @@ void InitInstructionTable() u16 mask = opcodes[j].opcode_mask; if ((mask & i) == opcodes[j].opcode) { - if (opTable[i] == DSPInterpreter::unknown) - { - opTable[i] = opcodes[j].interpFunc; - opSize[i] = opcodes[j].size & 3; - opTableUseExt[i] = opcodes[j].extended; - } + if (opTable[i] == &cw) + opTable[i] = &opcodes[j]; else - { ERROR_LOG(DSPLLE, "opcode table place %d already in use for %s", i, opcodes[j].name); - } } } } diff --git a/Source/Core/DSPCore/Src/DSPTables.h b/Source/Core/DSPCore/Src/DSPTables.h index 89984b6d88..13dcd5f03f 100644 --- a/Source/Core/DSPCore/Src/DSPTables.h +++ b/Source/Core/DSPCore/Src/DSPTables.h @@ -68,28 +68,6 @@ enum partype_t #define EXT_OPTABLE_SIZE 0xff + 1 typedef u16 UDSPInstruction; -/*/union UDSPInstruction -{ - u16 hex; - - UDSPInstruction(u16 _hex) { hex = _hex; } - UDSPInstruction() { hex = 0; } - - struct - { - signed shift : 6; - unsigned negating : 1; - unsigned arithmetic : 1; - unsigned areg : 1; - unsigned op : 7; - }; - struct - { - unsigned ushift : 6; - }; - - // TODO: Figure out more instruction structures (add structs here) - };*/ typedef void (*dspInstFunc)(const UDSPInstruction); @@ -125,14 +103,12 @@ extern const DSPOPCTemplate opcodes[]; extern const int opcodes_size; extern const DSPOPCTemplate opcodes_ext[]; extern const int opcodes_ext_size; -extern u8 opSize[OPTABLE_SIZE]; extern const DSPOPCTemplate cw; #define WRITEBACKLOGSIZE 7 -extern dspInstFunc opTable[]; -extern bool opTableUseExt[OPTABLE_SIZE]; -extern dspInstFunc extOpTable[EXT_OPTABLE_SIZE]; +extern const DSPOPCTemplate *opTable[OPTABLE_SIZE]; +extern const DSPOPCTemplate *extOpTable[EXT_OPTABLE_SIZE]; extern u16 writeBackLog[WRITEBACKLOGSIZE]; extern int writeBackLogIdx[WRITEBACKLOGSIZE]; @@ -157,22 +133,22 @@ void applyWriteBackLog(); void zeroWriteBackLog(); void zeroWriteBackLogPreserveAcc(u8 acc); +const DSPOPCTemplate *GetOpTemplate(const UDSPInstruction &inst); + inline void ExecuteInstruction(const UDSPInstruction inst) { - if (opTableUseExt[inst]) { + const DSPOPCTemplate *tinst = GetOpTemplate(inst); + + if (tinst->extended) { if ((inst >> 12) == 0x3) - extOpTable[inst & 0x7F](inst); + extOpTable[inst & 0x7F]->interpFunc(inst); else - extOpTable[inst & 0xFF](inst); + extOpTable[inst & 0xFF]->interpFunc(inst); } - opTable[inst](inst); - if (opTableUseExt[inst]) { + tinst->interpFunc(inst); + if (tinst->extended) { applyWriteBackLog(); } } -// This one's pretty slow, try to use it only at init or seldomly. -// returns NULL if no matching instruction. -const DSPOPCTemplate *GetOpTemplate(const UDSPInstruction &inst); - #endif // _DSPTABLES_H diff --git a/Source/Core/DSPCore/Src/DspIntBranch.cpp b/Source/Core/DSPCore/Src/DspIntBranch.cpp index 618c51d022..bece4f78e4 100644 --- a/Source/Core/DSPCore/Src/DspIntBranch.cpp +++ b/Source/Core/DSPCore/Src/DspIntBranch.cpp @@ -71,7 +71,7 @@ void ifcc(const UDSPInstruction opc) if (!CheckCondition(opc & 0xf)) { // skip the next opcode - we have to lookup its size. - g_dsp.pc += opSize[dsp_peek_code()]; + dsp_skip_inst(); } } @@ -242,7 +242,7 @@ void bloop(const UDSPInstruction opc) else { g_dsp.pc = loop_pc; - g_dsp.pc += opSize[dsp_peek_code()]; + dsp_skip_inst(); } } @@ -269,7 +269,7 @@ void bloopi(const UDSPInstruction opc) else { g_dsp.pc = loop_pc; - g_dsp.pc += opSize[dsp_peek_code()]; + dsp_skip_inst(); } } diff --git a/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj b/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj index 722629f528..bb62d19646 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj +++ b/Source/Plugins/Plugin_DSP_LLE/Plugin_DSP_LLE.vcproj @@ -76,8 +76,10 @@ GenerateDebugInformation="true" ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb" SubSystem="2" + BaseAddress="0x00b00000" RandomizedBaseAddress="1" - DataExecutionPrevention="0" + FixedBaseAddress="1" + DataExecutionPrevention="2" ImportLibrary="$(PlatformName)\$(ConfigurationName)\$(TargetName).lib" TargetMachine="1" /> @@ -164,8 +166,10 @@ AssemblyDebug="1" ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb" SubSystem="2" + BaseAddress="0x00b00000" RandomizedBaseAddress="1" - DataExecutionPrevention="0" + FixedBaseAddress="1" + DataExecutionPrevention="2" ImportLibrary="$(PlatformName)\$(ConfigurationName)\$(TargetName).lib" TargetMachine="17" /> @@ -254,8 +258,10 @@ SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" + BaseAddress="0x00b00000" RandomizedBaseAddress="1" - DataExecutionPrevention="0" + FixedBaseAddress="1" + DataExecutionPrevention="2" ImportLibrary="$(PlatformName)\$(ConfigurationName)\$(TargetName).lib" TargetMachine="1" /> @@ -310,7 +316,7 @@ @@ -435,8 +443,10 @@ SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" + BaseAddress="0x00b00000" RandomizedBaseAddress="1" - DataExecutionPrevention="0" + FixedBaseAddress="1" + DataExecutionPrevention="2" ImportLibrary="$(PlatformName)\$(ConfigurationName)\$(TargetName).lib" TargetMachine="1" /> @@ -526,8 +536,10 @@ SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" + BaseAddress="0x00b00000" RandomizedBaseAddress="1" - DataExecutionPrevention="0" + FixedBaseAddress="1" + DataExecutionPrevention="2" ImportLibrary="$(PlatformName)\$(ConfigurationName)\$(TargetName).lib" TargetMachine="17" />