From 74440c468f7adbf48ca007e6c90dfc763df06bd5 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Wed, 18 Aug 2021 15:34:01 -0700 Subject: [PATCH] DSPInterpreter: Sign-extend acS.h to 32 bits Thus, the 40-bit accumulator is treated as properly sign-extended when read as a 64-bit number. This affects e.g. overflow detection. --- Source/Core/Core/DSP/DSPCore.h | 2 +- Source/Core/Core/DSP/Interpreter/DSPInterpreter.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/DSP/DSPCore.h b/Source/Core/Core/DSP/DSPCore.h index 506e3995d4..6455349a09 100644 --- a/Source/Core/Core/DSP/DSPCore.h +++ b/Source/Core/Core/DSP/DSPCore.h @@ -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]; }; diff --git a/Source/Core/Core/DSP/Interpreter/DSPInterpreter.cpp b/Source/Core/Core/DSP/Interpreter/DSPInterpreter.cpp index 1fd3aa3ff3..9cd7804fbc 100644 --- a/Source/Core/Core/DSP/Interpreter/DSPInterpreter.cpp +++ b/Source/Core/Core/DSP/Interpreter/DSPInterpreter.cpp @@ -769,7 +769,7 @@ void Interpreter::ConditionalExtendAccum(int reg) // Sign extend into whole accum. auto& state = m_dsp_core.DSPState(); const u16 val = state.r.ac[reg - DSP_REG_ACM0].m; - state.r.ac[reg - DSP_REG_ACM0].h = (val & 0x8000) != 0 ? 0xFFFF : 0x0000; + state.r.ac[reg - DSP_REG_ACM0].h = (val & 0x8000) != 0 ? 0xFFFFFFFF : 0x0000; state.r.ac[reg - DSP_REG_ACM0].l = 0; }