Skip to content

Commit

Permalink
Merge pull request #2865 from o1-labs/dw/o1vm/bitmask
Browse files Browse the repository at this point in the history
o1vm/ricv32im: regression tests for bitmask
  • Loading branch information
dannywillems authored Dec 11, 2024
2 parents cdbc90c + faecb5c commit b1d9f24
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions o1vm/src/interpreters/riscv32im/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::{registers::Registers, witness::Env, INSTRUCTION_SET_SIZE, PAGE_SIZE,
use crate::interpreters::riscv32im::{
constraints,
interpreter::{
IInstruction, Instruction, MInstruction, RInstruction, SBInstruction, SInstruction,
SyscallInstruction, UInstruction, UJInstruction,
IInstruction, Instruction, InterpreterEnv, MInstruction, RInstruction, SBInstruction,
SInstruction, SyscallInstruction, UInstruction, UJInstruction,
},
};
use ark_ff::Zero;
Expand Down Expand Up @@ -419,3 +419,31 @@ pub fn test_instruction_decoding_and() {
let (opcode, _instruction) = env.decode_instruction();
assert_eq!(opcode, Instruction::RType(RInstruction::And));
}

#[test]
pub fn test_witness_bitmask_bounds() {
let mut env: Env<Fp> = dummy_env();
// Checking that the bit position given as upper bound is not included in
// the output, i.e. the output is v[LOWER_BOUND:UPPER_BOUND-1]
{
// We take only 4 bits on the 5.
let input = 0b10000;
let output = {
let pos = env.alloc_scratch();
unsafe { env.bitmask(&input, 4, 0, pos) }
};
let exp_output = 0b0000;
assert_eq!(output, exp_output);
}

{
// We take 5 bits
let input = 0b10000;
let output = {
let pos = env.alloc_scratch();
unsafe { env.bitmask(&input, 5, 0, pos) }
};
let exp_output = 0b10000;
assert_eq!(output, exp_output);
}
}

0 comments on commit b1d9f24

Please sign in to comment.