SHA256
1
0
forked from pool/glibc
glibc/riscv-fmax-fmin-nan.patch

113 lines
3.0 KiB
Diff
Raw Normal View History

2018-02-22 Andrew Waterman <andrew@sifive.com>
[BZ # 22884]
* 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.
Index: glibc-2.27/sysdeps/riscv/rvd/s_fmax.c
===================================================================
--- glibc-2.27.orig/sysdeps/riscv/rvd/s_fmax.c
+++ glibc-2.27/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)
Index: glibc-2.27/sysdeps/riscv/rvd/s_fmin.c
===================================================================
--- glibc-2.27.orig/sysdeps/riscv/rvd/s_fmin.c
+++ glibc-2.27/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)
Index: glibc-2.27/sysdeps/riscv/rvf/s_fmaxf.c
===================================================================
--- glibc-2.27.orig/sysdeps/riscv/rvf/s_fmaxf.c
+++ glibc-2.27/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)
Index: glibc-2.27/sysdeps/riscv/rvf/s_fminf.c
===================================================================
--- glibc-2.27.orig/sysdeps/riscv/rvf/s_fminf.c
+++ glibc-2.27/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)