binius_field/arch/portable/
packed_2.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2024 Irreducible Inc.

use super::{
	packed::{impl_broadcast, impl_ops_for_zero_height, PackedPrimitiveType},
	packed_arithmetic::TowerConstants,
	reuse_multiply_arithmetic::Alpha,
};
use crate::{
	arch::{PackedStrategy, PairwiseStrategy, PairwiseTableStrategy, ReuseMultiplyStrategy},
	arithmetic_traits::{
		impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with,
		impl_transformation_with_strategy,
	},
	underlier::{UnderlierType, U2},
	BinaryField1b, BinaryField2b,
};

// Define 2 bit packed field types
pub type PackedBinaryField2x1b = PackedPrimitiveType<U2, BinaryField1b>;
pub type PackedBinaryField1x2b = PackedPrimitiveType<U2, BinaryField2b>;

// Define broadcast
impl_broadcast!(U2, BinaryField1b);
impl_broadcast!(U2, BinaryField2b);

// Define operations for height 0
impl_ops_for_zero_height!(PackedBinaryField2x1b);

// Define constants
impl TowerConstants<U2> for BinaryField1b {
	const ALPHAS_ODD: U2 = U2::new(<Self as TowerConstants<u8>>::ALPHAS_ODD);
}
impl TowerConstants<U2> for BinaryField2b {
	const ALPHAS_ODD: U2 = U2::new(<Self as TowerConstants<u8>>::ALPHAS_ODD);
}

// Define multiplication
impl_mul_with!(PackedBinaryField1x2b @ PairwiseTableStrategy);

// Define square
impl_square_with!(PackedBinaryField1x2b @ ReuseMultiplyStrategy);

// Define invert
impl_invert_with!(PackedBinaryField1x2b @ PairwiseTableStrategy);

// Define multiply by alpha
impl_mul_alpha_with!(PackedBinaryField1x2b @ ReuseMultiplyStrategy);

impl Alpha for PackedBinaryField1x2b {
	#[inline]
	fn alpha() -> Self {
		Self::from_underlier(U2::new_unchecked(0x02))
	}
}

// Define linear transformations
impl_transformation_with_strategy!(PackedBinaryField2x1b, PackedStrategy);
impl_transformation_with_strategy!(PackedBinaryField1x2b, PairwiseStrategy);