public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/maskray/grte] RISC-V: fmax/fmin: Handle signalling NaNs correctly.
@ 2021-08-27 23:44 Fangrui Song
0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2021-08-27 23:44 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=012483cf93fd62162233a9d1be1879c664dd149a
commit 012483cf93fd62162233a9d1be1879c664dd149a
Author: Andrew Waterman <andrew@sifive.com>
Date: Thu Feb 22 14:31:54 2018 -0500
RISC-V: fmax/fmin: Handle signalling NaNs correctly.
RISC-V's fmax(sNAN,4) returns 4 but glibc expects it to return qNAN.
* sysdeps/riscv/rvd/s_fmax.c (__fmax): Handle sNaNs correctly.
* sysdeps/riscv/rvd/s_fmin.c (__fmin): Likewise.
* sysdeps/riscv/rvf/s_fmaxf.c (__fmaxf): Likewise.
* sysdeps/riscv/rvf/s_fminf.c (__fminf): Likewise.
(cherry picked from commit fdcc625376505eacb1125a6aeba57501407a30ec)
Diff:
---
ChangeLog | 7 +++++++
sysdeps/riscv/rvd/s_fmax.c | 11 +++++++++--
sysdeps/riscv/rvd/s_fmin.c | 11 +++++++++--
sysdeps/riscv/rvf/s_fmaxf.c | 11 +++++++++--
sysdeps/riscv/rvf/s_fminf.c | 11 +++++++++--
5 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8b859f637d..394f670363 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-02-22 Andrew Waterman <andrew@sifive.com>
+
+ * sysdeps/riscv/rvd/s_fmax.c (__fmax): Handle sNaNs correctly.
+ * sysdeps/riscv/rvd/s_fmin.c (__fmin): Likewise.
+ * sysdeps/riscv/rvf/s_fmaxf.c (__fmaxf): Likewise.
+ * sysdeps/riscv/rvf/s_fminf.c (__fminf): Likewise.
+
2018-02-22 DJ Delorie <dj@delorie.com>
* sysdeps/riscv/tls-macros.h: Do not initialize $gp.
diff --git a/sysdeps/riscv/rvd/s_fmax.c b/sysdeps/riscv/rvd/s_fmax.c
index ef8f1344ce..22e91bfc4b 100644
--- a/sysdeps/riscv/rvd/s_fmax.c
+++ b/sysdeps/riscv/rvd/s_fmax.c
@@ -17,12 +17,19 @@
<http://www.gnu.org/licenses/>. */
#include <math.h>
+#include <math_private.h>
#include <libm-alias-double.h>
double
__fmax (double x, double y)
{
- asm ("fmax.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
- return x;
+ double res;
+
+ if (__glibc_unlikely ((_FCLASS (x) | _FCLASS (y)) & _FCLASS_SNAN))
+ return x + y;
+ else
+ asm ("fmax.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+
+ return res;
}
libm_alias_double (__fmax, fmax)
diff --git a/sysdeps/riscv/rvd/s_fmin.c b/sysdeps/riscv/rvd/s_fmin.c
index c6ff24cefb..7b35230cac 100644
--- a/sysdeps/riscv/rvd/s_fmin.c
+++ b/sysdeps/riscv/rvd/s_fmin.c
@@ -17,12 +17,19 @@
<http://www.gnu.org/licenses/>. */
#include <math.h>
+#include <math_private.h>
#include <libm-alias-double.h>
double
__fmin (double x, double y)
{
- asm ("fmin.d %0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
- return x;
+ double res;
+
+ if (__glibc_unlikely ((_FCLASS (x) | _FCLASS (y)) & _FCLASS_SNAN))
+ return x + y;
+ else
+ asm ("fmin.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+
+ return res;
}
libm_alias_double (__fmin, fmin)
diff --git a/sysdeps/riscv/rvf/s_fmaxf.c b/sysdeps/riscv/rvf/s_fmaxf.c
index 3293f2f41c..63f7e3d664 100644
--- a/sysdeps/riscv/rvf/s_fmaxf.c
+++ b/sysdeps/riscv/rvf/s_fmaxf.c
@@ -17,12 +17,19 @@
<http://www.gnu.org/licenses/>. */
#include <math.h>
+#include <math_private.h>
#include <libm-alias-float.h>
float
__fmaxf (float x, float y)
{
- asm ("fmax.s %0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
- return x;
+ float res;
+
+ if (__glibc_unlikely ((_FCLASS (x) | _FCLASS (y)) & _FCLASS_SNAN))
+ return x + y;
+ else
+ asm ("fmax.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+
+ return res;
}
libm_alias_float (__fmax, fmax)
diff --git a/sysdeps/riscv/rvf/s_fminf.c b/sysdeps/riscv/rvf/s_fminf.c
index e4411f04b2..82cca4e37d 100644
--- a/sysdeps/riscv/rvf/s_fminf.c
+++ b/sysdeps/riscv/rvf/s_fminf.c
@@ -17,12 +17,19 @@
<http://www.gnu.org/licenses/>. */
#include <math.h>
+#include <math_private.h>
#include <libm-alias-float.h>
float
__fminf (float x, float y)
{
- asm ("fmin.s %0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
- return x;
+ float res;
+
+ if (__glibc_unlikely ((_FCLASS (x) | _FCLASS (y)) & _FCLASS_SNAN))
+ return x + y;
+ else
+ asm ("fmin.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+
+ return res;
}
libm_alias_float (__fmin, fmin)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-27 23:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-27 23:44 [glibc/maskray/grte] RISC-V: fmax/fmin: Handle signalling NaNs correctly Fangrui Song
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 read-only IMAP folder(s) and NNTP newsgroup(s).