IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /get-started.md).

Mojo function

decode_fp6_to_f32

def decode_fp6_to_f32[width: SIMDLength, //, fmt: FP6Format](code: SIMD[DType.uint8, width]) -> SIMD[DType.float32, width]

Decodes FP6 codes to float32 with branch-free bit arithmetic.

Builds the float32 bit pattern directly, so the result is bit-identical to indexing fp6_reference_table[fmt]() for all 64 codes, including the signed zeros. Every FP6 value is exactly representable in float32.

Construction (float32 s | 8-bit exp (bias 127) | 23-bit mantissa), with E the exponent field, m the mantissa field, and M the mantissa width:

  • Normal (E >= 1): value 2^(E - bias) * (1 + m/2^M), so the float32 exponent field is E + 127 - bias and the mantissa field is m << (23 - M).
  • Subnormal (E == 0): value m * 2^(1 - bias - M), a uniform grid. Built by converting m to float32 (exact for m < 2^M) and scaling by a power of two (also exact) rather than by bit surgery, which would need a leading-zero count.
  • The sign bit (code bit 5) is OR'd into float32 bit 31 after the select, so -0 decodes to 0x80000000 and matches the table's -0.0.

Unlike decode_e2m1_to_f32_inject in fp4_utils, this never forms a denormal float32 intermediate, so it is correct on flush-to-zero targets.

Parameters:

  • โ€‹width (SIMDLength): SIMD width (lane count) of the code vector.
  • โ€‹fmt (FP6Format): The FP6 encoding of the input codes.

Args:

Returns:

SIMD[DType.float32, width]: The decoded values as SIMD[DType.float32, width], bit-identical to indexing fp6_reference_table[fmt]().