MCPcopy Create free account
hub / github.com/Niko1221/Strata / f16_to_f32

Function f16_to_f32

engine/src/split/src/model.cpp:161–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161float f16_to_f32(uint16_t h) {
162 const uint32_t s = (h >> 15) & 1, e = (h >> 10) & 31, m = h & 1023;
163 uint32_t u;
164 if (e == 0) {
165 if (m == 0) u = s << 31;
166 else {
167 int ee = 0;
168 uint32_t mm = m;
169 while (!(mm & 1024)) { mm <<= 1; --ee; }
170 u = (s << 31) | ((uint32_t) (ee + 127 - 14) << 23) | ((mm & 1023) << 13);
171 }
172 } else if (e == 31) u = (s << 31) | 0x7f800000u | (m << 13);
173 else u = (s << 31) | ((e + 112) << 23) | (m << 13);
174 float f;
175 std::memcpy(&f, &u, 4);
176 return f;
177}
178
179uint16_t f32_to_f16(float x) {
180 uint32_t u;

Callers 2

bf16Method · 0.70
f32_rows2Method · 0.70

Calls 1

memcpyFunction · 0.85

Tested by

no test coverage detected