Skip to main content

Module sliced_packed_field

Module sliced_packed_field 

Source
Expand description

A packed extension field in a sliced (struct-of-arrays) memory layout.

An extension field element x = c_0·β_0 + … + c_{N-1}·β_{N-1} over a subfield FSub is a vector of N = DEGREE subfield coordinates in the basis {β_j}. SlicedPackedField packs WIDTH such extension scalars by storing each coordinate of every element in its own packed subfield register:

coords[0] = [ c_0(x_0), c_0(x_1), …, c_0(x_{WIDTH-1}) ]   // β_0 coordinate of every lane
coords[1] = [ c_1(x_0), c_1(x_1), …, c_1(x_{WIDTH-1}) ]   // β_1 coordinate of every lane
…

The coordinates of a single extension element are not adjacent in memory — hence “sliced”. This is the layout that lets a batch multiply run as a handful of packed subfield multiplies over the whole batch (Karatsuba over the extension), instead of a schoolbook product per lane.

§What is generic and what is not

Everything that does not depend on the extension’s multiplication rule is provided here, generically, for any PSub: PackedField and any scalar F: ExtensionField<PSub::Scalar>: scalar access, broadcast, iteration, addition, masking, interleave/unzip/spread, and square_transpose. The layout makes these uniform: a lane permutation (interleave, spread) or a bitwise op (add, mask) applies to each coordinate register identically, and scalar access reads or writes the N coordinate registers at one lane through the ExtensionField basis.

The field arithmetic is written per concrete extension: a type supplies a custom WideMul (the widening multiply, with a deferred reduction), plus Square and InvertOrZero. Mul is then blanket-implemented as reduce(wide_mul(a, b)), mirroring how the scalar fields are defined. A concrete extension whose coordinate PSub is a PackedPrimitiveType can reach into its underlier for optimizations a generic packed field cannot express. See packed_ghash_sq for the GHASH² instantiation.

§The F type parameter

The scalar F is carried as a phantom parameter rather than derived from (PSub, N). A degree and a subfield do not name a unique extension, and Rust requires a type parameter used only as type Scalar = F to appear in the self type. This mirrors PackedPrimitiveType<U, Scalar>, which likewise carries its scalar. The invariant N == <F as ExtensionField<PSub::Scalar>>:: DEGREE is upheld by the concrete type aliases.

Structs§

SlicedPackedField
A packed extension field stored as N packed subfield coordinate registers.