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 fieldE + 126, mantissa MSBm(mantissa fieldm << 22). - Subnormal-class (
E == 0):0.5 * m, i.e. float320x3F000000(+0.5) whenm == 1, else0x00000000. 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:
- nibble (
SIMD[DType.uint16, width]): One E2M1 nibble per lane in the low 4 bits (0..15).
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?
Thank you! We'll create more content like this.
Thank you for helping us improve!