Skip to content

Commit

Permalink
Fix and generialise
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgoergens committed Dec 12, 2024
1 parent 856095e commit 76a3cb7
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions ceno_zkvm/src/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,24 @@ pub struct Value<'a, T: Into<u64> + From<u32> + Copy + Default> {
pub limbs: Cow<'a, [u16]>,
}

impl<'a, T: Into<u64> + From<u32> + Copy + Default> From<&'a Value<'a, T>> for &'a [u16] {
fn from(v: &'a Value<'a, T>) -> Self {
v.as_u16_limbs()
}
}

impl<'a, T: Into<u64> + From<u32> + Copy + Default> From<&Value<'a, T>> for u64 {
fn from(v: &Value<'a, T>) -> Self {
v.as_u64()
}
}

impl<'a, T: Into<u64> + From<u32> + Copy + Default> From<&Value<'a, T>> for u32 {
fn from(v: &Value<'a, T>) -> Self {
v.as_u32()
}
}

// TODO generalize to support non 16 bit limbs
// TODO optimize api with fixed size array
impl<'a, T: Into<u64> + From<u32> + Copy + Default> Value<'a, T> {
Expand All @@ -616,10 +634,7 @@ impl<'a, T: Into<u64> + From<u32> + Copy + Default> Value<'a, T> {
const LIMBS: usize = (Self::M + 15) / 16;

pub fn new(val: T, lkm: &mut LkMultiplicity) -> Self {
let uint = Value::<T> {
val,
limbs: Cow::Owned(Self::split_to_u16(val)),
};
let uint = Self::new_unchecked(val);
Self::assert_u16(&uint.limbs, lkm);
uint
}
Expand Down

0 comments on commit 76a3cb7

Please sign in to comment.