mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-10 01:33:07 +00:00
addressed comments
This commit is contained in:
parent
244543578b
commit
5dd4ed3e1c
@ -81,24 +81,11 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
self.mul_add_u32(a, one, b)
|
||||
}
|
||||
|
||||
pub fn add_three_u32(
|
||||
&mut self,
|
||||
a: U32Target,
|
||||
b: U32Target,
|
||||
c: U32Target,
|
||||
) -> (U32Target, U32Target) {
|
||||
let (init_low, carry1) = self.add_u32(a, b);
|
||||
let (final_low, carry2) = self.add_u32(c, init_low);
|
||||
let (combined_carry, _zero) = self.add_u32(carry1, carry2);
|
||||
(final_low, combined_carry)
|
||||
}
|
||||
|
||||
pub fn add_many_u32(&mut self, to_add: Vec<U32Target>) -> (U32Target, U32Target) {
|
||||
pub fn add_many_u32(&mut self, to_add: &[U32Target]) -> (U32Target, U32Target) {
|
||||
match to_add.len() {
|
||||
0 => (self.zero_u32(), self.zero_u32()),
|
||||
1 => (to_add[0], self.zero_u32()),
|
||||
2 => self.add_u32(to_add[0], to_add[1]),
|
||||
3 => self.add_three_u32(to_add[0], to_add[1], to_add[2]),
|
||||
_ => {
|
||||
let (mut low, mut carry) = self.add_u32(to_add[0], to_add[1]);
|
||||
for i in 2..to_add.len() {
|
||||
|
||||
@ -117,7 +117,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
self.zero_u32()
|
||||
};
|
||||
|
||||
let (new_limb, new_carry) = self.add_three_u32(carry.clone(), a_limb, b_limb);
|
||||
let (new_limb, new_carry) = self.add_many_u32(&[carry.clone(), a_limb, b_limb]);
|
||||
carry = new_carry;
|
||||
combined_limbs.push(new_limb);
|
||||
}
|
||||
@ -164,7 +164,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let mut carry = self.zero_u32();
|
||||
for i in 0..total_limbs {
|
||||
to_add[i].push(carry);
|
||||
let (new_result, new_carry) = self.add_many_u32(to_add[i].clone());
|
||||
let (new_result, new_carry) = self.add_many_u32(&to_add[i].clone());
|
||||
combined_limbs.push(new_result);
|
||||
carry = new_carry;
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBase};
|
||||
pub const NUM_U32_SUBTRACTION_OPS: usize = 3;
|
||||
|
||||
/// A gate to perform a subtraction on 32-bit limbs: given `x`, `y`, and `borrow`, it returns
|
||||
/// the result `x - y - borrow` and, if this underflows, a new `borrow`.
|
||||
/// the result `x - y - borrow` and, if this underflows, a new `borrow`. Inputs are not range-checked.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct U32SubtractionGate<F: RichField + Extendable<D>, const D: usize> {
|
||||
_phantom: PhantomData<F>,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user