Mesa (master): gallivm: fix edge cases in exp2

Zack Rusin zack at kemper.freedesktop.org
Fri Jul 19 20:34:22 UTC 2013


Module: Mesa
Branch: master
Commit: 7b672c1503abffcc83a30a9731419539f52ac73f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7b672c1503abffcc83a30a9731419539f52ac73f

Author: Zack Rusin <zackr at vmware.com>
Date:   Thu Jul 18 02:38:54 2013 -0400

gallivm: fix edge cases in exp2

exp(0) has to be exactly 1, exp(-inf) has to be 0, exp(inf) has
to be inf and exp(nan) has to be nan, this fixes all of those
cases.

Signed-off-by: Zack Rusin <zackr at vmware.com>
Reviewed-by: Jose Fonseca <jfonseca at vmware.com>
Reviewed-by: Roland Scheidegger <sroland at vmware.com>

---

 src/gallium/auxiliary/gallivm/lp_bld_arit.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
index d2d91f5..34e3ed9 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
@@ -3141,7 +3141,7 @@ lp_build_polynomial(struct lp_build_context *bld,
  */
 const double lp_build_exp2_polynomial[] = {
 #if EXP_POLY_DEGREE == 5
-   0.999999925063526176901,
+   1.000000000000000000000, /*XXX: was 0.999999925063526176901, recompute others */
    0.693153073200168932794,
    0.240153617044375388211,
    0.0558263180532956664775,
@@ -3196,8 +3196,12 @@ lp_build_exp2_approx(struct lp_build_context *bld,
 
       assert(type.floating && type.width == 32);
 
-      x = lp_build_min(bld, x, lp_build_const_vec(bld->gallivm, type,  129.0));
-      x = lp_build_max(bld, x, lp_build_const_vec(bld->gallivm, type, -126.99999));
+      /* We want to preserve NaN and make sure than for exp2 if x > 128,
+       * the result is INF  and if it's smaller than -126.9 the result is 0 */
+      x = lp_build_min_ext(bld, lp_build_const_vec(bld->gallivm, type,  128.0), x,
+                           GALLIVM_NAN_RETURN_SECOND);
+      x = lp_build_max_ext(bld, lp_build_const_vec(bld->gallivm, type, -126.99999), x,
+                           GALLIVM_NAN_RETURN_SECOND);
 
       /* ipart = floor(x) */
       /* fpart = x - ipart */




More information about the mesa-commit mailing list