Skip to content

Commit

Permalink
Merge pull request #2902 from o1-labs/dw/slt-tests
Browse files Browse the repository at this point in the history
o1vm/riscv32im: add tests for SLT
  • Loading branch information
dannywillems authored Dec 24, 2024
2 parents 8fe531a + 755b085 commit 5b63f23
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Binary file added o1vm/resources/programs/riscv32im/bin/slt
Binary file not shown.
30 changes: 30 additions & 0 deletions o1vm/resources/programs/riscv32im/src/slt.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.section .text
.globl _start

_start:

# SLT with t0 < t1 (Expected: 1)
li t0, 100 # t0 = 100
li t1, 200 # t1 = 200
slt t2, t0, t1 # t2 = (t0 < t1) ? 1 : 0 (Expected: t2 = 1)

# SLT with t3 > t4 (Expected: 0)
li t3, 300 # t3 = 300
li t4, 200 # t4 = 200
slt t5, t3, t4 # t5 = (t3 < t4) ? 1 : 0 (Expected: t5 = 0)

# SLT with t0 == t1 (Expected: 0)
li t0, 150 # t6 = 150
li t1, 150 # t7 = 150
slt t6, t0, t1 # t6 = (t0 < t1) ? 1 : 0 (Expected: t6 = 0)

# 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
18 changes: 18 additions & 0 deletions o1vm/tests/test_riscv_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,21 @@ fn test_and() {
assert_eq!(witness.registers[T5], 0);
assert_eq!(witness.registers[T1], 0b1010);
}

#[test]
fn test_slt() {
let curr_dir = std::env::current_dir().unwrap();
let path = curr_dir.join(std::path::PathBuf::from(
"resources/programs/riscv32im/bin/slt",
));
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[T2], 1);
assert_eq!(witness.registers[T5], 0);
assert_eq!(witness.registers[T6], 0);
}

0 comments on commit 5b63f23

Please sign in to comment.