DSPAnalyzer: Separate instruction searching and idle skip finding

Places them into their own function to keep their functionality isolated
and self-documenting.
This commit is contained in:
Lioncash 2020-12-28 12:09:31 -05:00
parent cc512a7524
commit 8aecaf784c
2 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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]; }