Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jolt-core): Fixes DIVU and REMU sequence_output #506

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions jolt-core/src/jolt/instruction/divu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,15 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for DIVUInstruction<WORD
}

fn sequence_output(x: u64, y: u64) -> u64 {
x / y
if y == 0 {
match WORD_SIZE {
32 => u32::MAX as u64,
64 => u64::MAX,
_ => panic!("Unsupported WORD_SIZE: {}", WORD_SIZE),
}
} else {
x / y
}
}
}

Expand All @@ -238,7 +246,7 @@ mod test {
use crate::{jolt::instruction::JoltInstruction, jolt_virtual_sequence_test};

#[test]
fn div_virtual_sequence_32() {
fn divu_virtual_sequence_32() {
jolt_virtual_sequence_test!(DIVUInstruction::<32>, RV32IM::DIVU);
}
}
12 changes: 8 additions & 4 deletions jolt-core/src/jolt/instruction/remu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,14 @@ impl<const WORD_SIZE: usize> VirtualInstructionSequence for REMUInstruction<WORD
}

fn sequence_output(x: u64, y: u64) -> u64 {
match WORD_SIZE {
32 => (x as u32 % y as u32) as u64,
64 => x % y,
_ => panic!("Unsupported WORD_SIZE: {}", WORD_SIZE),
if y == 0 {
x
} else {
match WORD_SIZE {
32 => (x as u32 % y as u32) as u64,
64 => x % y,
_ => panic!("Unsupported WORD_SIZE: {}", WORD_SIZE),
}
}
}
}
Expand Down
Loading