From 8aecaf784c43aec914226fec08a7226eed6cba6d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 28 Dec 2020 12:09:31 -0500 Subject: [PATCH] DSPAnalyzer: Separate instruction searching and idle skip finding Places them into their own function to keep their functionality isolated and self-documenting. --- Source/Core/Core/DSP/DSPAnalyzer.cpp | 14 ++++++++++++-- Source/Core/Core/DSP/DSPAnalyzer.h | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/DSP/DSPAnalyzer.cpp b/Source/Core/Core/DSP/DSPAnalyzer.cpp index ae81357b19..2b2d70e2e6 100644 --- a/Source/Core/Core/DSP/DSPAnalyzer.cpp +++ b/Source/Core/Core/DSP/DSPAnalyzer.cpp @@ -80,7 +80,16 @@ void Analyzer::AnalyzeRange(const SDSP& dsp, u16 start_addr, u16 end_addr) { // First we run an extremely simplified version of a disassembler to find // where all instructions start. + FindInstructionStarts(dsp, start_addr, end_addr); + // Next, we'll scan for potential idle skips. + FindIdleSkips(dsp, start_addr, end_addr); + + INFO_LOG_FMT(DSPLLE, "Finished analysis."); +} + +void Analyzer::FindInstructionStarts(const SDSP& dsp, u16 start_addr, u16 end_addr) +{ // This may not be 100% accurate in case of jump tables! // It could get desynced, which would be bad. We'll see if that's an issue. u16 last_arithmetic = 0; @@ -132,8 +141,10 @@ void Analyzer::AnalyzeRange(const SDSP& dsp, u16 start_addr, u16 end_addr) addr += opcode->size; } +} - // Next, we'll scan for potential idle skips. +void Analyzer::FindIdleSkips(const SDSP& dsp, u16 start_addr, u16 end_addr) +{ for (size_t s = 0; s < NUM_IDLE_SIGS; s++) { for (u16 addr = start_addr; addr < end_addr; addr++) @@ -155,6 +166,5 @@ void Analyzer::AnalyzeRange(const SDSP& dsp, u16 start_addr, u16 end_addr) } } } - INFO_LOG_FMT(DSPLLE, "Finished analysis."); } } // namespace DSP diff --git a/Source/Core/Core/DSP/DSPAnalyzer.h b/Source/Core/Core/DSP/DSPAnalyzer.h index c48199aa24..84f1c1cd97 100644 --- a/Source/Core/Core/DSP/DSPAnalyzer.h +++ b/Source/Core/Core/DSP/DSPAnalyzer.h @@ -92,6 +92,14 @@ private: // Note: start is inclusive, end is exclusive. void AnalyzeRange(const SDSP& dsp, u16 start_addr, u16 end_addr); + // Finds addresses in the range [start_addr, end_addr) that are the start of an + // instruction. During this process other attributes may be detected as well + // for relevant instructions (loop start/end, etc). + void FindInstructionStarts(const SDSP& dsp, u16 start_addr, u16 end_addr); + + // Finds locations within the range [start_addr, end_addr) that may contain idle skips. + void FindIdleSkips(const SDSP& dsp, u16 start_addr, u16 end_addr); + // Retrieves the flags set during analysis for code in memory. [[nodiscard]] u8 GetCodeFlags(u16 address) const { return m_code_flags[address]; }