binius_field/
packed_extension.rs1use crate::{
5 BinaryField, ExtensionField, PackedField, arch::PackedPrimitiveType, underlier::WithUnderlier,
6};
7
8pub type PackedSubfield<P, FSub> = PackedPrimitiveType<<P as WithUnderlier>::Underlier, FSub>;
16
17pub fn cast_bases_mut<FSub, P>(packed: &mut [P]) -> &mut [PackedSubfield<P, FSub>]
22where
23 FSub: BinaryField,
24 P: PackedField<Scalar: ExtensionField<FSub>> + WithUnderlier,
25 PackedSubfield<P, FSub>: PackedField<Scalar = FSub>,
26{
27 PackedSubfield::<P, FSub>::from_underliers_ref_mut(P::to_underliers_ref_mut(packed))
28}
29
30pub fn cast_base_mut<FSub, P>(packed: &mut P) -> &mut PackedSubfield<P, FSub>
33where
34 FSub: BinaryField,
35 P: PackedField<Scalar: ExtensionField<FSub>> + WithUnderlier,
36 PackedSubfield<P, FSub>: PackedField<Scalar = FSub>,
37{
38 PackedSubfield::<P, FSub>::from_underlier_ref_mut(packed.to_underlier_ref_mut())
39}
40
41pub fn cast_base<FSub, P>(ext: P) -> PackedSubfield<P, FSub>
43where
44 FSub: BinaryField,
45 P: PackedField<Scalar: ExtensionField<FSub>> + WithUnderlier,
46 PackedSubfield<P, FSub>: PackedField<Scalar = FSub>,
47{
48 PackedSubfield::<P, FSub>::from_underlier(ext.to_underlier())
49}
50
51pub fn cast_ext<FSub, P>(base: PackedSubfield<P, FSub>) -> P
53where
54 FSub: BinaryField,
55 P: PackedField<Scalar: ExtensionField<FSub>> + WithUnderlier,
56 PackedSubfield<P, FSub>: PackedField<Scalar = FSub>,
57{
58 P::from_underlier(base.to_underlier())
59}