Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
pull upstream main, fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Schaeff committed Sep 12, 2024
2 parents 6afe4f7 + 2df15fd commit 1091e1d
Show file tree
Hide file tree
Showing 63 changed files with 2,443 additions and 449 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
"monty-31",
"poseidon",
"poseidon2",
"poseidon2-air",
"rescue",
"sha256",
"symmetric",
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion baby-bear/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ p3-mds = { path = "../mds" }
p3-monty-31 = { path = "../monty-31" }
p3-poseidon2 = { path = "../poseidon2" }
p3-symmetric = { path = "../symmetric" }
num-bigint = { version = "0.4.3", default-features = false }
rand = "0.8.5"
serde = { version = "1.0", default-features = false, features = ["derive"] }

[dev-dependencies]
p3-field-testing = { path = "../field-testing" }
p3-dft = { path = "../dft" }
rand = { version = "0.8.5", features = ["min_const_gen"] }
criterion = "0.5.1"
rand_chacha = "0.3.1"
Expand Down
24 changes: 21 additions & 3 deletions baby-bear/benches/bench_field.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::any::type_name;

use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use p3_baby_bear::BabyBear;
use p3_field::AbstractField;
use p3_field::{AbstractField, Field};
use p3_field_testing::bench_func::{
benchmark_add_latency, benchmark_add_throughput, benchmark_inv, benchmark_iter_sum,
benchmark_sub_latency, benchmark_sub_throughput,
benchmark_mul_latency, benchmark_mul_throughput, benchmark_sub_latency,
benchmark_sub_throughput,
};

type F = BabyBear;
Expand Down Expand Up @@ -33,5 +36,20 @@ fn bench_field(c: &mut Criterion) {
});
}

criterion_group!(baby_bear_arithmetic, bench_field);
fn bench_packedfield(c: &mut Criterion) {
let name = type_name::<<F as Field>::Packing>().to_string();
// Note that each round of throughput has 10 operations
// So we should have 10 * more repetitions for latency tests.
const REPS: usize = 100;
const L_REPS: usize = 10 * REPS;

benchmark_add_latency::<<F as Field>::Packing, L_REPS>(c, &name);
benchmark_add_throughput::<<F as Field>::Packing, REPS>(c, &name);
benchmark_sub_latency::<<F as Field>::Packing, L_REPS>(c, &name);
benchmark_sub_throughput::<<F as Field>::Packing, REPS>(c, &name);
benchmark_mul_latency::<<F as Field>::Packing, L_REPS>(c, &name);
benchmark_mul_throughput::<<F as Field>::Packing, REPS>(c, &name);
}

criterion_group!(baby_bear_arithmetic, bench_field, bench_packedfield);
criterion_main!(baby_bear_arithmetic);
15 changes: 12 additions & 3 deletions baby-bear/benches/extension.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
use criterion::{criterion_group, criterion_main, Criterion};
use p3_baby_bear::BabyBear;
use p3_field::extension::BinomialExtensionField;
use p3_field_testing::bench_func::{benchmark_inv, benchmark_mul, benchmark_square};
use p3_field_testing::bench_func::{
benchmark_inv, benchmark_mul_latency, benchmark_mul_throughput, benchmark_square,
};

type EF4 = BinomialExtensionField<BabyBear, 4>;
type EF5 = BinomialExtensionField<BabyBear, 5>;

// Note that each round of throughput has 10 operations
// So we should have 10 * more repetitions for latency tests.
const REPS: usize = 100;
const L_REPS: usize = 10 * REPS;

fn bench_quartic_extension(c: &mut Criterion) {
let name = "BinomialExtensionField<BabyBear, 4>";
benchmark_square::<EF4>(c, name);
benchmark_inv::<EF4>(c, name);
benchmark_mul::<EF4>(c, name);
benchmark_mul_throughput::<EF4, REPS>(c, name);
benchmark_mul_latency::<EF4, L_REPS>(c, name);
}

fn bench_qunitic_extension(c: &mut Criterion) {
let name = "BinomialExtensionField<BabyBear, 5>";
benchmark_square::<EF5>(c, name);
benchmark_inv::<EF5>(c, name);
benchmark_mul::<EF5>(c, name);
benchmark_mul_throughput::<EF5, REPS>(c, name);
benchmark_mul_latency::<EF5, L_REPS>(c, name);
}

