Skip to content

Commit

Permalink
Merge pull request #2898 from o1-labs/dw/addi-boundary-immediate
Browse files Browse the repository at this point in the history
o1vm/riscv32im: add unit tests for addi with boundary values
  • Loading branch information
dannywillems authored Dec 24, 2024
2 parents 422f493 + 9d77acc commit b7e8000
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Binary file not shown.
20 changes: 20 additions & 0 deletions o1vm/resources/programs/riscv32im/src/addi_boundary_immediate.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.section .text
.globl _start

_start:
li t0, 100 # t0 = 100
addi t1, t0, 2047 # t1 = t0 + 2047 (Expected: t1 = 2147)

li t2, 1000 # t2 = 1000
addi t3, t2, -2048 # t3 = t2 + (-2048) (Expected: t1 = -1048)

# Custom exit syscall
li a0, 0
li a1, 0
li a2, 0
li a3, 0
li a4, 0
li a5, 0
li a6, 0
li a7, 42
ecall
17 changes: 17 additions & 0 deletions o1vm/tests/test_riscv_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,20 @@ fn test_addi_overflow() {
assert_eq!(witness.registers[T3], 2147483647);
assert_eq!(witness.registers[T5], 123456789);
}

#[test]
fn test_addi_boundary_immediate() {
let curr_dir = std::env::current_dir().unwrap();
let path = curr_dir.join(std::path::PathBuf::from(
"resources/programs/riscv32im/bin/addi_boundary_immediate",
));
let state = o1vm::elf_loader::parse_riscv32(&path).unwrap();
let mut witness = Env::<Fp>::create(PAGE_SIZE.try_into().unwrap(), state);

while !witness.halt {
witness.step();
}

assert_eq!(witness.registers[T1], 2147);
assert_eq!(witness.registers[T3], (-1048_i32) as u32);
}

0 comments on commit b7e8000

Please sign in to comment.