Skip to content

Commit

Permalink
add lookup_ltu_limb8 example
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Sep 9, 2024
1 parent ca0a364 commit 7ddc98e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ceno_zkvm/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct LkMultiplicity {

#[allow(dead_code)]
impl LkMultiplicity {
/// assert within range
#[inline(always)]
pub fn assert_ux<const C: usize>(&mut self, v: u64) {
match C {
Expand Down Expand Up @@ -108,6 +109,17 @@ impl LkMultiplicity {
.or_default()) += 1;
}

/// lookup a < b as usigned byte
pub fn lookup_ltu_limb8(&mut self, a: u64, b: u64) {
let key = a.wrapping_mul(256) + b;
let multiplicity = self
.multiplicity
.get_or(|| RefCell::new(array::from_fn(|_| HashMap::new())));
(*multiplicity.borrow_mut()[ROMType::Ltu as usize]
.entry(key)
.or_default()) += 1;
}

/// merge result from multiple thread local to single result
fn into_finalize_result(self) -> [HashMap<u64, usize>; mem::variant_count::<ROMType>()] {
Arc::try_unwrap(self.multiplicity)
Expand Down

0 comments on commit 7ddc98e

Please sign in to comment.