git: f2e38602de89 - stable/12 - Avoid raising unexpected floating point exceptions in libm
Dimitry Andric
dim at FreeBSD.org
Thu Apr 15 18:45:43 UTC 2021
The branch stable/12 has been updated by dim:
URL: https://cgit.FreeBSD.org/src/commit/?id=f2e38602de89608b46a3b920fc222fdcf50864dd
commit f2e38602de89608b46a3b920fc222fdcf50864dd
Author: Dimitry Andric <dim at FreeBSD.org>
AuthorDate: 2021-04-09 23:07:54 +0000
Commit: Dimitry Andric <dim at FreeBSD.org>
CommitDate: 2021-04-15 18:38:49 +0000
Avoid raising unexpected floating point exceptions in libm
When using clang with x86_64 CPUs that support AVX, some floating point
transformations may raise exceptions that would not have been raised by
the original code. To avoid this, use the -fp-exception-behavior=maytrap
flag, introduced in clang 10.0.0.
In particular, this fixes a number of test failures with ctanhf(3) and
ctanf(3), when libm is compiled with -mavx. An unexpected FE_INVALID
exception is then raised, because clang emits vdivps instructions to
perform certain divides. (The vdivps instruction operates on multiple
single-precision float operands simultaneously, but the exceptions may
be influenced by unused parts of the XMM registers. In this particular
case, it was calculating 0 / 0, which results in FE_INVALID.)
If -fp-exception-behavior=maytrap is specified however, clang uses
vdivss instructions instead, which work on one operand, and should not
raise unexpected exceptions.
Reported by: olivier
Reviewed by: arichardson
PR: 254911
Differential Revision: https://reviews.freebsd.org/D29686
(cherry picked from commit 3b00222f156dca5700c839d73e36daf479fa640c)
Only use -fp-exception-behavior=maytrap on x86, for now
After 3b00222f156d, it turns out that clang only supports strict
floating point semantics for SystemZ and x86 at the moment, while for
other architectures it is still experimental.
Therefore, only use -fp-exception-behavior=maytrap on x86 for now,
otherwise this option results in "error: overriding currently
unsupported use of floating point exceptions on this target
[-Werror,-Wunsupported-floating-point-opt]" on other architectures.
Fixes: 3b00222f156d
PR: 254911
(cherry picked from commit bae9fd0b33462e9506c3ac3400089c6dbc4aee8f)
---
lib/msun/Makefile | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/lib/msun/Makefile b/lib/msun/Makefile
index 6c9af4c018c8..d56b33deabea 100644
--- a/lib/msun/Makefile
+++ b/lib/msun/Makefile
@@ -34,6 +34,17 @@ CFLAGS+= -I${.CURDIR}/ld128
CFLAGS+= -I${.CURDIR}/${ARCH_SUBDIR}
+.include <bsd.compiler.mk>
+.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 100000 && \
+ (${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386")
+# When using clang with x86_64 CPUs that support AVX, some floating point
+# transformations may raise exceptions that would not have been raised by the
+# original code. To avoid this, use the -fp-exception-behavior=maytrap flag,
+# introduced in clang 10.0.0.
+# See also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=254911
+CFLAGS+= -ffp-exception-behavior=maytrap
+.endif
+
.PATH: ${.CURDIR}/bsdsrc
.PATH: ${.CURDIR}/src
.PATH: ${.CURDIR}/man
@@ -113,7 +124,6 @@ COMMON_SRCS+= catrigl.c \
# 'long double' [-Werror=overflow]
# if( y >= LDBL_MAX )
# See also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=130067
-.include <bsd.compiler.mk>
.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 60000
CFLAGS.e_powl.c+= -Wno-error=overflow
.endif
More information about the dev-commits-src-branches
mailing list