Skip to content

Commit

Permalink
Fix negative imm values
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksmckinley committed Mar 29, 2024
1 parent a34aa15 commit 8204869
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/emulation_core/riscv/datapath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,10 +1102,10 @@ impl RiscDatapath {

fn construct_jump_address(&mut self) {
self.state.i_type_jump =
(self.state.imm as u64 + self.state.read_data_1) & 0xfffffffffffffff0;
((self.state.imm as u64).wrapping_add(self.state.read_data_1)) & 0xfffffffffffffff0;
self.state.jump_address = match self.instruction {
Instruction::IType(_i) => self.state.imm as u64 + self.state.read_data_1,
Instruction::JType(_j) => self.state.imm as u64 * 4,
Instruction::IType(_i) => (self.state.imm as u64).wrapping_add(self.state.read_data_1),
Instruction::JType(_j) => (self.state.imm as u64).wrapping_shl(2),
_ => self.state.jump_address,
}
}
Expand Down

0 comments on commit 8204869

Please sign in to comment.