binius_field/arch/portable/
packed_2.rs

1// Copyright 2024-2025 Irreducible Inc.
2
3use super::{
4	packed::{impl_broadcast, impl_ops_for_zero_height, PackedPrimitiveType},
5	packed_arithmetic::TowerConstants,
6	reuse_multiply_arithmetic::Alpha,
7};
8use crate::{
9	arch::{PackedStrategy, PairwiseStrategy, PairwiseTableStrategy, ReuseMultiplyStrategy},
10	arithmetic_traits::{
11		impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with,
12		impl_transformation_with_strategy,
13	},
14	underlier::{UnderlierType, U2},
15	BinaryField1b, BinaryField2b,
16};
17
18// Define 2 bit packed field types
19pub type PackedBinaryField2x1b = PackedPrimitiveType<U2, BinaryField1b>;
20pub type PackedBinaryField1x2b = PackedPrimitiveType<U2, BinaryField2b>;
21
22// Define broadcast
23impl_broadcast!(U2, BinaryField1b);
24impl_broadcast!(U2, BinaryField2b);
25
26// Define operations for height 0
27impl_ops_for_zero_height!(PackedBinaryField2x1b);
28
29// Define constants
30impl TowerConstants<U2> for BinaryField1b {
31	const ALPHAS_ODD: U2 = U2::new(<Self as TowerConstants<u8>>::ALPHAS_ODD);
32}
33impl TowerConstants<U2> for BinaryField2b {
34	const ALPHAS_ODD: U2 = U2::new(<Self as TowerConstants<u8>>::ALPHAS_ODD);
35}
36
37// Define multiplication
38impl_mul_with!(PackedBinaryField1x2b @ PairwiseTableStrategy);
39
40// Define square
41impl_square_with!(PackedBinaryField1x2b @ ReuseMultiplyStrategy);
42
43// Define invert
44impl_invert_with!(PackedBinaryField1x2b @ PairwiseTableStrategy);
45
46// Define multiply by alpha
47impl_mul_alpha_with!(PackedBinaryField1x2b @ ReuseMultiplyStrategy);
48
49impl Alpha for PackedBinaryField1x2b {
50	#[inline]
51	fn alpha() -> Self {
52		Self::from_underlier(U2::new_unchecked(0x02))
53	}
54}
55
56// Define linear transformations
57impl_transformation_with_strategy!(PackedBinaryField2x1b, PackedStrategy);
58impl_transformation_with_strategy!(PackedBinaryField1x2b, PairwiseStrategy);