mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-09 01:03:08 +00:00
add_many_u32
This commit is contained in:
parent
a4eac25f3d
commit
956b34c2e9
@ -7,7 +7,7 @@ use crate::gates::subtraction_u32::U32SubtractionGate;
|
||||
use crate::iop::target::Target;
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct U32Target(pub Target);
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
@ -87,6 +87,25 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
(final_low, combined_carry)
|
||||
}
|
||||
|
||||
pub fn add_many_u32(&mut self, to_add: Vec<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() {
|
||||
let (new_low, new_carry) = self.add_u32(to_add[i], low);
|
||||
let (combined_carry, _zero) = self.add_u32(carry, new_carry);
|
||||
low = new_low;
|
||||
carry = combined_carry;
|
||||
}
|
||||
(low, carry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mul_u32(&mut self, a: U32Target, b: U32Target) -> (U32Target, U32Target) {
|
||||
let zero = self.zero_u32();
|
||||
self.mul_add_u32(a, b, zero)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user