Skip to content

Commit

Permalink
o1vm/ricv32im: regression tests for bitmask
Browse files Browse the repository at this point in the history
Checking that the count of the bit index starts at 0, i.e. the number of bits
that bitmask returns if `higher_bit - lower_bit`.
  • Loading branch information
dannywillems committed Dec 5, 2024
1 parent 0af1256 commit faecb5c
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 faecb5c

Please sign in to comment.