Skip to content

Commit

Permalink
Merge branch 'mathias/use-sum' into matthias/to-expr-instances
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgoergens committed Dec 12, 2024
2 parents 78c43b5 + 4c597d9 commit 04a72ff
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
4 changes: 1 addition & 3 deletions ceno_zkvm/src/instructions/riscv/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,7 @@ impl<E: ExtensionField> Signed<E> {
lkm,
*val.as_u16_limbs().last().unwrap() as u64,
)?;
let signed_val = val.as_u32() as i32;

Ok(signed_val)
Ok(i32::from(val))
}
}

Expand Down
34 changes: 30 additions & 4 deletions ceno_zkvm/src/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,30 @@ 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()
}
}

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

// 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 @@ -617,10 +641,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 Expand Up @@ -685,6 +706,11 @@ impl<'a, T: Into<u64> + From<u32> + Copy + Default> Value<'a, T> {
self.as_u64() as u32
}

/// Convert the limbs to an i32 value
pub fn as_i32(&self) -> i32 {
self.as_u32() as i32
}

pub fn u16_fields<F: SmallField>(&self) -> Vec<F> {
self.limbs.iter().map(|v| F::from(*v as u64)).collect_vec()
}
Expand Down
2 changes: 1 addition & 1 deletion mpcs/src/sum_check/classic/coeff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<E: ExtensionField> ClassicSumCheckRoundMessage<E> for Coefficients<E> {
}

fn sum(&self) -> E {
self[..].iter().sum()
self[0] + self[..].iter().sum::<E>()
}

fn evaluate(&self, _: &Self::Auxiliary, challenge: &E) -> E {
Expand Down

0 comments on commit 04a72ff

Please sign in to comment.