24 #ifndef ARM_COMPUTE_BFLOAT16_H 25 #define ARM_COMPUTE_BFLOAT16_H 40 inline uint16_t float_to_bf16(
const float v)
42 const uint32_t *fromptr = reinterpret_cast<const uint32_t *>(&v);
43 #if defined(__ARM_FEATURE_BF16_VECTOR_ARITHMETIC) || defined(ARM_COMPUTE_FORCE_BF16) 47 "ldr s0, [%[fromptr]]\n" 49 "str h0, [%[toptr]]\n" 51 : [fromptr]
"r"(fromptr), [toptr]
"r"(&res)
54 uint16_t res = (*fromptr >> 16);
55 const uint16_t error = (*fromptr & 0x0000ffff);
56 uint16_t bf_l = res & 0x0001;
57 if((error > 0x8000) || ((error == 0x8000) && (bf_l != 0)))
71 inline float bf16_to_float(
const uint16_t &v)
73 const uint32_t lv = (v << 16);
75 memcpy(&fp, &lv,
sizeof(lv));
94 : value(float_to_bf16(v))
105 value = float_to_bf16(v);
112 operator float()
const 114 return bf16_to_float(value);
bfloat16(float v)
Constructor.
Brain floating point representation class.
bfloat16 & operator=(float v)
Assignment operator.
Copyright (c) 2017-2021 Arm Limited.
static bfloat16 lowest()
Lowest representative value.
bfloat16()
Default Constructor.
static bfloat16 max()
Largest representative value.