diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2020-01-22 02:13:18 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2020-01-22 02:13:18 +0000 |
commit | fdcc03929065b5bf5dd93553db219ea3e05c8c34 (patch) | |
tree | ca90dc8d9e89febdcd4160956c1b8ec098a4efc9 /lib/mesa/src/util/half_float.c | |
parent | 3c9de4a7e13712b5696750bbd59a18c848742022 (diff) |
Import Mesa 19.2.8
Diffstat (limited to 'lib/mesa/src/util/half_float.c')
-rw-r--r-- | lib/mesa/src/util/half_float.c | 47 |
1 files changed, 3 insertions, 44 deletions
diff --git a/lib/mesa/src/util/half_float.c b/lib/mesa/src/util/half_float.c index 63aec5c5c..5ccee81f7 100644 --- a/lib/mesa/src/util/half_float.c +++ b/lib/mesa/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); } /** @@ -187,7 +146,7 @@ uint8_t _mesa_half_to_unorm8(uint16_t val) { const int m = val & 0x3ff; const int e = (val >> 10) & 0x1f; - MAYBE_UNUSED const int s = (val >> 15) & 0x1; + ASSERTED const int s = (val >> 15) & 0x1; /* v = round_to_nearest(1.mmmmmmmmmm * 2^(e-15) * 255) * = round_to_nearest((1.mmmmmmmmmm * 255) * 2^(e-15)) |