From: https://stackoverflow.com/questions/1659440/32-bit-to-16-bit-floating-point-conversion
| 17 | //! From: |
| 18 | //! https://stackoverflow.com/questions/1659440/32-bit-to-16-bit-floating-point-conversion |
| 19 | static float half_to_float(const uint16_t x) { |
| 20 | const ccuint e = (x & 0x7C00) >> 10; // exponent |
| 21 | const ccuint m = (x & 0x03FF) << 13; // mantissa |
| 22 | const ccuint v = as_uint((float)m) >> 23; // evil log2 bit hack to count leading |
| 23 | // zeros in denormalized format |
| 24 | return as_float( |
| 25 | (x & 0x8000) << 16 | (e != 0) * ((e + 112) << 23 | m) | |
| 26 | ((e == 0) & (m != 0)) * |
| 27 | ((v - 37) << 23 | |
| 28 | ((m << (150 - v)) & |
| 29 | 0x007FE000))); // sign : normalized : denormalized |
| 30 | } |
| 31 | |
| 32 | static TinyNNDType dtype_from_fbs(ns(DTypeEnum_enum_t) fbs_dtype) { |
| 33 | switch (fbs_dtype) { |
no test coverage detected