Mesa (master): gallivm: Use nextafterf(0.5, 0.0) as rounding constant

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Nov 28 19:22:58 UTC 2018


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

Author: Matt Turner <mattst88 at gmail.com>
Date:   Wed Nov 21 12:13:19 2018 -0800

gallivm: Use nextafterf(0.5, 0.0) as rounding constant

The common truncf(x + 0.5) fails for the floating-point value just less
than 0.5 (nextafterf(0.5, 0.0)). nextafterf(0.5, 0.0) + 0.5, after
rounding is 1.0, thus truncf does not produce the desired value.

The solution is to add nextafterf(0.5, 0.0) instead of 0.5 before
truncating. This works for all values.

Reviewed-by: Roland Scheidegger <sroland at vmware.com>

---

 src/gallium/auxiliary/gallivm/lp_bld_arit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
index f348833206..c050bfdb93 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
@@ -2477,7 +2477,7 @@ lp_build_iround(struct lp_build_context *bld,
    else {
       LLVMValueRef half;
 
-      half = lp_build_const_vec(bld->gallivm, type, 0.5);
+      half = lp_build_const_vec(bld->gallivm, type, nextafterf(0.5, 0.0));
 
       if (type.sign) {
          LLVMTypeRef vec_type = bld->vec_type;




More information about the mesa-commit mailing list