From ed6797b32992bb7e5cdaa25118e4fcc6d746ceef Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Wed, 11 Dec 2024 09:39:24 +0800 Subject: [PATCH] Introduce `Value::as_i32` To help make https://github.com/scroll-tech/ceno/pull/596 easier to read and reason about. --- ceno_zkvm/src/instructions/riscv/mul.rs | 4 +--- ceno_zkvm/src/uint.rs | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ceno_zkvm/src/instructions/riscv/mul.rs b/ceno_zkvm/src/instructions/riscv/mul.rs index 58b410960..c588feadf 100644 --- a/ceno_zkvm/src/instructions/riscv/mul.rs +++ b/ceno_zkvm/src/instructions/riscv/mul.rs @@ -432,9 +432,7 @@ impl Signed { lkm, *val.as_u16_limbs().last().unwrap() as u64, )?; - let signed_val = val.as_u32() as i32; - - Ok(signed_val) + Ok(val.as_i32()) } pub fn expr(&self) -> Expression { diff --git a/ceno_zkvm/src/uint.rs b/ceno_zkvm/src/uint.rs index 193d34f13..f8e872a2e 100644 --- a/ceno_zkvm/src/uint.rs +++ b/ceno_zkvm/src/uint.rs @@ -684,6 +684,11 @@ impl<'a, T: Into + From + Copy + Default> Value<'a, T> { self.as_u64() as u32 } + /// Convert the limbs to a u32 value + pub fn as_i32(&self) -> i32 { + self.as_u32() as i32 + } + pub fn u16_fields(&self) -> Vec { self.limbs.iter().map(|v| F::from(*v as u64)).collect_vec() }