Remove obsolete function ceil_div_usize (#1574)

This commit is contained in:
Matthias Görgens 2024-04-19 21:00:03 +08:00 committed by GitHub
parent 76da138338
commit 72c1c90748
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 33 additions and 47 deletions

View File

@ -13,7 +13,6 @@ use crate::iop::target::{BoolTarget, Target};
use crate::iop::witness::{PartitionWitness, Witness, WitnessWrite};
use crate::plonk::circuit_builder::CircuitBuilder;
use crate::plonk::circuit_data::CommonCircuitData;
use crate::util::ceil_div_usize;
use crate::util::serialization::{Buffer, IoResult, Read, Write};
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
@ -26,7 +25,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
return Vec::new();
}
let gate_type = BaseSumGate::<2>::new_from_config::<F>(&self.config);
let k = ceil_div_usize(num_bits, gate_type.num_limbs);
let k = num_bits.div_ceil(gate_type.num_limbs);
let gates = (0..k)
.map(|_| self.add_gate(gate_type, vec![]))
.collect::<Vec<_>>();

View File

@ -11,7 +11,6 @@ use std::sync::Arc;
use itertools::Itertools;
use keccak_hash::keccak;
use plonky2_util::ceil_div_usize;
use crate::field::extension::Extendable;
use crate::field::packed::PackedField;
@ -207,7 +206,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F, D> for Loo
}
fn run_once(&self, _witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let first_row = self.last_lut_row + ceil_div_usize(self.lut.len(), self.num_slots) - 1;
let first_row = self.last_lut_row + self.lut.len().div_ceil(self.num_slots) - 1;
let slot = (first_row - self.row) * self.num_slots + self.slot_nb;
let slot_input_target =

View File

@ -9,7 +9,6 @@ use std::{collections::BTreeMap, sync::Arc, time::Instant};
use hashbrown::{HashMap, HashSet};
use itertools::Itertools;
use log::{debug, info, warn, Level};
use plonky2_util::ceil_div_usize;
use crate::field::cosets::get_unique_coset_shifts;
use crate::field::extension::{Extendable, FieldExtension};
@ -1219,7 +1218,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
0
} else {
// There is 1 RE polynomial and multiple Sum/LDC polynomials.
ceil_div_usize(LookupGate::num_slots(&self.config), lookup_degree) + 1
LookupGate::num_slots(&self.config).div_ceil(lookup_degree) + 1
};
let constants_sigmas_cap = constants_sigmas_commitment.merkle_tree.cap.clone();
let domain_separator = self.domain_separator.unwrap_or_default();

View File

