MCPcopy Create free account
hub / github.com/MegEngine/MegCC / half_to_float

Function half_to_float

runtime/src/parse.c:19–30  ·  view source on GitHub ↗

From: https://stackoverflow.com/questions/1659440/32-bit-to-16-bit-floating-point-conversion

Source from the content-addressed store, hash-verified

17//! From:
18//! https://stackoverflow.com/questions/1659440/32-bit-to-16-bit-floating-point-conversion
19static 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
32static TinyNNDType dtype_from_fbs(ns(DTypeEnum_enum_t) fbs_dtype) {
33 switch (fbs_dtype) {

Callers 1

Calls 2

as_floatFunction · 0.85
as_uintFunction · 0.70

Tested by

no test coverage detected