Skip to main content

float_to_e2m1_bits

Function float_to_e2m1_bits 

Source
pub fn float_to_e2m1_bits<F: Numeric, N: Size>(
    value: Vector<F, N>,
) -> Vector<u32, N>
Expand description

Encode one e2m1 code per lane into the low nibble of each lane, rounding to nearest with ties to even and saturating at ±6.

Ties to even is not a detail here. e2m1’s magnitudes are so far apart that a tie is a common input rather than a rare one — 0.75 and 2.5 are both exact midpoints — and rounding them all outward would bias every quantized block upward.

The rounding is expressed as a count of the midpoints the magnitude clears, which puts the whole codec in comparisons and adds. The comparisons alternate strict and non-strict on purpose: that is what lands each tie on the even code (0.75 -> 1.0, 2.5 -> 2.0) without a separate parity fixup.