criterion_group!(
Expand Down
38 changes: 1 addition & 37 deletions baby-bear/src/aarch64_neon/packing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ pub type PackedBabyBearNeon = PackedMontyField31Neon<BabyBearParameters>;

#[cfg(test)]
mod tests {
use p3_field::AbstractField;
use p3_field_testing::test_packed_field;
use p3_monty_31::PackedMontyField31Neon;

use super::WIDTH;
use crate::{BabyBear, BabyBearParameters};
use crate::BabyBear;

const SPECIAL_VALS: [BabyBear; WIDTH] =
BabyBear::new_array([0x00000000, 0x00000001, 0x00000002, 0x78000000]);
Expand All @@ -32,38 +30,4 @@ mod tests {
crate::PackedBabyBearNeon::zero(),
p3_monty_31::PackedMontyField31Neon::<crate::BabyBearParameters>(super::SPECIAL_VALS)
);

#[test]
fn test_cube_vs_mul() {
let vec = PackedMontyField31Neon::<BabyBearParameters>(BabyBear::new_array([
0x4efd5eaf, 0x311b8e0c, 0x74dd27c1, 0x449613f0,
]));
let res0 = vec * vec.square();
let res1 = vec.cube();
assert_eq!(res0, res1);
}

#[test]
fn test_cube_vs_scalar() {
let arr = BabyBear::new_array([0x57155037, 0x71bdcc8e, 0x301f94d, 0x435938a6]);

let vec = PackedMontyField31Neon::<BabyBearParameters>(arr);
let vec_res = vec.cube();

#[allow(clippy::needless_range_loop)]
for i in 0..WIDTH {
assert_eq!(vec_res.0[i], arr[i].cube());
}
}

#[test]
fn test_cube_vs_scalar_special_vals() {
let vec = PackedMontyField31Neon::<BabyBearParameters>(SPECIAL_VALS);
let vec_res = vec.cube();

#[allow(clippy::needless_range_loop)]
for i in 0..WIDTH {
assert_eq!(vec_res.0[i], SPECIAL_VALS[i].cube());
}
}
}
27 changes: 23 additions & 4 deletions baby-bear/src/baby_bear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,24 @@ impl FieldParameters for BabyBearParameters {
impl TwoAdicData for BabyBearParameters {
const TWO_ADICITY: usize = 27;

type ArrayLike = [BabyBear; Self::TWO_ADICITY + 1];
type ArrayLike = &'static [BabyBear];

const TWO_ADIC_GENERATORS: Self::ArrayLike = BabyBear::new_array([
const TWO_ADIC_GENERATORS: Self::ArrayLike = &BabyBear::new_array([
0x1, 0x78000000, 0x67055c21, 0x5ee99486, 0xbb4c4e4, 0x2d4cc4da, 0x669d6090, 0x17b56c64,
0x67456167, 0x688442f9, 0x145e952d, 0x4fe61226, 0x4c734715, 0x11c33e2a, 0x62c3d2b1,
0x77cad399, 0x54c131f4, 0x4cabd6a6, 0x5cf5713f, 0x3e9430e8, 0xba067a3, 0x18adc27d,
0x21fd55bc, 0x4b859b3d, 0x3bd57996, 0x4483d85a, 0x3a26eef8, 0x1a427a41,
]);

const ROOTS_8: Self::ArrayLike = &BabyBear::new_array([0x5ee99486, 0x67055c21, 0xc9ea3ba]);
const INV_ROOTS_8: Self::ArrayLike = &BabyBear::new_array([0x6b615c47, 0x10faa3e0, 0x19166b7b]);

const ROOTS_16: Self::ArrayLike = &BabyBear::new_array([
0xbb4c4e4, 0x5ee99486, 0x4b49e08, 0x67055c21, 0x5376917a, 0xc9ea3ba, 0x563112a7,
]);
const INV_ROOTS_16: Self::ArrayLike = &BabyBear::new_array([
0x21ceed5a, 0x6b615c47, 0x24896e87, 0x10faa3e0, 0x734b61f9, 0x19166b7b, 0x6c4b3b1d,
]);
}

impl BinomialExtensionData<4> for BabyBearParameters {
Expand Down Expand Up @@ -101,8 +111,8 @@ impl BinomialExtensionData<5> for BabyBearParameters {
mod tests {
use core::array;

use p3_field::{AbstractField, Field, PrimeField32, PrimeField64, TwoAdicField};
use p3_field_testing::{test_field, test_two_adic_field};
use p3_field::{PrimeField32, PrimeField64, TwoAdicField};
use p3_field_testing::{test_field, test_field_dft, test_two_adic_field};

use super::*;

Expand Down Expand Up @@ -215,4 +225,13 @@ mod tests {

test_field!(crate::BabyBear);
test_two_adic_field!(crate::BabyBear);

test_field_dft!(radix2dit, crate::BabyBear, p3_dft::Radix2Dit<_>);
test_field_dft!(bowers, crate::BabyBear, p3_dft::Radix2Bowers);
test_field_dft!(parallel, crate::BabyBear, p3_dft::Radix2DitParallel);
test_field_dft!(
recur_dft,
crate::BabyBear,
p3_monty_31::dft::RecursiveDft<_>
);
}
2 changes: 1 addition & 1 deletion bn254-fr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ff = { version = "0.13", features = ["derive", "derive_bits"] }
num-bigint = { version = "0.4.3", default-features = false }
rand = "0.8.5"
serde = { version = "1.0", default-features = false, features = ["derive"] }
halo2curves = { version = "0.6.1", features = ["bits", "derive_serde"] }
halo2curves = { version = "0.7.0", features = ["bits", "derive_serde"] }

[dev-dependencies]
p3-field-testing = { path = "../field-testing" }
Expand Down
1 change: 0 additions & 1 deletion circle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ p3-keccak = { path = "../keccak" }
p3-mds = { path = "../mds" }
p3-mersenne-31 = { path = "../mersenne-31" }
p3-merkle-tree = { path = "../merkle-tree" }
p3-poseidon = { path = "../poseidon" }
p3-symmetric = { path = "../symmetric" }

hashbrown = "0.14.3"
Expand Down
12 changes: 1 addition & 11 deletions circle/benches/cfft.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::any::type_name;

use criterion::measurement::Measurement;
use criterion::{criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion};
use p3_baby_bear::BabyBear;
Expand All @@ -8,18 +6,10 @@ use p3_dft::{Radix2Bowers, Radix2Dit, Radix2DitParallel, TwoAdicSubgroupDft};
use p3_field::TwoAdicField;
use p3_matrix::dense::RowMajorMatrix;
use p3_mersenne_31::Mersenne31;
use p3_util::pretty_name;
use rand::distributions::{Distribution, Standard};
use rand::thread_rng;

fn pretty_name<T>() -> String {
let name = type_name::<T>();
let mut result = String::new();
for qual in name.split_inclusive(&['<', '>', ',']) {
result.push_str(qual.split("::").last().unwrap());
}
result
}

fn bench_lde(c: &mut Criterion) {
let log_n = 18;
let log_w = 8;
Expand Down
1 change: 0 additions & 1 deletion circle/src/cfft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ pub fn circle_basis<F: Field>(p: Point<F>, log_n: usize) -> Vec<F> {
mod tests {
use itertools::iproduct;
use p3_field::extension::BinomialExtensionField;
use p3_matrix::dense::RowMajorMatrix;
use p3_mersenne_31::Mersenne31;
use rand::{random, thread_rng};

Expand Down
1 change: 0 additions & 1 deletion circle/src/folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ mod tests {
use itertools::iproduct;
use p3_field::extension::BinomialExtensionField;
use p3_matrix::dense::RowMajorMatrix;
use p3_matrix::Matrix;
use p3_mersenne_31::Mersenne31;
use rand::{random, thread_rng};

Expand Down
5 changes: 2 additions & 3 deletions circle/src/pcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use p3_matrix::{Dimensions, Matrix};
use p3_maybe_rayon::prelude::*;
use p3_util::log2_strict_usize;
use serde::{Deserialize, Serialize};
use tracing::{info_span, instrument};
use tracing::info_span;

use crate::deep_quotient::{deep_quotient_reduce_row, extract_lambda};
use crate::domain::CircleDomain;
Expand Down Expand Up @@ -131,7 +131,6 @@ where
}
}

#[instrument(skip_all)]
fn open(
&self,
// For each round,
Expand Down Expand Up @@ -468,7 +467,7 @@ where
#[cfg(test)]
mod tests {
use p3_challenger::{HashChallenger, SerializingChallenger32};
use p3_commit::{ExtensionMmcs, Pcs};
use p3_commit::ExtensionMmcs;
use p3_field::extension::BinomialExtensionField;
use p3_keccak::Keccak256Hash;
use p3_merkle_tree::FieldMerkleTreeMmcs;
Expand Down
1 change: 0 additions & 1 deletion commit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ serde = { version = "1.0", default-features = false }
p3-dft = { path = "../dft", optional = true }

[dev-dependencies]
p3-baby-bear = { path = "../baby-bear" }
p3-dft = { path = "../dft" }
rand = "0.8.5"
2 changes: 2 additions & 0 deletions dft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ p3-matrix = { path = "../matrix" }
p3-maybe-rayon = { path = "../maybe-rayon" }
p3-util = { path = "../util" }
tracing = "0.1.37"
itertools = "0.13.0"

[dev-dependencies]
p3-monty-31 = { path = "../monty-31" }
p3-baby-bear = { path = "../baby-bear" }
p3-goldilocks = { path = "../goldilocks" }
p3-mersenne-31 = { path = "../mersenne-31" }
Expand Down
Loading

0 comments on commit 1091e1d

Please sign in to comment.