24 #ifndef ARM_COMPUTE_BFLOAT16_H 25 #define ARM_COMPUTE_BFLOAT16_H 39 inline uint16_t float_to_bf16(
const float v)
41 const uint32_t *fromptr =
reinterpret_cast<const uint32_t *
>(&v);
42 #if defined(__ARM_FEATURE_BF16_VECTOR_ARITHMETIC) || defined(ARM_COMPUTE_FORCE_BF16) 46 "ldr s0, [%[fromptr]]\n" 48 "str h0, [%[toptr]]\n" 50 : [fromptr]
"r"(fromptr), [toptr]
"r"(&res)
53 uint16_t res = (*fromptr >> 16);
54 const uint16_t error = (*fromptr & 0x0000ffff);
55 uint16_t bf_l = res & 0x0001;
56 if((error > 0x8000) || ((error == 0x8000) && (bf_l != 0)))
70 inline float bf16_to_float(
const uint16_t &v)
72 const uint32_t lv = (v << 16);
73 const float *fp =
reinterpret_cast<const float *
>(&lv);
93 : value(float_to_bf16(v))
104 value = float_to_bf16(v);
111 operator float()
const 113 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.