Convert float to bfloat16 * * @param[in] v Floating-point value to convert to bfloat * * @return Converted value */
| 58 | * @return Converted value |
| 59 | */ |
| 60 | inline uint16_t float_to_bf16(const float v) |
| 61 | { |
| 62 | #if defined(ARM_COMPUTE_ENABLE_BF16) |
| 63 | const uint32_t *fromptr = reinterpret_cast<const uint32_t *>(&v); |
| 64 | uint16_t res; |
| 65 | |
| 66 | __asm __volatile("ldr s0, [%[fromptr]]\n" |
| 67 | ".inst 0x1e634000\n" // BFCVT h0, s0 |
| 68 | "str h0, [%[toptr]]\n" |
| 69 | : |
| 70 | : [fromptr] "r"(fromptr), [toptr] "r"(&res) |
| 71 | : "v0", "memory"); |
| 72 | return res; |
| 73 | #else /* defined(ARM_COMPUTE_ENABLE_BF16) */ |
| 74 | return portable_float_to_bf16(v); |
| 75 | #endif /* defined(ARM_COMPUTE_ENABLE_BF16) */ |
| 76 | } |
| 77 | |
| 78 | /** Truncate a float to bf16 precision. |
| 79 | * |
no test coverage detected