Skip to content

Commit ac54012

Browse files
authored
fix(executor): remove incorrect sign extension for J/JAL target address (#427)
* fix(executor): remove incorrect sign extension for J/JAL target address * fmt
1 parent ff01f1c commit ac54012

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

crates/core/executor/src/instruction.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ impl Instruction {
319319
let offset = insn & 0xffff; // as known as imm
320320
let offset_ext16 = sign_extend::<16>(offset);
321321
let target = insn & 0x3ffffff;
322-
let target_ext = sign_extend::<26>(target);
323322
log::trace!("op {opcode}, func {func}, rt {rt}, rs {rs}, rd {rd}");
324323
log::trace!("decode: insn {insn:X}, opcode {opcode:X}, func {func:X}");
325324

@@ -440,15 +439,10 @@ impl Instruction {
440439
Ok(Self::new_with_raw(Opcode::UNIMPL, 0, 0, insn, true, true, insn))
441440
}
442441
}
443-
// J
444-
(0x02, _) => {
445-
// Ignore the upper 4 most significant bits,since they are always 0 currently.
446-
Ok(Self::new(Opcode::Jumpi, 0u8, target_ext.overflowing_shl(2).0, 0, true, true))
447-
}
448-
// JAL
449-
(0x03, _) => {
450-
Ok(Self::new(Opcode::Jumpi, 31u8, target_ext.overflowing_shl(2).0, 0, true, true))
451-
}
442+
// J: target is unsigned (not sign-extended) per MIPS spec.
443+
(0x02, _) => Ok(Self::new(Opcode::Jumpi, 0u8, target << 2, 0, true, true)),
444+
// JAL: target is unsigned (not sign-extended) per MIPS spec.
445+
(0x03, _) => Ok(Self::new(Opcode::Jumpi, 31u8, target << 2, 0, true, true)),
452446
// BEQ
453447
(0x04, _) => Ok(Self::new(
454448
Opcode::BEQ,

0 commit comments

Comments
 (0)