20 #include <immintrin.h>
24 #define NATIVE_FLOAT16_SUPPORT 1
26 #define NATIVE_FLOAT16_SUPPORT 0
27 #define FLT16_MAX 0x7bff
28 #define FLT16_MIN 0xfbff
32#ifdef NATIVE_FLOAT16_SUPPORT
35 #warning "float16_t type is not supported, using manual implementations"
39 } float_uint32_union_t;
51 #ifdef NATIVE_FLOAT16_SUPPORT
58 float_uint32_union_t v;
63 uint32_t hexpmant = ((uint32_t) (h) << 17) >> 4;
64 v.i = ((uint32_t) (h >> 15)) << 31;
67 if ((hexpmant >= 0x00800000)) {
71 if ((hexpmant < 0x0f800000)) {
78 else if (hexpmant != 0) {
86 while (0 == ((hexpmant << lc) & 0x80000000)) {
102 v.i |= (hexpmant << lc);
117 #ifdef NATIVE_FLOAT16_SUPPORT
124 float_uint32_union_t v;
126 uint32_t e, m, ui, r, shift;
130 ui = (v.i & ~0x80000000);
131 ret = ((v.i >> 16) & 0x8000);
134 if (ui >= 0x38800000) {
136 if (ui >= 0x7f800000) {
138 if (ui == 0x7f800000) {
141 m = (ui & 0x7fffff) >> 13;
143 return ret | (uint16_t) m | (uint16_t) (m == 0);
147 if (ui > 0x477fefff) {
152 ui = ((ui + 0x00000fff + ((ui >> 13) & 1)) >> 13);
153 return ret | (uint16_t) ui;
157 if (ui < 0x33000001) {
164 m = 0x800000 | (ui & 0x7fffff);
165 r = m << (32 - shift);
167 if (r > 0x80000000 || (r == 0x80000000 && (ret & 0x1) != 0)) {
static float16_t as_f16(float f)
Definition: float16.h:116
static float as_f32(float16_t h)
Definition: float16.h:50
_Float16 float16_t
Definition: float16.h:33