From fd1ad02c5c5517b853d783146e746719203c6156 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 21 Jun 2018 13:06:39 -0400 Subject: [PATCH] DSPTables: Deduplicate FindByOpcode() implementations in DSP opcode tables This function was duplicated across all the opcode tables: the main info tables, the interpreter tables, and the x86-64 JIT tables. However, we can just make the type of the std::array parameter a template type and get rid of this duplication. --- Source/Core/Core/DSP/DSPTables.cpp | 8 -------- Source/Core/Core/DSP/DSPTables.h | 9 +++++++++ Source/Core/Core/DSP/Interpreter/DSPIntTables.cpp | 11 ++--------- Source/Core/Core/DSP/Jit/x64/DSPJitTables.cpp | 11 ++--------- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/Source/Core/Core/DSP/DSPTables.cpp b/Source/Core/Core/DSP/DSPTables.cpp index 8415bade51..8672082c84 100644 --- a/Source/Core/Core/DSP/DSPTables.cpp +++ b/Source/Core/Core/DSP/DSPTables.cpp @@ -510,14 +510,6 @@ constexpr size_t EXT_OPTABLE_SIZE = 0xff + 1; std::array s_op_table; std::array s_ext_op_table; -template -auto FindByOpcode(UDSPInstruction opcode, const std::array& data) -{ - return std::find_if(data.cbegin(), data.cend(), [opcode](const auto& info) { - return (opcode & info.opcode_mask) == info.opcode; - }); -} - template auto FindByName(const std::string& name, const std::array& data) { diff --git a/Source/Core/Core/DSP/DSPTables.h b/Source/Core/Core/DSP/DSPTables.h index 65c336420d..7411384a30 100644 --- a/Source/Core/Core/DSP/DSPTables.h +++ b/Source/Core/Core/DSP/DSPTables.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -118,4 +119,12 @@ const DSPOPCTemplate* FindExtOpInfoByName(const std::string& name); // Used by the interpreter and JIT for instruction emulation const DSPOPCTemplate* GetOpTemplate(UDSPInstruction inst); const DSPOPCTemplate* GetExtOpTemplate(UDSPInstruction inst); + +template +auto FindByOpcode(UDSPInstruction opcode, const std::array& data) +{ + return std::find_if(data.cbegin(), data.cend(), [opcode](const auto& info) { + return (opcode & info.opcode_mask) == info.opcode; + }); +} } // namespace DSP diff --git a/Source/Core/Core/DSP/Interpreter/DSPIntTables.cpp b/Source/Core/Core/DSP/Interpreter/DSPIntTables.cpp index 57138feeaf..c3364e1c42 100644 --- a/Source/Core/Core/DSP/Interpreter/DSPIntTables.cpp +++ b/Source/Core/Core/DSP/Interpreter/DSPIntTables.cpp @@ -4,10 +4,10 @@ #include "Core/DSP/Interpreter/DSPIntTables.h" -#include #include #include "Common/CommonTypes.h" +#include "Core/DSP/DSPTables.h" #include "Core/DSP/Interpreter/DSPIntExtOps.h" #include "Core/DSP/Interpreter/DSPInterpreter.h" @@ -16,7 +16,7 @@ namespace DSP::Interpreter struct InterpreterOpInfo { u16 opcode; - u16 mask; + u16 opcode_mask; InterpreterFunction function; }; @@ -331,13 +331,6 @@ namespace std::array s_op_table; std::array s_ext_op_table; bool s_tables_initialized = false; - -template -auto FindByOpcode(UDSPInstruction opcode, const std::array& data) -{ - return std::find_if(data.cbegin(), data.cend(), - [opcode](const auto& info) { return (opcode & info.mask) == info.opcode; }); -} } // Anonymous namespace InterpreterFunction GetOp(UDSPInstruction inst) diff --git a/Source/Core/Core/DSP/Jit/x64/DSPJitTables.cpp b/Source/Core/Core/DSP/Jit/x64/DSPJitTables.cpp index a9edd4457f..e20f59710f 100644 --- a/Source/Core/Core/DSP/Jit/x64/DSPJitTables.cpp +++ b/Source/Core/Core/DSP/Jit/x64/DSPJitTables.cpp @@ -4,10 +4,10 @@ #include "Core/DSP/Jit/x64/DSPJitTables.h" -#include #include #include "Common/CommonTypes.h" +#include "Core/DSP/DSPTables.h" #include "Core/DSP/Jit/x64/DSPEmitter.h" namespace DSP::JIT::x64 @@ -15,7 +15,7 @@ namespace DSP::JIT::x64 struct JITOpInfo { u16 opcode; - u16 mask; + u16 opcode_mask; JITFunction function; }; @@ -330,13 +330,6 @@ namespace std::array s_op_table; std::array s_ext_op_table; bool s_tables_initialized = false; - -template -auto FindByOpcode(UDSPInstruction opcode, const std::array& data) -{ - return std::find_if(data.cbegin(), data.cend(), - [opcode](const auto& info) { return (opcode & info.mask) == info.opcode; }); -} } // Anonymous namespace JITFunction GetOp(UDSPInstruction inst)