Skip to main content

e2m1_bits_to_float

Function e2m1_bits_to_float 

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

Decode one e2m1 code per lane, held in the low nibble of each lane of code.

The upper bits of a lane are ignored, so a caller may hand over an unmasked field.

The decode is an assembly of the f32’s bits, not arithmetic over its value. e2m1 and f32 are the same shape of number, so a code’s magnitude bits are already an f32’s top value bits and only have to be moved into place and biased — where computing (1 + m/2) * 2^(e-1) term by term costs two integer-to-float conversions and three multiplies to reach one of sixteen possible numbers. The subnormal arm is the one place the two layouts genuinely disagree and the one place a select is owed.