@ -33,7 +33,7 @@ use crate::plonk::vars::EvaluationVarsBaseBatch;
use crate::timed;
use crate::util::partial_products::{partial_products_and_z_gx, quotient_chunk_products};
use crate::util::timing::TimingTree;
use crate::util::{ceil_div_usize, log2_ceil, transpose};
use crate::util::{log2_ceil, transpose};
/// Set all the lookup gate wires (including multiplicities) and pad unused LU slots.
/// Warning: rows are in descending order: the first gate to appear is the last LU gate, and
@ -462,9 +462,9 @@ fn compute_lookup_polys<
let degree = common_data.degree();
let num_lu_slots = LookupGate::num_slots(&common_data.config);
let max_lookup_degree = common_data.config.max_quotient_degree_factor - 1;
let num_partial_lookups = ceil_div_usize(num_lu_slots, max_lookup_degree);
let num_partial_lookups = num_lu_slots.div_ceil(max_lookup_degree);
let num_lut_slots = LookupTableGate::num_slots(&common_data.config);
let max_lookup_table_degree = ceil_div_usize(num_lut_slots, num_partial_lookups);
let max_lookup_table_degree = num_lut_slots.div_ceil(num_partial_lookups);
// First poly is RE, the rest are partial SLDCs.
let mut final_poly_vecs = Vec::with_capacity(num_partial_lookups + 1);
@ -652,10 +652,10 @@ fn compute_quotient_polys<
(LookupSelectors::StartEnd as usize..common_data.num_lookup_selectors)
.map(|r| {
let lut_row_number = ceil_div_usize(
common_data.luts[r - LookupSelectors::StartEnd as usize].len(),
num_lut_slots,
);
let lut_row_number = common_data.luts
[r - LookupSelectors::StartEnd as usize]
.len()
.div_ceil(num_lut_slots);
get_lut_poly(
common_data,
@ -676,7 +676,7 @@ fn compute_quotient_polys<
lut_re_poly_evals.iter().map(|v| v.as_slice()).collect();
let points_batches = points.par_chunks(BATCH_SIZE);
let num_batches = ceil_div_usize(points.len(), BATCH_SIZE);
let num_batches = points.len().div_ceil(BATCH_SIZE);
let quotient_values: Vec<Vec<F>> = points_batches
.enumerate()

View File

@ -3,7 +3,6 @@ use alloc::{format, vec, vec::Vec};
use core::cmp::min;
use plonky2_field::polynomial::PolynomialCoeffs;
use plonky2_util::ceil_div_usize;
use super::circuit_builder::{LookupChallenges, NUM_COINS_LOOKUP};
use super::vars::EvaluationVarsBase;
@ -345,7 +344,7 @@ pub fn check_lookup_constraints<F: RichField + Extendable<D>, const D: usize>(
let num_lut_slots = LookupTableGate::num_slots(&common_data.config);
let lu_degree = common_data.quotient_degree_factor - 1;
let num_sldc_polys = local_lookup_zs.len() - 1;
let lut_degree = ceil_div_usize(num_lut_slots, num_sldc_polys);
let lut_degree = num_lut_slots.div_ceil(num_sldc_polys);
let mut constraints = Vec::with_capacity(4 + common_data.luts.len() + 2 * num_sldc_polys);
@ -402,10 +401,9 @@ pub fn check_lookup_constraints<F: RichField + Extendable<D>, const D: usize>(
// Check final RE constraints for each different LUT.
for r in LookupSelectors::StartEnd as usize..common_data.num_lookup_selectors {
let cur_ends_selector = lookup_selectors[r];
let lut_row_number = ceil_div_usize(
common_data.luts[r - LookupSelectors::StartEnd as usize].len(),
num_lut_slots,
);
let lut_row_number = common_data.luts[r - LookupSelectors::StartEnd as usize]
.len()
.div_ceil(num_lut_slots);
let cur_function_eval = get_lut_poly(
common_data,
r - LookupSelectors::StartEnd as usize,
@ -519,7 +517,7 @@ pub fn check_lookup_constraints_batch<F: RichField + Extendable<D>, const D: usi
let num_lut_slots = LookupTableGate::num_slots(&common_data.config);
let lu_degree = common_data.quotient_degree_factor - 1;
let num_sldc_polys = local_lookup_zs.len() - 1;
let lut_degree = ceil_div_usize(num_lut_slots, num_sldc_polys);
let lut_degree = num_lut_slots.div_ceil(num_sldc_polys);
let mut constraints = Vec::with_capacity(4 + common_data.luts.len() + 2 * num_sldc_polys);
@ -931,7 +929,7 @@ pub fn check_lookup_constraints_circuit<F: RichField + Extendable<D>, const D: u
let num_lut_slots = LookupTableGate::num_slots(&common_data.config);
let lu_degree = common_data.quotient_degree_factor - 1;
let num_sldc_polys = local_lookup_zs.len() - 1;
let lut_degree = ceil_div_usize(num_lut_slots, num_sldc_polys);
let lut_degree = num_lut_slots.div_ceil(num_sldc_polys);
let mut constraints = Vec::with_capacity(4 + common_data.luts.len() + 2 * num_sldc_polys);
@ -1023,10 +1021,9 @@ pub fn check_lookup_constraints_circuit<F: RichField + Extendable<D>, const D: u
// Check final RE constraints for each different LUT.
for r in LookupSelectors::StartEnd as usize..common_data.num_lookup_selectors {
let cur_ends_selectors = lookup_selectors[r];
let lut_row_number = ceil_div_usize(
common_data.luts[r - LookupSelectors::StartEnd as usize].len(),
num_lut_slots,
);
let lut_row_number = common_data.luts[r - LookupSelectors::StartEnd as usize]
.len()
.div_ceil(num_lut_slots);
let cur_function_eval = get_lut_poly_circuit(
builder,
common_data,

View File

@ -8,7 +8,6 @@ use alloc::{
use hashbrown::HashMap;
use plonky2_field::extension::Extendable;
use plonky2_field::polynomial::PolynomialCoeffs;
use plonky2_util::ceil_div_usize;
use crate::fri::proof::{FriProof, FriProofTarget};
use crate::gadgets::polynomial::PolynomialCoeffsExtTarget;
@ -103,7 +102,7 @@ pub(crate) fn dummy_circuit<
// Number of `NoopGate`s to add to get a circuit of size `degree` in the end.
// Need to account for public input hashing, a `PublicInputGate` and a `ConstantGate`.
let degree = common_data.degree();
let num_noop_gate = degree - ceil_div_usize(common_data.num_public_inputs, 8) - 2;
let num_noop_gate = degree - common_data.num_public_inputs.div_ceil(8) - 2;
let mut builder = CircuitBuilder::<F, D>::new(config);
for _ in 0..num_noop_gate {

View File

@ -9,7 +9,6 @@ use crate::field::types::Field;
use crate::hash::hash_types::RichField;
use crate::iop::ext_target::ExtensionTarget;
use crate::plonk::circuit_builder::CircuitBuilder;
use crate::util::ceil_div_usize;
pub(crate) fn quotient_chunk_products<F: Field>(
quotient_values: &[F],
@ -41,10 +40,10 @@ pub(crate) fn partial_products_and_z_gx<F: Field>(z_x: F, quotient_chunk_product
pub(crate) fn num_partial_products(n: usize, max_degree: usize) -> usize {
debug_assert!(max_degree > 1);
let chunk_size = max_degree;
// We'll split the product into `ceil_div_usize(n, chunk_size)` chunks, but the last chunk will
// We'll split the product into `n.div_ceil( chunk_size)` chunks, but the last chunk will
// be associated with Z(gx) itself. Thus we subtract one to get the chunks associated with
// partial products.
ceil_div_usize(n, chunk_size) - 1
n.div_ceil(chunk_size) - 1
}
/// Checks the relationship between each pair of partial product accumulators. In particular, this

View File

@ -45,7 +45,6 @@ use plonky2::iop::ext_target::ExtensionTarget;
use plonky2::iop::target::Target;
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::config::GenericConfig;
use plonky2::util::ceil_div_usize;
use crate::config::StarkConfig;
use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
@ -125,7 +124,7 @@ impl<F: Field> CrossTableLookup<F> {
let num_appearances = all_tables.filter(|twc| twc.table == table).count();
let is_helpers = num_appearances > 1;
if is_helpers {
num_helpers_by_ctl[i] = ceil_div_usize(num_appearances, constraint_degree - 1);
num_helpers_by_ctl[i] = num_appearances.div_ceil(constraint_degree - 1);
num_helpers += num_helpers_by_ctl[i];
}
@ -292,7 +291,7 @@ pub(crate) fn num_ctl_helper_columns_by_table<F: Field, const N: usize>(
let sum = group.count();
if sum > 1 {
// We only need helper columns if there are at least 2 columns.
num_by_table[table] = ceil_div_usize(sum, constraint_degree - 1);
num_by_table[table] = sum.div_ceil(constraint_degree - 1);
}
}

View File

@ -24,7 +24,6 @@ use plonky2::plonk::plonk_common::{
reduce_with_powers, reduce_with_powers_circuit, reduce_with_powers_ext_circuit,
};
use plonky2::util::serialization::{Buffer, IoResult, Read, Write};
use plonky2_util::ceil_div_usize;
use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer};
use crate::evaluation_frame::StarkEvaluationFrame;
@ -441,10 +440,11 @@ impl<F: Field> Lookup<F> {
pub fn num_helper_columns(&self, constraint_degree: usize) -> usize {
// One helper column for each column batch of size `constraint_degree-1`,
// then one column for the inverse of `table + challenge` and one for the `Z` polynomial.
ceil_div_usize(
self.columns.len(),
constraint_degree.checked_sub(1).unwrap_or(1),
) + 1
self.columns
.len()
.div_ceil(constraint_degree.checked_sub(1).unwrap_or(1))
+ 1
}
}
@ -757,10 +757,9 @@ pub(crate) fn get_helper_cols<F: Field>(
challenge: GrandProductChallenge<F>,
constraint_degree: usize,
) -> Vec<PolynomialValues<F>> {
let num_helper_columns = ceil_div_usize(
columns_filters.len(),
constraint_degree.checked_sub(1).unwrap_or(1),
);
let num_helper_columns = columns_filters
.len()
.div_ceil(constraint_degree.checked_sub(1).unwrap_or(1));
let mut helper_columns = Vec::with_capacity(num_helper_columns);

View File

@ -16,10 +16,6 @@ pub const fn bits_u64(n: u64) -> usize {
(64 - n.leading_zeros()) as usize
}
pub const fn ceil_div_usize(a: usize, b: usize) -> usize {
(a + b - 1) / b
}
/// Computes `ceil(log_2(n))`.
#[must_use]
pub const fn log2_ceil(n: usize) -> usize {