summaryrefslogtreecommitdiffstats
path: root/configure.ac
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2023-07-29 16:24:12 +0800
committerBenBE <BenBE@geshi.org>2023-08-18 12:52:28 +0200
commitb416433fbe7ccf935ad4e268396aa423143c2318 (patch)
tree55a38c76f4f0091ed6b06d7369706bd2f1f6f61e /configure.ac
parentc6fd64fce8502a4e557711abe9fee394763ac52c (diff)
Replace isnan() with better comparisons (isgreater(), etc.)
The standard isnan() function is defined to never throw FP exceptions even when the argument is a "signaling" NaN. This makes isnan() more expensive than (x != x) expression unless the compiler flag '-fno-signaling-nans' is given. Introduce functions isNaN(), isNonnegative(), isPositive(), sumPositiveValues() and compareRealNumbers(), and replace isnan() in htop's codebase with the new functions. These functions utilize isgreater() and isgreaterequal() comparisons, which do not throw FP exceptions on "quiet" NaNs, which htop uses extensively. With isnan() removed, there is no need to suppress the warning '-Wno-c11-extensions' in FreeBSD. Remove the code from 'configure.ac'. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac42
1 files changed, 29 insertions, 13 deletions
diff --git a/configure.ac b/configure.ac
index 8f8606c2..07c3ee85 100644
--- a/configure.ac
+++ b/configure.ac
@@ -203,21 +203,42 @@ AC_COMPILE_IFELSE([
CFLAGS="$old_CFLAGS"
AC_MSG_CHECKING(for NaN support)
-AC_RUN_IFELSE([
+dnl Note: AC_RUN_IFELSE does not try compiling the program at all when
+dnl $cross_compiling is 'yes'.
+AC_LINK_IFELSE([
AC_LANG_PROGRAM(
[[
- #include <math.h>
+#include <math.h>
]],
[[
- double x = NAN; return !isnan(x);
+ double x = NAN;
+ /* Both should evaluate to false -> 0 (exit success) */
+ return isgreater(x, x) || isgreaterequal(x, x);
]]
)],
- [AC_MSG_RESULT(yes)],
- [
+ [flag_finite_math_only=unknown
+ if test "$cross_compiling" = yes; then
+ AC_COMPILE_IFELSE([
+ AC_LANG_SOURCE([[
+/* __FINITE_MATH_ONLY__ is documented in Clang. */
+#ifdef __FINITE_MATH_ONLY__
+#error "should not enable -ffinite-math-only"
+#endif
+ ]])],
+ AC_MSG_RESULT([assume yes (cross compiling)]),
+ flag_finite_math_only=yes)
+ elif ./conftest$EXEEXT >&AS_MESSAGE_LOG_FD; then
+ flag_finite_math_only=no
+ AC_MSG_RESULT(yes)
+ else
+ flag_finite_math_only=yes
+ fi
+ if test "$flag_finite_math_only" = yes; then
AC_MSG_RESULT(no)
- AC_MSG_WARN([Compiler does not respect NaN, some functionality might break; consider using '-fno-finite-math-only'])
- ],
- [AC_MSG_RESULT(skipped)])
+ AC_MSG_WARN([runtime behavior with NaN is not compliant - some functionality might break; consider using '-fno-finite-math-only'])
+ fi],
+ [AC_MSG_RESULT(no)
+ AC_MSG_ERROR([can not find required macros: NAN, isgreater() and isgreaterequal()])])
# ----------------------------------------------------------------------
@@ -700,11 +721,6 @@ AM_CFLAGS="\
-Wunused\
-Wwrite-strings"
-# FreeBSD uses C11 _Generic in its isnan implementation, even with -std=c99
-if test "$my_htop_platform" = freebsd; then
- AM_CFLAGS="$AM_CFLAGS -Wno-c11-extensions"
-fi
-
dnl https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
[

© 2014-2024 Faster IT GmbH | imprint | privacy policy