Skip to content

Commit

Permalink
Simple Renaming (Plonky3#328)
Browse files Browse the repository at this point in the history
BabyBear is written with a double capital in all other cases. Just getting DiffusionMatrixBabyBear to follow this convention.
  • Loading branch information
SyxtonPrime authored Apr 15, 2024
1 parent 0b83201 commit f12c361
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 79 deletions.
20 changes: 10 additions & 10 deletions baby-bear/src/aarch64_neon/poseidon2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use p3_poseidon2::{matmul_internal, DiffusionPermutation};
use p3_symmetric::Permutation;

use crate::{
BabyBear, DiffusionMatrixBabybear, PackedBabyBearNeon, MONTY_INVERSE,
BabyBear, DiffusionMatrixBabyBear, PackedBabyBearNeon, MONTY_INVERSE,
POSEIDON2_INTERNAL_MATRIX_DIAG_16_BABYBEAR_MONTY,
POSEIDON2_INTERNAL_MATRIX_DIAG_24_BABYBEAR_MONTY,
};
Expand All @@ -11,7 +11,7 @@ use crate::{
// matmul_internal internal performs a standard matrix multiplication so we need to additional rescale by the inverse monty constant.
// These will be removed once we have architecture specific implementations.

impl Permutation<[PackedBabyBearNeon; 16]> for DiffusionMatrixBabybear {
impl Permutation<[PackedBabyBearNeon; 16]> for DiffusionMatrixBabyBear {
fn permute_mut(&self, state: &mut [PackedBabyBearNeon; 16]) {
matmul_internal::<BabyBear, PackedBabyBearNeon, 16>(
state,
Expand All @@ -21,9 +21,9 @@ impl Permutation<[PackedBabyBearNeon; 16]> for DiffusionMatrixBabybear {
}
}

impl DiffusionPermutation<PackedBabyBearNeon, 16> for DiffusionMatrixBabybear {}
impl DiffusionPermutation<PackedBabyBearNeon, 16> for DiffusionMatrixBabyBear {}

impl Permutation<[PackedBabyBearNeon; 24]> for DiffusionMatrixBabybear {
impl Permutation<[PackedBabyBearNeon; 24]> for DiffusionMatrixBabyBear {
fn permute_mut(&self, state: &mut [PackedBabyBearNeon; 24]) {
matmul_internal::<BabyBear, PackedBabyBearNeon, 24>(
state,
Expand All @@ -33,7 +33,7 @@ impl Permutation<[PackedBabyBearNeon; 24]> for DiffusionMatrixBabybear {
}
}

impl DiffusionPermutation<PackedBabyBearNeon, 24> for DiffusionMatrixBabybear {}
impl DiffusionPermutation<PackedBabyBearNeon, 24> for DiffusionMatrixBabyBear {}

#[cfg(test)]
mod tests {
Expand All @@ -42,12 +42,12 @@ mod tests {
use p3_symmetric::Permutation;
use rand::Rng;

use crate::{BabyBear, DiffusionMatrixBabybear, PackedBabyBearNeon};
use crate::{BabyBear, DiffusionMatrixBabyBear, PackedBabyBearNeon};

type F = BabyBear;
const D: u64 = 7;
type Perm16 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabybear, 16, D>;
type Perm24 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabybear, 24, D>;
type Perm16 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, 16, D>;
type Perm24 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, 24, D>;

/// Test that the output is the same as the scalar version on a random input.
#[test]
Expand All @@ -57,7 +57,7 @@ mod tests {
// Our Poseidon2 implementation.
let poseidon2 = Perm16::new_from_rng_128(
Poseidon2ExternalMatrixGeneral,
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
&mut rng,
);

Expand All @@ -82,7 +82,7 @@ mod tests {
// Our Poseidon2 implementation.
let poseidon2 = Perm24::new_from_rng_128(
Poseidon2ExternalMatrixGeneral,
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
&mut rng,
);

Expand Down
28 changes: 14 additions & 14 deletions baby-bear/src/poseidon2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ const POSEIDON2_INTERNAL_MATRIX_DIAG_24_MONTY_SHIFTS: [u8; 23] = [
];

#[derive(Debug, Clone, Default)]
pub struct DiffusionMatrixBabybear;
pub struct DiffusionMatrixBabyBear;

impl Permutation<[BabyBear; 16]> for DiffusionMatrixBabybear {
impl Permutation<[BabyBear; 16]> for DiffusionMatrixBabyBear {
#[inline]
fn permute_mut(&self, state: &mut [BabyBear; 16]) {
let part_sum: u64 = state.iter().skip(1).map(|x| x.value as u64).sum();
Expand All @@ -107,9 +107,9 @@ impl Permutation<[BabyBear; 16]> for DiffusionMatrixBabybear {
}
}

impl DiffusionPermutation<BabyBear, 16> for DiffusionMatrixBabybear {}
impl DiffusionPermutation<BabyBear, 16> for DiffusionMatrixBabyBear {}

impl Permutation<[BabyBear; 24]> for DiffusionMatrixBabybear {
impl Permutation<[BabyBear; 24]> for DiffusionMatrixBabyBear {
#[inline]
fn permute_mut(&self, state: &mut [BabyBear; 24]) {
let part_sum: u64 = state.iter().skip(1).map(|x| x.value as u64).sum();
Expand All @@ -129,18 +129,18 @@ impl Permutation<[BabyBear; 24]> for DiffusionMatrixBabybear {
}
}

impl DiffusionPermutation<BabyBear, 24> for DiffusionMatrixBabybear {}
impl DiffusionPermutation<BabyBear, 24> for DiffusionMatrixBabyBear {}

#[derive(Debug, Clone, Default)]
pub struct DiffusionMatrixBabybearHL;
pub struct DiffusionMatrixBabyBearHL;

impl Permutation<[BabyBear; 16]> for DiffusionMatrixBabybearHL {
impl Permutation<[BabyBear; 16]> for DiffusionMatrixBabyBearHL {
fn permute_mut(&self, state: &mut [BabyBear; 16]) {
matmul_internal::<BabyBear, BabyBear, 16>(state, MATRIX_DIAG_16_BABYBEAR_MONTY_HL);
}
}

impl DiffusionPermutation<BabyBear, 16> for DiffusionMatrixBabybearHL {}
impl DiffusionPermutation<BabyBear, 16> for DiffusionMatrixBabyBearHL {}

pub const HL_BABYBEAR_16_EXTERNAL_ROUND_CONSTANTS: [[BabyBear; 16]; 8] = [
to_babybear_array([
Expand Down Expand Up @@ -213,7 +213,7 @@ mod tests {
let poseidon2: Poseidon2<
BabyBear,
Poseidon2ExternalMatrixHL,
DiffusionMatrixBabybearHL,
DiffusionMatrixBabyBearHL,
WIDTH,
D,
> = Poseidon2::new(
Expand All @@ -222,7 +222,7 @@ mod tests {
Poseidon2ExternalMatrixHL,
ROUNDS_P,
HL_BABYBEAR_16_INTERNAL_ROUND_CONSTANTS.to_vec(),
DiffusionMatrixBabybearHL,
DiffusionMatrixBabyBearHL,
);
poseidon2.permute_mut(input);
}
Expand All @@ -247,7 +247,7 @@ mod tests {
let poseidon2: Poseidon2<
BabyBear,
Poseidon2ExternalMatrixGeneral,
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
WIDTH,
D,
> = Poseidon2::new(
Expand All @@ -256,7 +256,7 @@ mod tests {
Poseidon2ExternalMatrixGeneral,
ROUNDS_P,
internal_round_constants.to_vec(),
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
);
poseidon2.permute_mut(input);
}
Expand All @@ -281,7 +281,7 @@ mod tests {
let poseidon2: Poseidon2<
BabyBear,
Poseidon2ExternalMatrixGeneral,
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
WIDTH,
D,
> = Poseidon2::new(
Expand All @@ -290,7 +290,7 @@ mod tests {
Poseidon2ExternalMatrixGeneral,
ROUNDS_P,
internal_round_constants.to_vec(),
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
);
poseidon2.permute_mut(input);
}
Expand Down
20 changes: 10 additions & 10 deletions baby-bear/src/x86_64_avx2/poseidon2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use p3_poseidon2::{matmul_internal, DiffusionPermutation};
use p3_symmetric::Permutation;

use crate::{
BabyBear, DiffusionMatrixBabybear, PackedBabyBearAVX2, MONTY_INVERSE,
BabyBear, DiffusionMatrixBabyBear, PackedBabyBearAVX2, MONTY_INVERSE,
POSEIDON2_INTERNAL_MATRIX_DIAG_16_BABYBEAR_MONTY,
POSEIDON2_INTERNAL_MATRIX_DIAG_24_BABYBEAR_MONTY,
};
Expand All @@ -11,7 +11,7 @@ use crate::{
// matmul_internal internal performs a standard matrix multiplication so we need to additional rescale by the inverse monty constant.
// These will be removed once we have architecture specific implementations.

impl Permutation<[PackedBabyBearAVX2; 16]> for DiffusionMatrixBabybear {
impl Permutation<[PackedBabyBearAVX2; 16]> for DiffusionMatrixBabyBear {
fn permute_mut(&self, state: &mut [PackedBabyBearAVX2; 16]) {
matmul_internal::<BabyBear, PackedBabyBearAVX2, 16>(
state,
Expand All @@ -21,9 +21,9 @@ impl Permutation<[PackedBabyBearAVX2; 16]> for DiffusionMatrixBabybear {
}
}

impl DiffusionPermutation<PackedBabyBearAVX2, 16> for DiffusionMatrixBabybear {}
impl DiffusionPermutation<PackedBabyBearAVX2, 16> for DiffusionMatrixBabyBear {}

impl Permutation<[PackedBabyBearAVX2; 24]> for DiffusionMatrixBabybear {
impl Permutation<[PackedBabyBearAVX2; 24]> for DiffusionMatrixBabyBear {
fn permute_mut(&self, state: &mut [PackedBabyBearAVX2; 24]) {
matmul_internal::<BabyBear, PackedBabyBearAVX2, 24>(
state,
Expand All @@ -33,7 +33,7 @@ impl Permutation<[PackedBabyBearAVX2; 24]> for DiffusionMatrixBabybear {
}
}

impl DiffusionPermutation<PackedBabyBearAVX2, 24> for DiffusionMatrixBabybear {}
impl DiffusionPermutation<PackedBabyBearAVX2, 24> for DiffusionMatrixBabyBear {}

#[cfg(test)]
mod tests {
Expand All @@ -42,12 +42,12 @@ mod tests {
use p3_symmetric::Permutation;
use rand::Rng;

use crate::{BabyBear, DiffusionMatrixBabybear, PackedBabyBearAVX2};
use crate::{BabyBear, DiffusionMatrixBabyBear, PackedBabyBearAVX2};

type F = BabyBear;
const D: u64 = 7;
type Perm16 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabybear, 16, D>;
type Perm24 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabybear, 24, D>;
type Perm16 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, 16, D>;
type Perm24 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, 24, D>;

/// Test that the output is the same as the scalar version on a random input.
#[test]
Expand All @@ -57,7 +57,7 @@ mod tests {
// Our Poseidon2 implementation.
let poseidon2 = Perm16::new_from_rng_128(
Poseidon2ExternalMatrixGeneral,
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
&mut rng,
);

Expand All @@ -82,7 +82,7 @@ mod tests {
// Our Poseidon2 implementation.
let poseidon2 = Perm24::new_from_rng_128(
Poseidon2ExternalMatrixGeneral,
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
&mut rng,
);

Expand Down
20 changes: 10 additions & 10 deletions baby-bear/src/x86_64_avx512/poseidon2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use p3_poseidon2::{matmul_internal, DiffusionPermutation};
use p3_symmetric::Permutation;

use crate::{
BabyBear, DiffusionMatrixBabybear, PackedBabyBearAVX512, MONTY_INVERSE,
BabyBear, DiffusionMatrixBabyBear, PackedBabyBearAVX512, MONTY_INVERSE,
POSEIDON2_INTERNAL_MATRIX_DIAG_16_BABYBEAR_MONTY,
POSEIDON2_INTERNAL_MATRIX_DIAG_24_BABYBEAR_MONTY,
};
Expand All @@ -11,7 +11,7 @@ use crate::{
// matmul_internal internal performs a standard matrix multiplication so we need to additional rescale by the inverse monty constant.
// These will be removed once we have architecture specific implementations.

impl Permutation<[PackedBabyBearAVX512; 16]> for DiffusionMatrixBabybear {
impl Permutation<[PackedBabyBearAVX512; 16]> for DiffusionMatrixBabyBear {
fn permute_mut(&self, state: &mut [PackedBabyBearAVX512; 16]) {
matmul_internal::<BabyBear, PackedBabyBearAVX512, 16>(
state,
Expand All @@ -21,9 +21,9 @@ impl Permutation<[PackedBabyBearAVX512; 16]> for DiffusionMatrixBabybear {
}
}

impl DiffusionPermutation<PackedBabyBearAVX512, 16> for DiffusionMatrixBabybear {}
impl DiffusionPermutation<PackedBabyBearAVX512, 16> for DiffusionMatrixBabyBear {}

impl Permutation<[PackedBabyBearAVX512; 24]> for DiffusionMatrixBabybear {
impl Permutation<[PackedBabyBearAVX512; 24]> for DiffusionMatrixBabyBear {
fn permute_mut(&self, state: &mut [PackedBabyBearAVX512; 24]) {
matmul_internal::<BabyBear, PackedBabyBearAVX512, 24>(
state,
Expand All @@ -33,7 +33,7 @@ impl Permutation<[PackedBabyBearAVX512; 24]> for DiffusionMatrixBabybear {
}
}

impl DiffusionPermutation<PackedBabyBearAVX512, 24> for DiffusionMatrixBabybear {}
impl DiffusionPermutation<PackedBabyBearAVX512, 24> for DiffusionMatrixBabyBear {}

#[cfg(test)]
mod tests {
Expand All @@ -42,12 +42,12 @@ mod tests {
use p3_symmetric::Permutation;
use rand::Rng;

use crate::{BabyBear, DiffusionMatrixBabybear, PackedBabyBearAVX512};
use crate::{BabyBear, DiffusionMatrixBabyBear, PackedBabyBearAVX512};

type F = BabyBear;
const D: u64 = 7;
type Perm16 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabybear, 16, D>;
type Perm24 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabybear, 24, D>;
type Perm16 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, 16, D>;
type Perm24 = Poseidon2<F, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, 24, D>;

/// Test that the output is the same as the scalar version on a random input.
#[test]
Expand All @@ -57,7 +57,7 @@ mod tests {
// Our Poseidon2 implementation.
let poseidon2 = Perm16::new_from_rng_128(
Poseidon2ExternalMatrixGeneral,
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
&mut rng,
);

Expand All @@ -82,7 +82,7 @@ mod tests {
// Our Poseidon2 implementation.
let poseidon2 = Perm24::new_from_rng_128(
Poseidon2ExternalMatrixGeneral,
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
&mut rng,
);

Expand Down
6 changes: 3 additions & 3 deletions fri/tests/fri.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use itertools::Itertools;
use p3_baby_bear::{BabyBear, DiffusionMatrixBabybear};
use p3_baby_bear::{BabyBear, DiffusionMatrixBabyBear};
use p3_challenger::{CanSampleBits, DuplexChallenger, FieldChallenger};
use p3_commit::ExtensionMmcs;
use p3_dft::{Radix2Dit, TwoAdicSubgroupDft};
Expand All @@ -19,7 +19,7 @@ use rand_chacha::ChaCha20Rng;
type Val = BabyBear;
type Challenge = BinomialExtensionField<Val, 4>;

type Perm = Poseidon2<Val, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabybear, 16, 7>;
type Perm = Poseidon2<Val, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, 16, 7>;
type MyHash = PaddingFreeSponge<Perm, 16, 8, 8>;
type MyCompress = TruncatedPermutation<Perm, 2, 8, 16>;
type ValMmcs =
Expand All @@ -29,7 +29,7 @@ type Challenger = DuplexChallenger<Val, Perm, 16>;
type MyFriConfig = FriConfig<ChallengeMmcs>;

fn get_ldt_for_testing<R: Rng>(rng: &mut R) -> (Perm, MyFriConfig) {
let perm = Perm::new_from_rng_128(Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabybear, rng);
let perm = Perm::new_from_rng_128(Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, rng);
let hash = MyHash::new(perm.clone());
let compress = MyCompress::new(perm.clone());
let mmcs = ChallengeMmcs::new(ValMmcs::new(hash, compress));
Expand Down
6 changes: 3 additions & 3 deletions fri/tests/pcs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use itertools::{izip, Itertools};
use p3_baby_bear::{BabyBear, DiffusionMatrixBabybear};
use p3_baby_bear::{BabyBear, DiffusionMatrixBabyBear};
use p3_challenger::{CanObserve, DuplexChallenger, FieldChallenger};
use p3_commit::{ExtensionMmcs, Pcs};
use p3_dft::Radix2DitParallel;
Expand All @@ -15,7 +15,7 @@ use rand::thread_rng;
type Val = BabyBear;
type Challenge = BinomialExtensionField<Val, 4>;

type Perm = Poseidon2<Val, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabybear, 16, 7>;
type Perm = Poseidon2<Val, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, 16, 7>;
type MyHash = PaddingFreeSponge<Perm, 16, 8, 8>;
type MyCompress = TruncatedPermutation<Perm, 2, 8, 16>;

Expand All @@ -36,7 +36,7 @@ fn make_test_fri_pcs(log_degrees_by_round: &[&[usize]]) {

let perm = Perm::new_from_rng_128(
Poseidon2ExternalMatrixGeneral,
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
&mut rng,
);
let hash = MyHash::new(perm.clone());
Expand Down
6 changes: 3 additions & 3 deletions keccak-air/examples/prove_baby_bear_poseidon2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use p3_baby_bear::{BabyBear, DiffusionMatrixBabybear};
use p3_baby_bear::{BabyBear, DiffusionMatrixBabyBear};
use p3_challenger::DuplexChallenger;
use p3_commit::ExtensionMmcs;
use p3_dft::Radix2DitParallel;
Expand Down Expand Up @@ -34,10 +34,10 @@ fn main() -> Result<(), VerificationError> {
type Val = BabyBear;
type Challenge = BinomialExtensionField<Val, 4>;

type Perm = Poseidon2<Val, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabybear, 16, 7>;
type Perm = Poseidon2<Val, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, 16, 7>;
let perm = Perm::new_from_rng_128(
Poseidon2ExternalMatrixGeneral,
DiffusionMatrixBabybear,
DiffusionMatrixBabyBear,
&mut thread_rng(),
);

Expand Down
Loading

0 comments on commit f12c361

Please sign in to comment.