binius_field/
packed_extension.rs1use crate::{
5 BinaryField, ExtensionField, PackedField, arch::PackedPrimitiveType, underlier::WithUnderlier,
6};
7
8pub trait PackedExtension<FSub: BinaryField>:
20 PackedField<Scalar: ExtensionField<FSub>> + WithUnderlier
21{
22 type PackedSubfield: PackedField<Scalar = FSub>;
24
25 fn cast_base(self) -> Self::PackedSubfield;
27
28 fn cast_base_mut(&mut self) -> &mut Self::PackedSubfield;
30
31 fn cast_ext(base: Self::PackedSubfield) -> Self;
33
34 fn cast_bases_mut(packed: &mut [Self]) -> &mut [Self::PackedSubfield];
36}
37
38pub type PackedSubfield<P, FSub> = <P as PackedExtension<FSub>>::PackedSubfield;
40
41impl<FSub, P> PackedExtension<FSub> for P
44where
45 FSub: BinaryField,
46 P: PackedField<Scalar: ExtensionField<FSub>> + WithUnderlier,
47 PackedPrimitiveType<P::Underlier, FSub>: PackedField<Scalar = FSub>,
48{
49 type PackedSubfield = PackedPrimitiveType<P::Underlier, FSub>;
50
51 #[inline]
52 fn cast_base(self) -> Self::PackedSubfield {
53 Self::PackedSubfield::from_underlier(self.to_underlier())
54 }
55
56 #[inline]
57 fn cast_base_mut(&mut self) -> &mut Self::PackedSubfield {
58 Self::PackedSubfield::from_underlier_ref_mut(self.to_underlier_ref_mut())
59 }
60
61 #[inline]
62 fn cast_ext(base: Self::PackedSubfield) -> Self {
63 Self::from_underlier(base.to_underlier())
64 }
65
66 #[inline]
67 fn cast_bases_mut(packed: &mut [Self]) -> &mut [Self::PackedSubfield] {
68 Self::PackedSubfield::from_underliers_ref_mut(Self::to_underliers_ref_mut(packed))
69 }
70}