diff --git a/plonky2/src/gadgets/split_join.rs b/plonky2/src/gadgets/split_join.rs index 2f35b94c77..d20c09bc5f 100644 --- a/plonky2/src/gadgets/split_join.rs +++ b/plonky2/src/gadgets/split_join.rs @@ -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, const D: usize> CircuitBuilder { @@ -26,7 +25,7 @@ impl, const D: usize> CircuitBuilder { return Vec::new(); } let gate_type = BaseSumGate::<2>::new_from_config::(&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::>(); diff --git a/plonky2/src/gates/lookup_table.rs b/plonky2/src/gates/lookup_table.rs index 28f47c4d8a..e7ead9aff3 100644 --- a/plonky2/src/gates/lookup_table.rs +++ b/plonky2/src/gates/lookup_table.rs @@ -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, const D: usize> SimpleGenerator for Loo } fn run_once(&self, _witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - 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 = diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index de3ab16fdf..5f153c637e 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -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, const D: usize> CircuitBuilder { 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(); diff --git a/plonky2/src/plonk/prover.rs b/plonky2/src/plonk/prover.rs index 400845bc6f..3001e60eb6 100644 --- a/plonky2/src/plonk/prover.rs +++ b/plonky2/src/plonk/prover.rs @@ -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> = points_batches .enumerate() diff --git a/plonky2/src/plonk/vanishing_poly.rs b/plonky2/src/plonk/vanishing_poly.rs index 9eb7252e1a..ef10108106 100644 --- a/plonky2/src/plonk/vanishing_poly.rs +++ b/plonky2/src/plonk/vanishing_poly.rs @@ -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, 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, 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, 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, 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, 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, diff --git a/plonky2/src/recursion/dummy_circuit.rs b/plonky2/src/recursion/dummy_circuit.rs index 501a475f1b..75b3929e82 100644 --- a/plonky2/src/recursion/dummy_circuit.rs +++ b/plonky2/src/recursion/dummy_circuit.rs @@ -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::::new(config); for _ in 0..num_noop_gate { diff --git a/plonky2/src/util/partial_products.rs b/plonky2/src/util/partial_products.rs index 1ceea7cab1..ac02188fd8 100644 --- a/plonky2/src/util/partial_products.rs +++ b/plonky2/src/util/partial_products.rs @@ -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( quotient_values: &[F], @@ -41,10 +40,10 @@ pub(crate) fn partial_products_and_z_gx(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 diff --git a/starky/src/cross_table_lookup.rs b/starky/src/cross_table_lookup.rs index d0b020a6a0..73caf28cc8 100644 --- a/starky/src/cross_table_lookup.rs +++ b/starky/src/cross_table_lookup.rs @@ -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 CrossTableLookup { 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( 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); } } diff --git a/starky/src/lookup.rs b/starky/src/lookup.rs index f63c4bd76c..2a90e6b93e 100644 --- a/starky/src/lookup.rs +++ b/starky/src/lookup.rs @@ -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 Lookup { 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( challenge: GrandProductChallenge, constraint_degree: usize, ) -> Vec> { - 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); diff --git a/util/src/lib.rs b/util/src/lib.rs index 613bf6ef5a..687e9237f8 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -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 {