ggml_compute_fp32_to_bf16, ggml/src/ggml-impl.h (MIT, the ggml authors), on raw bits.
| 21 | |
| 22 | /// ggml_compute_fp32_to_bf16, ggml/src/ggml-impl.h (MIT, the ggml authors), on raw bits. |
| 23 | uint16_t ggml_bf16(uint32_t u) { |
| 24 | if ((u & 0x7fffffffu) > 0x7f800000u) return (uint16_t) ((u >> 16) | 64); |
| 25 | return (uint16_t) ((u + (0x7fffu + ((u >> 16) & 1u))) >> 16); |
| 26 | } |
| 27 | |
| 28 | /// The rule before this fix, kept only to prove the change is confined to NaN inputs. |
| 29 | uint16_t previous_bf16(uint32_t u) { |