binius_field/arch/portable/
packed_2.rs

1// Copyright 2024-2025 Irreducible Inc.
2
3use super::{
4	packed::PackedPrimitiveType, packed_arithmetic::TowerConstants,
5	reuse_multiply_arithmetic::Alpha,
6};
7use crate::{
8	BinaryField1b, BinaryField2b,
9	arch::portable::packed_macros::{portable_macros::*, *},
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::{U2, UnderlierType},
15};
16
17define_packed_binary_fields!(
18	underlier: U2,
19	packed_fields: [
20		packed_field {
21			name: PackedBinaryField2x1b,
22			scalar: BinaryField1b,
23			alpha_idx: _,
24			mul: (None),
25			square: (None),
26			invert: (None),
27			mul_alpha: (None),
28			transform: (PackedStrategy),
29		},
30		packed_field {
31			name: PackedBinaryField1x2b,
32			scalar: BinaryField2b,
33			alpha_idx: _,
34			mul: (PairwiseTableStrategy),
35			square: (ReuseMultiplyStrategy),
36			invert: (PairwiseTableStrategy),
37			mul_alpha: (ReuseMultiplyStrategy),
38			transform: (PairwiseStrategy),
39		}
40	]
41);
42
43// Define operations for height 0
44impl_ops_for_zero_height!(PackedBinaryField2x1b);
45
46// Define constants
47impl TowerConstants<U2> for BinaryField1b {
48	const ALPHAS_ODD: U2 = U2::new(<Self as TowerConstants<u8>>::ALPHAS_ODD);
49}
50impl TowerConstants<U2> for BinaryField2b {
51	const ALPHAS_ODD: U2 = U2::new(<Self as TowerConstants<u8>>::ALPHAS_ODD);
52}
53
54// Define multiply by alpha
55impl Alpha for PackedBinaryField1x2b {
56	#[inline]
57	fn alpha() -> Self {
58		Self::from_underlier(U2::new_unchecked(0x02))
59	}
60}