[Mesa-dev] [PATCH] gallivm: use llvm.nearbyint instead of llvm.round

sroland at vmware.com sroland at vmware.com
Wed Apr 13 03:00:03 UTC 2016


From: Roland Scheidegger <sroland at vmware.com>

We used to use sse roundps intrinsic directly, but switched to use the llvm
intrinsics for rounding with e4f01da15d8c6ce3e8c77ff3ff3d2ce2574a3f7b.
However, llvm semantics follows standard math lib round function which is
specced to do roundNearestAwayFromZero but we really want roundNearestEven
(moreoever, using round generates atrocious code since the cpu can't do it
directly and it results in scalar calls to libm __roundf).
So, use llvm.nearbyint instead, which does exactly the right thing, and even
has the advantage of being available with llvm 3.3 too. (I've verified it
actually generates a roundps instruction with llvm 3.3.)

This fixes https://bugs.freedesktop.org/show_bug.cgi?id=94909
---
 src/gallium/auxiliary/gallivm/lp_bld_arit.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
index 0c43617..74f1683 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
@@ -1863,11 +1863,7 @@ lp_build_round_arch(struct lp_build_context *bld,
 
       switch (mode) {
       case LP_BUILD_ROUND_NEAREST:
-         if (HAVE_LLVM >= 0x0304) {
-            intrinsic_root = "llvm.round";
-         } else {
-            return lp_build_nearest_sse41(bld, a);
-         }
+         intrinsic_root = "llvm.nearbyint";
          break;
       case LP_BUILD_ROUND_FLOOR:
          intrinsic_root = "llvm.floor";
-- 
2.1.4



More information about the mesa-dev mailing list