binius_field/arch/portable/
packed_8.rs

1// Copyright 2024-2025 Irreducible Inc.
2
3use super::{
4	packed::{impl_broadcast, impl_ops_for_zero_height, PackedPrimitiveType},
5	packed_arithmetic::{alphas, impl_tower_constants},
6};
7use crate::{
8	arch::{PackedStrategy, PairwiseRecursiveStrategy, PairwiseStrategy, PairwiseTableStrategy},
9	arithmetic_traits::{
10		impl_invert_with, impl_mul_alpha_with, impl_mul_with, impl_square_with,
11		impl_transformation_with_strategy,
12	},
13	BinaryField1b, BinaryField2b, BinaryField4b, BinaryField8b,
14};
15
16// Define 8 bit packed field types
17pub type PackedBinaryField8x1b = PackedPrimitiveType<u8, BinaryField1b>;
18pub type PackedBinaryField4x2b = PackedPrimitiveType<u8, BinaryField2b>;
19pub type PackedBinaryField2x4b = PackedPrimitiveType<u8, BinaryField4b>;
20pub type PackedBinaryField1x8b = PackedPrimitiveType<u8, BinaryField8b>;
21
22// Define broadcast
23impl_broadcast!(u8, BinaryField1b);
24impl_broadcast!(u8, BinaryField2b);
25impl_broadcast!(u8, BinaryField4b);
26impl_broadcast!(u8, BinaryField8b);
27
28// Define operations for height 0
29impl_ops_for_zero_height!(PackedBinaryField8x1b);
30
31// Define constants
32impl_tower_constants!(BinaryField1b, u8, { alphas!(u8, 0) });
33impl_tower_constants!(BinaryField2b, u8, { alphas!(u8, 1) });
34impl_tower_constants!(BinaryField4b, u8, { alphas!(u8, 2) });
35
36// Define multiplication
37impl_mul_with!(PackedBinaryField4x2b @ PackedStrategy);
38impl_mul_with!(PackedBinaryField2x4b @ PackedStrategy);
39impl_mul_with!(PackedBinaryField1x8b @ PairwiseTableStrategy);
40
41// Define square
42impl_square_with!(PackedBinaryField4x2b @ PackedStrategy);
43impl_square_with!(PackedBinaryField2x4b @ PackedStrategy);
44impl_square_with!(PackedBinaryField1x8b @ PairwiseTableStrategy);
45
46// Define invert
47impl_invert_with!(PackedBinaryField4x2b @ PairwiseRecursiveStrategy);
48impl_invert_with!(PackedBinaryField2x4b @ PairwiseRecursiveStrategy);
49impl_invert_with!(PackedBinaryField1x8b @ PairwiseTableStrategy);
50
51// Define multiply by alpha
52impl_mul_alpha_with!(PackedBinaryField4x2b @ PackedStrategy);
53impl_mul_alpha_with!(PackedBinaryField2x4b @ PackedStrategy);
54impl_mul_alpha_with!(PackedBinaryField1x8b @ PairwiseTableStrategy);
55
56// Define linear transformations
57impl_transformation_with_strategy!(PackedBinaryField8x1b, PackedStrategy);
58impl_transformation_with_strategy!(PackedBinaryField4x2b, PackedStrategy);
59impl_transformation_with_strategy!(PackedBinaryField2x4b, PackedStrategy);
60impl_transformation_with_strategy!(PackedBinaryField1x8b, PairwiseStrategy);