def bf16_rne

bendtorch@1.3.0.0 · dtype.bend:43

import bendtorch@1.3.0.0/dtype.bend as Dtype
import Base

43# F32 -> BF16, round to nearest even: add 0x7FFF plus the lowest kept bit, keep the top half. The carry rounds up into
44# the exponent when the mantissa overflows, and past the largest finite value to infinity, as IEEE asks.
45def bf16_rne(+u: U32) -> U32:
46  U32.shrn(((u + 32767 : U32) + (U32.shrn(u, 16n) .&. 1 : U32) : U32), 16n)

Uses (4)

Used by (1)