MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / portable_float_to_bf16

Function portable_float_to_bf16

support/Bfloat16.h:40–52  ·  view source on GitHub ↗

Convert float to bfloat16 in a portable way that works on older hardware * * @param[in] v Floating-point value to convert to bfloat * * @return Converted value */

Source from the content-addressed store, hash-verified

38 * @return Converted value
39 */
40inline uint16_t portable_float_to_bf16(const float v)
41{
42 const uint32_t *fromptr = reinterpret_cast<const uint32_t *>(&v);
43 uint16_t res = (*fromptr >> 16);
44 const uint16_t error = (*fromptr & 0x0000ffff);
45 uint16_t bf_l = res & 0x0001;
46
47 if ((error > 0x8000) || ((error == 0x8000) && (bf_l != 0)))
48 {
49 res += 1;
50 }
51 return res;
52}
53
54/** Convert float to bfloat16
55 *

Callers 2

float_to_bf16Function · 0.85
bfloat16Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected