Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10045 from Pokechu22/dsp-lle-sr64
DSPLLE: Carry and overflow fixes
  • Loading branch information
Tilka committed Aug 23, 2021
2 parents 67dce9f + 779cd47 commit bc10412
Show file tree
Hide file tree
Showing 17 changed files with 810 additions and 521 deletions.
4 changes: 4 additions & 0 deletions Source/Core/Core/DSP/DSPAnalyzer.cpp
Expand Up @@ -91,7 +91,9 @@ void Analyzer::FindInstructionStarts(const SDSP& dsp, u16 start_addr, u16 end_ad
{
// 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.
#ifndef DISABLE_UPDATE_SR_ANALYSIS
u16 last_arithmetic = 0;
#endif
for (u16 addr = start_addr; addr < end_addr;)
{
const UDSPInstruction inst = dsp.ReadIMEM(addr);
Expand All @@ -117,6 +119,7 @@ void Analyzer::FindInstructionStarts(const SDSP& dsp, u16 start_addr, u16 end_ad
m_code_flags[static_cast<u16>(addr + 1u)] |= CODE_LOOP_END;
}

#ifndef DISABLE_UPDATE_SR_ANALYSIS
// Mark the last arithmetic/multiplier instruction before a branch.
// We must update the SR reg at these instructions
if (opcode->updates_sr)
Expand All @@ -128,6 +131,7 @@ void Analyzer::FindInstructionStarts(const SDSP& dsp, u16 start_addr, u16 end_ad
{
m_code_flags[last_arithmetic] |= CODE_UPDATE_SR;
}
#endif

// If an instruction potentially raises exceptions, mark the following
// instruction as needing to check for exceptions
Expand Down
11 changes: 11 additions & 0 deletions Source/Core/Core/DSP/DSPAnalyzer.h
Expand Up @@ -6,6 +6,13 @@
#include <array>
#include "Common/CommonTypes.h"

// The update SR analysis is not perfect: it does not properly handle modified SR values if SR is
// only read within a function call, and it's possible that a previous instruction sets SR (e.g. the
// logical zero bit, or the sticky overflow bit) but is marked as not changing SR as a later
// instruction sets it. When this flag is set, we always treat instructions as updating SR, and
// disable the analysis for if SR needs to be set.
#define DISABLE_UPDATE_SR_ANALYSIS

namespace DSP
{
struct SDSP;
Expand Down Expand Up @@ -63,7 +70,11 @@ class Analyzer
// Whether or not the address describes an instruction that requires updating the SR register.
[[nodiscard]] bool IsUpdateSR(u16 address) const
{
#ifdef DISABLE_UPDATE_SR_ANALYSIS
return true;
#else
return (GetCodeFlags(address) & CODE_UPDATE_SR) != 0;
#endif
}

// Whether or not the address describes instructions that potentially raise exceptions.
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/DSP/DSPCore.h
Expand Up @@ -271,7 +271,7 @@ struct DSP_Regs
{
u16 l;
u16 m;
u16 h;
u32 h; // 32 bits so that val is fully sign-extended (only 8 bits are actually used)
};
} ac[2];
};
Expand Down

0 comments on commit bc10412

Please sign in to comment.