From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent.desnogues@gmail.com,
"Alex Bennée" <alex.bennee@linaro.org>,
"Emilio G . Cota" <cota@braap.org>,
"Aurelien Jarno" <aurelien@aurel32.net>,
"Peter Maydell" <peter.maydell@linaro.org>
Subject: [Qemu-devel] [RFC PATCH] fpu: add compile time check for old glibc/libm and fma
Date: Thu, 20 Dec 2018 11:10:08 +0000 [thread overview]
Message-ID: <20181220111008.24954-1-alex.bennee@linaro.org> (raw)
Some versions of glibc have been reported to have problems with
fused-multiply-accumulate operations. If the underlying fma
implementation does a two step operation it will instroduce subtle
rounding errors. Newer versions of the library seem to deal with this
better and modern hardware has fused operations which the library can
use.
Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Emilio G. Cota <cota@braap.org>
---
fpu/softfloat.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 59eac97d10..9c2dbd04b5 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -203,6 +203,25 @@ GEN_INPUT_FLUSH3(float64_input_flush3, float64)
# define QEMU_HARDFLOAT_3F64_USE_FP 0
#endif
+/*
+ * Choose whether to accelerate fused multiply-accumulate operations
+ * with hard float functions. Some versions of glibc's maths library
+ * have been reported to be broken on x86 without FMA instructions.
+ */
+#if defined(__x86_64__)
+/* this was actually reported as glibc-2.12-1.149.el6_6.5.x86_64 was
+ * broken but glibc 2.12-1.209 works but out of caution lets disable
+ * for all older glibcs.
+ */
+#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 12)
+#define QEMU_HARDFLOAT_USE_FMA 0
+#else
+#define QEMU_HARDFLOAT_USE_FMA 1
+#endif
+#else
+#define QEMU_HARDFLOAT_USE_FMA 1
+#endif
+
/*
* QEMU_HARDFLOAT_USE_ISINF chooses whether to use isinf() over
* float{32,64}_is_infinity when !USE_FP.
@@ -1551,6 +1570,9 @@ float32_muladd(float32 xa, float32 xb, float32 xc, int flags, float_status *s)
ub.s = xb;
uc.s = xc;
+ if (!QEMU_HARDFLOAT_USE_FMA) {
+ goto soft;
+ }
if (unlikely(!can_use_fpu(s))) {
goto soft;
}
@@ -1612,6 +1634,9 @@ float64_muladd(float64 xa, float64 xb, float64 xc, int flags, float_status *s)
ub.s = xb;
uc.s = xc;
+ if (!QEMU_HARDFLOAT_USE_FMA) {
+ goto soft;
+ }
if (unlikely(!can_use_fpu(s))) {
goto soft;
}
--
2.17.1
next reply other threads:[~2018-12-20 11:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-20 11:10 Alex Bennée [this message]
2018-12-20 13:10 ` [Qemu-devel] [RFC PATCH] fpu: add compile time check for old glibc/libm and fma Aleksandar Markovic
2018-12-21 14:14 ` Laurent Desnogues
2018-12-21 19:30 ` Emilio G. Cota
2018-12-21 22:01 ` Richard Henderson
2019-01-07 11:50 ` Alex Bennée
2019-01-07 12:42 ` Alex Bennée
2018-12-22 6:40 ` Aleksandar Markovic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181220111008.24954-1-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=aurelien@aurel32.net \
--cc=cota@braap.org \
--cc=laurent.desnogues@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).