diff options
author | Eric Anholt <[email protected]> | 2019-06-27 15:53:53 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2019-07-16 12:51:13 -0700 |
commit | 628f55717bb7451e8a766fdbb3be3823f6ce9308 (patch) | |
tree | bbaecca2217840ed6b4d303c93109c0780fa579f /src/util | |
parent | bb5801ad98ec0958ff0d2f18df61842b3e1f0fd9 (diff) |
src/util: Switch _mesa_half_to_float() to u_half.h's version.
The two implementations differ across the entire input range only in
that u_half.h preserves mantissa bits for NaNs. The u_half.h version
shaves 15% off of the text size of half_float.o.
Reviewed-by: Thomas Helland <[email protected]>
Reviewed-by: Kristian H. Kristensen <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/half_float.c | 45 |
1 files changed, 2 insertions, 43 deletions
diff --git a/src/util/half_float.c b/src/util/half_float.c index 63aec5c5c14..422c0b69b78 100644 --- a/src/util/half_float.c +++ b/src/util/half_float.c @@ -27,6 +27,7 @@ #include <math.h> #include <assert.h> #include "half_float.h" +#include "util/u_half.h" #include "rounding.h" #include "macros.h" @@ -134,49 +135,7 @@ _mesa_float_to_half(float val) float _mesa_half_to_float(uint16_t val) { - /* XXX could also use a 64K-entry lookup table */ - const int m = val & 0x3ff; - const int e = (val >> 10) & 0x1f; - const int s = (val >> 15) & 0x1; - int flt_m, flt_e, flt_s; - fi_type fi; - float result; - - /* sign bit */ - flt_s = s; - - /* handle special cases */ - if ((e == 0) && (m == 0)) { - /* zero */ - flt_m = 0; - flt_e = 0; - } - else if ((e == 0) && (m != 0)) { - /* denorm -- denorm half will fit in non-denorm single */ - const float half_denorm = 1.0f / 16384.0f; /* 2^-14 */ - float mantissa = ((float) (m)) / 1024.0f; - float sign = s ? -1.0f : 1.0f; - return sign * mantissa * half_denorm; - } - else if ((e == 31) && (m == 0)) { - /* infinity */ - flt_e = 0xff; - flt_m = 0; - } - else if ((e == 31) && (m != 0)) { - /* NaN */ - flt_e = 0xff; - flt_m = 1; - } - else { - /* regular */ - flt_e = e + 112; - flt_m = m << 13; - } - - fi.i = (flt_s << 31) | (flt_e << 23) | flt_m; - result = fi.f; - return result; + return util_half_to_float(val); } /** |