Skip to content

Commit

Permalink
DSPAnalyzer: Separate instruction searching and idle skip finding
Browse files Browse the repository at this point in the history
Places them into their own function to keep their functionality isolated
and self-documenting.
  • Loading branch information
lioncash committed Dec 28, 2020
1 parent cc512a7 commit 8aecaf7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Source/Core/Core/DSP/DSPAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++)
Expand All @@ -155,6 +166,5 @@ void Analyzer::AnalyzeRange(const SDSP& dsp, u16 start_addr, u16 end_addr)
}
}
}
INFO_LOG_FMT(DSPLLE, "Finished analysis.");
}
} // namespace DSP
8 changes: 8 additions & 0 deletions Source/Core/Core/DSP/DSPAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ class Analyzer
// 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]; }

Expand Down

0 comments on commit 8aecaf7

Please sign in to comment.