R5900: Fix decoding the imm5 operand of the viaddi instruction as a signed value instead of decoding it as an unsigned one.

This commit is contained in:
angie 2025-02-06 16:26:37 -03:00
parent b9242fe0eb
commit cecc302373
5 changed files with 11 additions and 4 deletions

View File

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- R5900: Fix decoding the `imm5` operand of the `viaddi` instruction as a signed
value instead of decoding it as an unsigned one.
## [1.12.5] - 2024-12-16
### Fixed

View File

@ -33,7 +33,7 @@ namespace rabbitizer {
uint8_t GetR5900_l() const;
uint8_t GetR5900_m() const;
uint8_t GetR5900_imm5() const;
int8_t GetR5900_imm5() const;
};
};

View File

@ -113,6 +113,6 @@ uint8_t InstructionR5900::GetR5900_m() const {
return RAB_INSTR_R5900_GET_m(&this->instr);
}
uint8_t InstructionR5900::GetR5900_imm5() const {
return RAB_INSTR_R5900_GET_imm5(&this->instr);
int8_t InstructionR5900::GetR5900_imm5() const {
return RabbitizerUtils_From2Complement(RAB_INSTR_R5900_GET_imm5(&this->instr), 5);
}

View File

@ -515,7 +515,7 @@ size_t RabbitizerOperandType_process_r5900_immediate5(const RabbitizerInstructio
return immOverrideLength;
}
number = RAB_INSTR_R5900_GET_imm5(self);
number = RabbitizerUtils_From2Complement(RAB_INSTR_R5900_GET_imm5(self), 5);
if (RabbitizerConfig_Cfg.misc.omit0XOnSmallImm) {
if (number > -10 && number < 10) {
RABUTILS_BUFFER_SPRINTF(dst, totalSize, "%i", number);

View File

@ -40,6 +40,8 @@ const TestEntry test_entries[] = {
TEST_ENTRY_C(0x4A820BFF, NULL, "viswr.y $vi2, ($vi1)"),
TEST_ENTRY_C(0x4A420BFF, NULL, "viswr.z $vi2, ($vi1)"),
TEST_ENTRY_C(0x4A220BFF, NULL, "viswr.w $vi2, ($vi1)"),
TEST_ENTRY_C(0x4A0307B2, NULL, "viaddi $vi3, $vi0, -0x2"),
};
size_t test_entries_len = ARRAY_COUNT(test_entries);