From 305cc76448239c063dcd07e9429befda9fd161af Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Wed, 11 Sep 2024 23:39:39 -0400 Subject: [PATCH] Fixed edge case with switch case jump table detection when lo16 immediate is exactly 0 --- src/analysis.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/analysis.cpp b/src/analysis.cpp index 0310875..5dfd955 100644 --- a/src/analysis.cpp +++ b/src/analysis.cpp @@ -158,9 +158,11 @@ bool analyze_instruction(const rabbitizer::InstructionCpu& instr, const N64Recom } // If the base register has a valid lui state and a valid addend before this, then this may be a load from a jump table else if (reg_states[base].valid_lui && reg_states[base].valid_addend) { - // Exactly one of the lw and the base reg should have a valid lo16 value + // Exactly one of the lw and the base reg should have a valid lo16 value. However, the lo16 may end up just being zero by pure luck, + // so allow the case where the lo16 immediate is zero and the register state doesn't have a valid addiu immediate. + // This means the only invalid case is where they're both true. bool nonzero_immediate = imm != 0; - if (nonzero_immediate != reg_states[base].valid_addiu) { + if (!(nonzero_immediate && reg_states[base].valid_addiu)) { uint32_t lo16; if (nonzero_immediate) { lo16 = (int16_t)imm;