mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-08 00:33:06 +00:00
More changes
This commit is contained in:
parent
4cd37ca8d4
commit
a31de48d88
@ -250,9 +250,9 @@ struct InsertionGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for InsertionGenerator<F, D> {
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| Target::wire(self.gate_index, input);
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
|
||||
let local_targets = |inputs: Range<usize>| inputs.map(local_target);
|
||||
let local_targets = |columns: Range<usize>| columns.map(local_target);
|
||||
|
||||
let mut deps = vec![local_target(self.gate.wires_insertion_index())];
|
||||
deps.extend(local_targets(self.gate.wires_element_to_insert()));
|
||||
@ -263,12 +263,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for Insert
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
|
||||
let get_local_ext = |wire_range: Range<usize>| {
|
||||
debug_assert_eq!(wire_range.len(), D);
|
||||
|
||||
@ -25,9 +25,9 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
|
||||
let mut bits = Vec::with_capacity(num_bits);
|
||||
for &gate in &gates {
|
||||
for limb_input in gate_type.limbs() {
|
||||
for limb_column in gate_type.limbs() {
|
||||
// `new_unsafe` is safe here because BaseSumGate::<2> forces it to be in `{0, 1}`.
|
||||
bits.push(BoolTarget::new_unsafe(Target::wire(gate, limb_input)));
|
||||
bits.push(BoolTarget::new_unsafe(Target::wire(gate, limb_column)));
|
||||
}
|
||||
}
|
||||
for b in bits.drain(num_bits..) {
|
||||
|
||||
@ -362,7 +362,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for AssertLessThanGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| Target::wire(self.gate_index, input);
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
|
||||
vec![
|
||||
local_target(self.gate.wire_first_input()),
|
||||
@ -371,12 +371,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
|
||||
let first_input = get_local_wire(self.gate.wire_first_input());
|
||||
let second_input = get_local_wire(self.gate.wire_second_input());
|
||||
|
||||
@ -239,7 +239,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for ExponentiationGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| Target::wire(self.gate_index, input);
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
|
||||
let mut deps = Vec::with_capacity(self.gate.num_power_bits + 1);
|
||||
deps.push(local_target(self.gate.wire_base()));
|
||||
@ -250,12 +250,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
|
||||
let num_power_bits = self.gate.num_power_bits;
|
||||
let base = get_local_wire(self.gate.wire_base());
|
||||
|
||||
@ -214,14 +214,14 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for InterpolationGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| {
|
||||
let local_target = |column| {
|
||||
Target::Wire(Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
})
|
||||
};
|
||||
|
||||
let local_targets = |inputs: Range<usize>| inputs.map(local_target);
|
||||
let local_targets = |columns: Range<usize>| columns.map(local_target);
|
||||
|
||||
let num_points = self.gate.num_points();
|
||||
let mut deps = Vec::with_capacity(1 + D + num_points * D);
|
||||
@ -235,12 +235,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
|
||||
let get_local_ext = |wire_range: Range<usize>| {
|
||||
debug_assert_eq!(wire_range.len(), D);
|
||||
|
||||
@ -305,14 +305,14 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for InterpolationGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| {
|
||||
let local_target = |column| {
|
||||
Target::Wire(Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
})
|
||||
};
|
||||
|
||||
let local_targets = |inputs: Range<usize>| inputs.map(local_target);
|
||||
let local_targets = |columns: Range<usize>| columns.map(local_target);
|
||||
|
||||
let num_points = self.gate.num_points();
|
||||
let mut deps = Vec::with_capacity(1 + D + num_points * D);
|
||||
@ -326,12 +326,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
|
||||
let get_local_ext = |wire_range: Range<usize>| {
|
||||
debug_assert_eq!(wire_range.len(), D);
|
||||
|
||||
@ -420,14 +420,14 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> SimpleGenerator<F>
|
||||
(0..SPONGE_WIDTH)
|
||||
.map(|i| PoseidonGate::<F, D>::wire_input(i))
|
||||
.chain(Some(PoseidonGate::<F, D>::WIRE_SWAP))
|
||||
.map(|input| Target::wire(self.gate_index, input))
|
||||
.map(|column| Target::wire(self.gate_index, column))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let mut state = (0..SPONGE_WIDTH)
|
||||
|
||||
@ -318,7 +318,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for RandomAccessGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| Target::wire(self.gate_index, input);
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
|
||||
let mut deps = vec![local_target(self.gate.wire_access_index(self.copy))];
|
||||
for i in 0..self.gate.vec_size() {
|
||||
@ -328,13 +328,13 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let mut set_local_wire = |input, value| out_buffer.set_wire(local_wire(input), value);
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
let mut set_local_wire = |column, value| out_buffer.set_wire(local_wire(column), value);
|
||||
|
||||
let copy = self.copy;
|
||||
let vec_size = self.gate.vec_size();
|
||||
|
||||
@ -16,11 +16,8 @@ pub enum Target {
|
||||
}
|
||||
|
||||
impl Target {
|
||||
pub fn wire(gate: usize, input: usize) -> Self {
|
||||
Self::Wire(Wire {
|
||||
row: gate,
|
||||
column: input,
|
||||
})
|
||||
pub fn wire(row: usize, column: usize) -> Self {
|
||||
Self::Wire(Wire { row, column })
|
||||
}
|
||||
|
||||
pub fn is_routable(&self, config: &CircuitConfig) -> bool {
|
||||
@ -36,10 +33,7 @@ impl Target {
|
||||
|
||||
pub fn index(&self, num_wires: usize, degree: usize) -> usize {
|
||||
match self {
|
||||
Target::Wire(Wire {
|
||||
row: gate,
|
||||
column: input,
|
||||
}) => gate * num_wires + input,
|
||||
Target::Wire(Wire { row, column }) => row * num_wires + column,
|
||||
Target::VirtualTarget { index } => degree * num_wires + index,
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,12 +89,9 @@ impl Forest {
|
||||
let mut partition = HashMap::<_, Vec<_>>::new();
|
||||
|
||||
// Here we keep just the Wire targets, filtering out everything else.
|
||||
for gate in 0..self.degree {
|
||||
for input in 0..self.num_routed_wires {
|
||||
let w = Wire {
|
||||
row: gate,
|
||||
column: input,
|
||||
};
|
||||
for row in 0..self.degree {
|
||||
for column in 0..self.num_routed_wires {
|
||||
let w = Wire { row, column };
|
||||
let t = Target::Wire(w);
|
||||
let x_parent = self.parents[self.target_index(t)];
|
||||
partition.entry(x_parent).or_default().push(w);
|
||||
@ -147,12 +144,9 @@ impl WirePartition {
|
||||
}
|
||||
|
||||
let mut sigma = Vec::new();
|
||||
for input in 0..num_routed_wires {
|
||||
for gate in 0..degree {
|
||||
let wire = Wire {
|
||||
row: gate,
|
||||
column: input,
|
||||
};
|
||||
for column in 0..num_routed_wires {
|
||||
for row in 0..degree {
|
||||
let wire = Wire { row, column };
|
||||
let neighbor = neighbors[&wire];
|
||||
sigma.push(neighbor.column * degree + neighbor.row);
|
||||
}
|
||||
|
||||
@ -282,7 +282,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for U32AddManyGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| Target::wire(self.gate_index, input);
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
|
||||
(0..self.gate.num_addends)
|
||||
.map(|j| local_target(self.gate.wire_ith_op_jth_addend(self.i, j)))
|
||||
@ -291,12 +291,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
|
||||
let addends: Vec<_> = (0..self.gate.num_addends)
|
||||
.map(|j| get_local_wire(self.gate.wire_ith_op_jth_addend(self.i, j)))
|
||||
|
||||
@ -290,7 +290,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for U32ArithmeticGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| Target::wire(self.gate_index, input);
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
|
||||
vec![
|
||||
local_target(self.gate.wire_ith_multiplicand_0(self.i)),
|
||||
@ -300,12 +300,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
|
||||
let multiplicand_0 = get_local_wire(self.gate.wire_ith_multiplicand_0(self.i));
|
||||
let multiplicand_1 = get_local_wire(self.gate.wire_ith_multiplicand_1(self.i));
|
||||
|
||||
@ -405,7 +405,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for ComparisonGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| Target::wire(self.gate_index, input);
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
|
||||
vec![
|
||||
local_target(self.gate.wire_first_input()),
|
||||
@ -414,12 +414,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
|
||||
let first_input = get_local_wire(self.gate.wire_first_input());
|
||||
let second_input = get_local_wire(self.gate.wire_second_input());
|
||||
|
||||
@ -274,7 +274,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for U32SubtractionGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| Target::wire(self.gate_index, input);
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
|
||||
vec![
|
||||
local_target(self.gate.wire_ith_input_x(self.i)),
|
||||
@ -284,12 +284,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
|
||||
let input_x = get_local_wire(self.gate.wire_ith_input_x(self.i));
|
||||
let input_y = get_local_wire(self.gate.wire_ith_input_y(self.i));
|
||||
|
||||
@ -222,7 +222,7 @@ struct SwitchGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> SwitchGenerator<F, D> {
|
||||
fn in_out_dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| Target::wire(self.gate_index, input);
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
|
||||
let mut deps = Vec::new();
|
||||
for e in 0..self.gate.chunk_size {
|
||||
@ -236,7 +236,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SwitchGenerator<F, D> {
|
||||
}
|
||||
|
||||
fn in_switch_dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |input| Target::wire(self.gate_index, input);
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
|
||||
let mut deps = Vec::new();
|
||||
for e in 0..self.gate.chunk_size {
|
||||
@ -249,12 +249,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SwitchGenerator<F, D> {
|
||||
}
|
||||
|
||||
fn run_in_out(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
|
||||
let switch_bool_wire = local_wire(self.gate.wire_switch_bool(self.copy));
|
||||
|
||||
@ -279,12 +279,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SwitchGenerator<F, D> {
|
||||
}
|
||||
|
||||
fn run_in_switch(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |input| Wire {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
column: input,
|
||||
column,
|
||||
};
|
||||
|
||||
let get_local_wire = |input| witness.get_wire(local_wire(input));
|
||||
let get_local_wire = |column| witness.get_wire(local_wire(column));
|
||||
|
||||
let switch_bool = get_local_wire(self.gate.wire_switch_bool(self.copy));
|
||||
for e in 0..self.gate.chunk_size {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user