From df49eb43d1d16e9c91203b1e334129c2684c6b09 Mon Sep 17 00:00:00 2001 From: AngusG Date: Mon, 26 Feb 2024 15:45:53 -0500 Subject: [PATCH 1/2] Currently errors on AVX compile (#265) Need to make some small updates to AVX code so it compiles on AVX again. --- baby-bear/src/x86_64_avx2.rs | 10 +++++++--- mersenne-31/src/x86_64_avx2.rs | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/baby-bear/src/x86_64_avx2.rs b/baby-bear/src/x86_64_avx2.rs index cd8427c9..4a778159 100644 --- a/baby-bear/src/x86_64_avx2.rs +++ b/baby-bear/src/x86_64_avx2.rs @@ -3,7 +3,7 @@ use core::iter::{Product, Sum}; use core::mem::transmute; use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; -use p3_field::{AbstractField, Field, PackedField}; +use p3_field::{AbstractField, Field, PackedField, PackedValue}; use rand::distributions::{Distribution, Standard}; use rand::Rng; @@ -604,8 +604,8 @@ fn interleave4(a: __m256i, b: __m256i) -> (__m256i, __m256i) { } } -unsafe impl PackedField for PackedBabyBearAVX2 { - type Scalar = BabyBear; +unsafe impl PackedValue for PackedBabyBearAVX2 { + type Value = BabyBear; const WIDTH: usize = WIDTH; @@ -645,6 +645,10 @@ unsafe impl PackedField for PackedBabyBearAVX2 { fn as_slice_mut(&mut self) -> &mut [BabyBear] { &mut self.0[..] } +} + +unsafe impl PackedField for PackedBabyBearAVX2 { + type Scalar = BabyBear; #[inline] fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { diff --git a/mersenne-31/src/x86_64_avx2.rs b/mersenne-31/src/x86_64_avx2.rs index 6a75d13a..4151002c 100644 --- a/mersenne-31/src/x86_64_avx2.rs +++ b/mersenne-31/src/x86_64_avx2.rs @@ -3,7 +3,7 @@ use core::iter::{Product, Sum}; use core::mem::transmute; use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; -use p3_field::{AbstractField, Field, PackedField}; +use p3_field::{AbstractField, Field, PackedField, PackedValue}; use rand::distributions::{Distribution, Standard}; use rand::Rng; @@ -578,8 +578,8 @@ fn interleave4(a: __m256i, b: __m256i) -> (__m256i, __m256i) { } } -unsafe impl PackedField for PackedMersenne31AVX2 { - type Scalar = Mersenne31; +unsafe impl PackedValue for PackedMersenne31AVX2 { + type Value = Mersenne31; const WIDTH: usize = WIDTH; @@ -619,6 +619,10 @@ unsafe impl PackedField for PackedMersenne31AVX2 { fn as_slice_mut(&mut self) -> &mut [Mersenne31] { &mut self.0[..] } +} + +unsafe impl PackedField for PackedMersenne31AVX2 { + type Scalar = Mersenne31; #[inline] fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { From fcb7aa0c104918524268ca443001747100d0dfa4 Mon Sep 17 00:00:00 2001 From: Daniel Lubarov Date: Mon, 26 Feb 2024 14:40:53 -0700 Subject: [PATCH 2/2] Rejection sampling for SerializingChallenger64 (#266) --- baby-bear/src/baby_bear.rs | 1 - brakedown/src/brakedown_code.rs | 1 - challenger/src/duplex_challenger.rs | 2 +- challenger/src/serializing_challenger.rs | 13 +++++++++---- field-testing/src/lib.rs | 2 +- fri/src/fold_even_odd.rs | 2 +- mersenne-31/src/dft.rs | 2 +- util/src/array_serialization.rs | 1 - 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/baby-bear/src/baby_bear.rs b/baby-bear/src/baby_bear.rs index 7f694403..88f03180 100644 --- a/baby-bear/src/baby_bear.rs +++ b/baby-bear/src/baby_bear.rs @@ -445,7 +445,6 @@ fn monty_reduce(x: u64) -> u32 { #[cfg(test)] mod tests { - use p3_field::PrimeField64; use p3_field_testing::{test_field, test_two_adic_field}; use super::*; diff --git a/brakedown/src/brakedown_code.rs b/brakedown/src/brakedown_code.rs index 50eda18c..d45ed10d 100644 --- a/brakedown/src/brakedown_code.rs +++ b/brakedown/src/brakedown_code.rs @@ -117,7 +117,6 @@ where #[cfg(test)] #[allow(deprecated)] // TODO: remove when `p3_lde::NaiveUndefinedLde` is gone mod tests { - use p3_matrix::Matrix; use p3_mersenne_31::Mersenne31; use rand::SeedableRng; use rand_chacha::ChaCha20Rng; diff --git a/challenger/src/duplex_challenger.rs b/challenger/src/duplex_challenger.rs index 60d29bea..6e9c57ac 100644 --- a/challenger/src/duplex_challenger.rs +++ b/challenger/src/duplex_challenger.rs @@ -139,7 +139,7 @@ where mod tests { use p3_field::AbstractField; use p3_goldilocks::Goldilocks; - use p3_symmetric::{CryptographicPermutation, Permutation}; + use p3_symmetric::Permutation; use super::*; diff --git a/challenger/src/serializing_challenger.rs b/challenger/src/serializing_challenger.rs index 4a408c61..57796e65 100644 --- a/challenger/src/serializing_challenger.rs +++ b/challenger/src/serializing_challenger.rs @@ -182,11 +182,16 @@ where Inner: CanSample, { fn sample(&mut self) -> EF { - let log_size = log2_ceil_u64(F::ORDER_U64).saturating_sub(1); - let bound = (1 << log_size) - 1; - let sample_base = |inner: &mut Inner| { + let modulus = F::ORDER_U64; + let log_size = log2_ceil_u64(F::ORDER_U64); + let pow_of_two_bound = (1 << log_size) - 1; + // Perform rejection sampling over the uniform range (0..log2_ceil(p)) + let sample_base = |inner: &mut Inner| loop { let value = u64::from_le_bytes(inner.sample_array::<8>()); - F::from_canonical_u64(value & bound) + let value = value & pow_of_two_bound; + if value < modulus { + return F::from_canonical_u64(value); + } }; EF::from_base_fn(|_| sample_base(&mut self.inner)) } diff --git a/field-testing/src/lib.rs b/field-testing/src/lib.rs index ce124611..107c0db4 100644 --- a/field-testing/src/lib.rs +++ b/field-testing/src/lib.rs @@ -178,7 +178,7 @@ mod tests { use p3_baby_bear::BabyBear; use p3_field::extension::{BinomialExtensionField, HasFrobenius}; use p3_field::{binomial_expand, eval_poly, AbstractExtensionField, AbstractField}; - use rand::{thread_rng, Rng}; + use rand::thread_rng; use super::*; diff --git a/fri/src/fold_even_odd.rs b/fri/src/fold_even_odd.rs index 7cdece35..b4c95aab 100644 --- a/fri/src/fold_even_odd.rs +++ b/fri/src/fold_even_odd.rs @@ -50,7 +50,7 @@ pub fn fold_even_odd(poly: Vec, beta: F) -> Vec { #[cfg(test)] mod tests { - use itertools::{izip, Itertools}; + use itertools::izip; use p3_baby_bear::BabyBear; use p3_dft::{Radix2Dit, TwoAdicSubgroupDft}; use rand::{thread_rng, Rng}; diff --git a/mersenne-31/src/dft.rs b/mersenne-31/src/dft.rs index 8b3d60cf..6bd44f52 100644 --- a/mersenne-31/src/dft.rs +++ b/mersenne-31/src/dft.rs @@ -183,7 +183,7 @@ mod tests { use rand::{thread_rng, Rng}; use super::*; - use crate::{Mersenne31, Mersenne31ComplexRadix2Dit}; + use crate::Mersenne31ComplexRadix2Dit; type Base = Mersenne31; type Dft = Mersenne31ComplexRadix2Dit; diff --git a/util/src/array_serialization.rs b/util/src/array_serialization.rs index 9aff03fd..1e6ea1e2 100644 --- a/util/src/array_serialization.rs +++ b/util/src/array_serialization.rs @@ -1,5 +1,4 @@ use alloc::vec::Vec; -use core::convert::TryInto; use core::marker::PhantomData; use serde::de::{SeqAccess, Visitor};