diff options
author | Chad Versace <[email protected]> | 2013-01-16 19:49:40 -0800 |
---|---|---|
committer | Chad Versace <[email protected]> | 2013-01-24 21:24:07 -0800 |
commit | eac030e38e3cdd4ed4534516e3d3a50c8a372719 (patch) | |
tree | 29b81f500914cd9371e10625809f4286048b6a96 /src/mesa/main | |
parent | 1fafd008392d5240dc36d0c72978cef62e21b4b1 (diff) |
mesa,glsl: Move round_to_even() from glsl to mesa/main (v2)
Move round_to_even's definition to mesa/main so that _mesa_float_to_half()
can use it in order to eliminate rounding bias.
In additon to moving the fuction definition, prefix its name with "_mesa",
just as all other functions in mesa/main are prefixed.
v2: Fix Android build.
Reviewed-by: Ian Romanick <[email protected]>
Signed-off-by: Chad Versace <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r-- | src/mesa/main/imports.c | 20 | ||||
-rw-r--r-- | src/mesa/main/imports.h | 3 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index 76f835e0ec3..26c91dce535 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -314,6 +314,26 @@ _mesa_bitcount_64(uint64_t n) #endif +/* Using C99 rounding functions for roundToEven() implementation is + * difficult, because round(), rint, and nearbyint() are affected by + * fesetenv(), which the application may have done for its own + * purposes. Mesa's IROUND macro is close to what we want, but it + * rounds away from 0 on n + 0.5. + */ +int +_mesa_round_to_even(float val) +{ + int rounded = IROUND(val); + + if (val - floor(val) == 0.5) { + if (rounded % 2 != 0) + rounded += val > 0 ? -1 : 1; + } + + return rounded; +} + + /** * Convert a 4-byte float to a 2-byte half float. * Based on code from: diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h index 8446ea2a3e8..4b783818b2f 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -548,6 +548,9 @@ _mesa_fls(unsigned int n) #endif } +extern int +_mesa_round_to_even(float val); + extern GLhalfARB _mesa_float_to_half(float f); |