binius_field/
packed_polyval.rs1pub use crate::arch::{
4 packed_polyval_128::PackedBinaryPolyval1x128b, packed_polyval_256::PackedBinaryPolyval2x128b,
5 packed_polyval_512::PackedBinaryPolyval4x128b,
6};
7
8#[cfg(test)]
9mod test_utils {
10 macro_rules! define_multiply_tests {
13 ($mult_func:path, $constraint:ty) => {
14 $crate::packed_binary_field::test_utils::define_check_packed_mul!(
15 $mult_func,
16 $constraint
17 );
18
19 proptest! {
20 #[test]
21 fn test_mul_packed_128(a_val in any::<u128>(), b_val in any::<u128>()) {
22 TestMult::<$crate::arch::packed_polyval_128::PackedBinaryPolyval1x128b>::test_mul(
23 a_val.into(),
24 b_val.into(),
25 );
26 }
27
28 #[test]
29 fn test_mul_packed_256(a_val in any::<[u128; 2]>(), b_val in any::<[u128; 2]>()) {
30 TestMult::<$crate::arch::packed_polyval_256::PackedBinaryPolyval2x128b>::test_mul(
31 a_val.into(),
32 b_val.into(),
33 );
34 }
35
36 #[test]
37 fn test_mul_packed_512(a_val in any::<[u128; 4]>(), b_val in any::<[u128; 4]>()) {
38 TestMult::<$crate::arch::packed_polyval_512::PackedBinaryPolyval4x128b>::test_mul(
39 a_val.into(),
40 b_val.into(),
41 );
42 }
43 }
44 };
45 }
46
47 macro_rules! define_square_tests {
50 ($square_func:path, $constraint:ident) => {
51 $crate::packed_binary_field::test_utils::define_check_packed_square!(
52 $square_func,
53 $constraint
54 );
55
56 proptest! {
57 #[test]
58 fn test_square_packed_128(a_val in any::<u128>()) {
59 TestSquare::<$crate::arch::packed_polyval_128::PackedBinaryPolyval1x128b>::test_square(a_val.into());
60 }
61
62 #[test]
63 fn test_square_packed_256(a_val in any::<[u128; 2]>()) {
64 TestSquare::<$crate::arch::packed_polyval_256::PackedBinaryPolyval2x128b>::test_square(a_val.into());
65 }
66
67 #[test]
68 fn test_square_packed_512(a_val in any::<[u128; 4]>()) {
69 TestSquare::<$crate::arch::packed_polyval_512::PackedBinaryPolyval4x128b>::test_square(a_val.into());
70 }
71 }
72 };
73 }
74
75 macro_rules! define_invert_tests {
78 ($invert_func:path, $constraint:ident) => {
79 $crate::packed_binary_field::test_utils::define_check_packed_inverse!(
80 $invert_func,
81 $constraint
82 );
83
84 proptest! {
85 #[test]
86 fn test_invert_packed_128(a_val in any::<u128>()) {
87 TestInvert::<$crate::arch::packed_polyval_128::PackedBinaryPolyval1x128b>::test_invert(a_val.into());
88 }
89
90 #[test]
91 fn test_invert_packed_256(a_val in any::<[u128; 2]>()) {
92 TestInvert::<$crate::arch::packed_polyval_256::PackedBinaryPolyval2x128b>::test_invert(a_val.into());
93 }
94
95 #[test]
96 fn test_invert_packed_512(a_val in any::<[u128; 4]>()) {
97 TestInvert::<$crate::arch::packed_polyval_512::PackedBinaryPolyval4x128b>::test_invert(a_val.into());
98 }
99 }
100 };
101 }
102
103 macro_rules! define_transformation_tests {
104 ($constraint:path) => {
105 $crate::packed_binary_field::test_utils::define_check_packed_transformation!(
106 $constraint
107 );
108
109 proptest::proptest! {
110 #[test]
111 fn test_transformation_packed_128(a_val in proptest::prelude::any::<u128>()) {
112 TestTransformation::<$crate::arch::packed_polyval_128::PackedBinaryPolyval1x128b>::test_transformation(a_val.into());
113 }
114
115 #[test]
116 fn test_transformation_packed_256(a_val in proptest::prelude::any::<[u128; 2]>()) {
117 TestTransformation::<$crate::arch::packed_polyval_256::PackedBinaryPolyval2x128b>::test_transformation(a_val.into());
118 }
119
120 #[test]
121 fn test_transformation_packed_512(a_val in proptest::prelude::any::<[u128; 4]>()) {
122 TestTransformation::<$crate::arch::packed_polyval_512::PackedBinaryPolyval4x128b>::test_transformation(a_val.into());
123 }
124 }
125 };
126 }
127
128 pub(crate) use define_invert_tests;
129 pub(crate) use define_multiply_tests;
130 pub(crate) use define_square_tests;
131 pub(crate) use define_transformation_tests;
132}
133
134#[cfg(test)]
135mod tests {
136 use std::ops::Mul;
137
138 use proptest::{arbitrary::any, proptest};
139
140 use super::test_utils::{
141 define_invert_tests, define_multiply_tests, define_square_tests,
142 define_transformation_tests,
143 };
144 use crate::{
145 arch::{
146 packed_polyval_128::PackedBinaryPolyval1x128b,
147 packed_polyval_256::PackedBinaryPolyval2x128b,
148 packed_polyval_512::PackedBinaryPolyval4x128b,
149 },
150 linear_transformation::PackedTransformationFactory,
151 test_utils::implements_transformation_factory,
152 underlier::WithUnderlier,
153 BinaryField128bPolyval, PackedBinaryField1x128b, PackedBinaryField2x128b,
154 PackedBinaryField4x128b, PackedField,
155 };
156
157 fn check_get_set<const WIDTH: usize, PT>(a: [u128; WIDTH], b: [u128; WIDTH])
158 where
159 PT: PackedField<Scalar = BinaryField128bPolyval>
160 + WithUnderlier<Underlier: From<[u128; WIDTH]>>,
161 {
162 let mut val = PT::from_underlier(a.into());
163 for i in 0..WIDTH {
164 assert_eq!(val.get(i), BinaryField128bPolyval::from(a[i]));
165 val.set(i, BinaryField128bPolyval::from(b[i]));
166 assert_eq!(val.get(i), BinaryField128bPolyval::from(b[i]));
167 }
168 }
169
170 proptest! {
171 #[test]
172 fn test_get_set_256(a in any::<[u128; 2]>(), b in any::<[u128; 2]>()) {
173 check_get_set::<2, PackedBinaryPolyval2x128b>(a, b);
174 }
175
176 #[test]
177 fn test_get_set_512(a in any::<[u128; 4]>(), b in any::<[u128; 4]>()) {
178 check_get_set::<4, PackedBinaryPolyval4x128b>(a, b);
179 }
180 }
181
182 define_multiply_tests!(Mul::mul, PackedField);
183
184 define_square_tests!(PackedField::square, PackedField);
185
186 define_invert_tests!(PackedField::invert_or_zero, PackedField);
187
188 #[allow(unused)]
189 trait SelfTransformationFactory: PackedTransformationFactory<Self> {}
190
191 impl<T: PackedTransformationFactory<T>> SelfTransformationFactory for T {}
192
193 define_transformation_tests!(SelfTransformationFactory);
194
195 #[allow(unused)]
197 const fn test_implement_transformation_factory() {
198 implements_transformation_factory::<PackedBinaryPolyval1x128b, PackedBinaryPolyval1x128b>();
200 implements_transformation_factory::<PackedBinaryField1x128b, PackedBinaryPolyval1x128b>();
201
202 implements_transformation_factory::<PackedBinaryPolyval2x128b, PackedBinaryPolyval2x128b>();
204 implements_transformation_factory::<PackedBinaryField2x128b, PackedBinaryPolyval2x128b>();
205
206 implements_transformation_factory::<PackedBinaryPolyval4x128b, PackedBinaryPolyval4x128b>();
208 implements_transformation_factory::<PackedBinaryField4x128b, PackedBinaryPolyval4x128b>();
209 }
210}