IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo function

decode_e2m1_to_f32

def decode_e2m1_to_f32[width: SIMDLength, //](nibble: SIMD[DType.uint16, width]) -> SIMD[DType.float32, width]

Decodes E2M1 nibbles to float32 with branch-free bit arithmetic.

The float32-native twin of decode_e2m1_to_bf16: it builds the float32 bit pattern directly instead of constructing bf16 and widening. All 16 E2M1 values are exactly representable in float32, so the result is bit-identical to E2M1_TO_FLOAT32[nibble] (and therefore to decode_e2m1_to_bf16(nibble).cast[float32]()). Use it on the dequant path where the next step is a float32 scale multiply -- it removes the bf16->f32 widen per element while keeping the bit-exact-vs-table contract.

Construction (float32 layout s | 8-bit exp (bias 127) | 23-bit mantissa): let E = bits2:1 and m = bit0.

  • Normal (E >= 1): exponent field E + 126, mantissa MSB m (mantissa field m << 22).
  • Subnormal-class (E == 0): 0.5 * m, i.e. float32 0x3F000000 (+0.5) when m == 1, else 0x00000000. Selected branch-free.
  • Sign bit (s, nibble bit 3) shifted into float32 bit 31 (s << 28).

Parameters:

  • width (SIMDLength): SIMD width (lane count) of the nibble vector.

Args:

Returns:

SIMD[DType.float32, width]: The decoded values as SIMD[DType.float32, width], bit-identical to indexing E2M1_TO_FLOAT32[nibble].

Was this page helpful?