mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-05 23:33:07 +00:00
Move to util and rename
This commit is contained in:
parent
e8eca780ae
commit
2a37aeca5d
@ -3,6 +3,7 @@ use std::ops::Range;
|
|||||||
use plonky2_field::extension::Extendable;
|
use plonky2_field::extension::Extendable;
|
||||||
use plonky2_field::packed::PackedField;
|
use plonky2_field::packed::PackedField;
|
||||||
use plonky2_field::types::{Field, Field64};
|
use plonky2_field::types::{Field, Field64};
|
||||||
|
use plonky2_util::log_floor;
|
||||||
|
|
||||||
use crate::gates::gate::Gate;
|
use crate::gates::gate::Gate;
|
||||||
use crate::gates::packed_util::PackedEvaluableBase;
|
use crate::gates::packed_util::PackedEvaluableBase;
|
||||||
@ -33,7 +34,7 @@ impl<const B: usize> BaseSumGate<B> {
|
|||||||
|
|
||||||
pub fn new_from_config<F: Field64>(config: &CircuitConfig) -> Self {
|
pub fn new_from_config<F: Field64>(config: &CircuitConfig) -> Self {
|
||||||
let num_limbs =
|
let num_limbs =
|
||||||
logarithm(F::ORDER as usize, B).min(config.num_routed_wires - Self::START_LIMBS);
|
log_floor(F::ORDER as usize, B).min(config.num_routed_wires - Self::START_LIMBS);
|
||||||
Self::new(num_limbs)
|
Self::new(num_limbs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,23 +194,6 @@ impl<F: RichField, const B: usize> SimpleGenerator<F> for BaseSplitGenerator<B>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the largest `i` such that `base**i < n`.
|
|
||||||
const fn logarithm(n: usize, base: usize) -> usize {
|
|
||||||
assert!(n > 0);
|
|
||||||
assert!(base > 1);
|
|
||||||
let mut i = 0;
|
|
||||||
let mut cur: usize = 1;
|
|
||||||
loop {
|
|
||||||
let (mul, overflow) = cur.overflowing_mul(base);
|
|
||||||
if overflow || mul >= n {
|
|
||||||
return i;
|
|
||||||
} else {
|
|
||||||
i += 1;
|
|
||||||
cur = mul;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|||||||
@ -38,6 +38,23 @@ pub fn log2_strict(n: usize) -> usize {
|
|||||||
res as usize
|
res as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the largest `i` such that `base**i < n`.
|
||||||
|
pub const fn log_floor(n: usize, base: usize) -> usize {
|
||||||
|
assert!(n > 0);
|
||||||
|
assert!(base > 1);
|
||||||
|
let mut i = 0;
|
||||||
|
let mut cur: usize = 1;
|
||||||
|
loop {
|
||||||
|
let (mul, overflow) = cur.overflowing_mul(base);
|
||||||
|
if overflow || mul >= n {
|
||||||
|
return i;
|
||||||
|
} else {
|
||||||
|
i += 1;
|
||||||
|
cur = mul;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Permutes `arr` such that each index is mapped to its reverse in binary.
|
/// Permutes `arr` such that each index is mapped to its reverse in binary.
|
||||||
pub fn reverse_index_bits<T: Copy>(arr: &[T]) -> Vec<T> {
|
pub fn reverse_index_bits<T: Copy>(arr: &[T]) -> Vec<T> {
|
||||||
let n = arr.len();
|
let n = arr.len();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user