4 #include "pipe/p_compiler.h"
5 #include "util/u_math.h"
11 extern uint32_t util_half_to_float_mantissa_table
[2048];
12 extern uint32_t util_half_to_float_exponent_table
[64];
13 extern uint32_t util_half_to_float_offset_table
[64];
14 extern uint16_t util_float_to_half_base_table
[512];
15 extern uint8_t util_float_to_half_shift_table
[512];
18 * Note that if the half float is a signaling NaN, the x87 FPU will turn
19 * it into a quiet NaN immediately upon loading into a float.
21 * Additionally, denormals may be flushed to zero.
23 * To avoid this, use the floatui functions instead of the float ones
24 * when just doing conversion rather than computation on the resulting
28 static INLINE
uint32_t
29 util_half_to_floatui(half h
)
31 unsigned exp
= h
>> 10;
32 return util_half_to_float_mantissa_table
[util_half_to_float_offset_table
[exp
] + (h
& 0x3ff)] + util_half_to_float_exponent_table
[exp
];
36 util_half_to_float(half h
)
39 r
.ui
= util_half_to_floatui(h
);
44 util_floatui_to_half(uint32_t v
)
46 unsigned signexp
= v
>> 23;
47 return util_float_to_half_base_table
[signexp
] + ((v
& 0x007fffff) >> util_float_to_half_shift_table
[signexp
]);
51 util_float_to_half(float f
)
55 return util_floatui_to_half(i
.ui
);