public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [2.27 COMMITTED 2/3] RISC-V: fmax/fmin: Handle signalling NaNs correctly.
  2018-03-19 18:42 [2.27 COMMITTED 1/3] RISC-V: Do not initialize $gp in TLS macros Aurelien Jarno
@ 2018-03-19 18:42 ` Aurelien Jarno
  2018-03-19 18:42 ` [2.27 COMMITTED 3/3] Update ChangeLog for BZ 22884 - riscv fmax/fmin Aurelien Jarno
  2018-03-19 18:44 ` [2.27 COMMITTED 1/3] RISC-V: Do not initialize $gp in TLS macros Aurelien Jarno
  2 siblings, 0 replies; 4+ messages in thread
From: Aurelien Jarno @ 2018-03-19 18:42 UTC (permalink / raw)
  To: libc-alpha; +Cc: Andrew Waterman

From: Andrew Waterman <andrew@sifive.com>

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)
---
 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 8b859f637d6..394f6703638 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 ef8f1344ce5..22e91bfc4b8 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 c6ff24cefb8..7b35230cacd 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 3293f2f41ca..63f7e3d6648 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 e4411f04b25..82cca4e37d8 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)
-- 
2.16.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [2.27 COMMITTED 1/3] RISC-V: Do not initialize $gp in TLS macros.
@ 2018-03-19 18:42 Aurelien Jarno
  2018-03-19 18:42 ` [2.27 COMMITTED 2/3] RISC-V: fmax/fmin: Handle signalling NaNs correctly Aurelien Jarno
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Aurelien Jarno @ 2018-03-19 18:42 UTC (permalink / raw)
  To: libc-alpha; +Cc: DJ Delorie

From: DJ Delorie <dj@redhat.com>

RISC-V TLS doesn't require GP to be initialized, and doing so breaks
TLS in a shared object.

(cherry picked from commit 8090720a87e42fddc31396f6126112d4b8014d8e)
---
 ChangeLog                  |  4 ++++
 sysdeps/riscv/tls-macros.h | 20 +++-----------------
 2 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 17075925fa6..8b859f637d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2018-02-22  DJ Delorie  <dj@delorie.com>
+
+	* sysdeps/riscv/tls-macros.h: Do not initialize $gp.
+
 2018-03-16  Rafal Luzynski  <digitalfreak@lingonborough.com>
 
 	[BZ #22963]
diff --git a/sysdeps/riscv/tls-macros.h b/sysdeps/riscv/tls-macros.h
index 5433ed9d16c..7f0dd926d0c 100644
--- a/sysdeps/riscv/tls-macros.h
+++ b/sysdeps/riscv/tls-macros.h
@@ -23,19 +23,9 @@
 #include <sysdep.h>
 #include "dl-tls.h"
 
-#define LOAD_GP						\
-	".option push\n\t"				\
-	".option norelax\n\t"				\
-	"la gp, __global_pointer$\n\t"			\
-	".option pop\n\t"
-
-#define UNLOAD_GP
-
 #define TLS_GD(x)					\
 	({ void *__result;				\
-	asm (LOAD_GP					\
-	     "la.tls.gd %0, " #x "\n\t"			\
-	     UNLOAD_GP					\
+	asm ("la.tls.gd %0, " #x "\n\t"			\
 	     : "=r" (__result));			\
 	__tls_get_addr (__result); })
 
@@ -43,19 +33,15 @@
 
 #define TLS_IE(x)					\
 	({ void *__result;				\
-	asm (LOAD_GP					\
-	     "la.tls.ie %0, " #x "\n\t"			\
+	asm ("la.tls.ie %0, " #x "\n\t"			\
 	     "add %0, %0, tp\n\t"			\
-	     UNLOAD_GP					\
 	     : "=r" (__result));			\
 	__result; })
 
 #define TLS_LE(x)					\
 	({ void *__result;				\
-	asm (LOAD_GP					\
-	     "lui %0, %%tprel_hi(" #x ")\n\t"		\
+	asm ("lui %0, %%tprel_hi(" #x ")\n\t"		\
 	     "add %0, %0, tp, %%tprel_add(" #x ")\n\t"	\
 	     "addi %0, %0, %%tprel_lo(" #x ")\n\t"	\
-	     UNLOAD_GP					\
 	     : "=r" (__result));			\
 	__result; })
-- 
2.16.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [2.27 COMMITTED 3/3] Update ChangeLog for BZ 22884 - riscv fmax/fmin
  2018-03-19 18:42 [2.27 COMMITTED 1/3] RISC-V: Do not initialize $gp in TLS macros Aurelien Jarno
  2018-03-19 18:42 ` [2.27 COMMITTED 2/3] RISC-V: fmax/fmin: Handle signalling NaNs correctly Aurelien Jarno
@ 2018-03-19 18:42 ` Aurelien Jarno
  2018-03-19 18:44 ` [2.27 COMMITTED 1/3] RISC-V: Do not initialize $gp in TLS macros Aurelien Jarno
  2 siblings, 0 replies; 4+ messages in thread
From: Aurelien Jarno @ 2018-03-19 18:42 UTC (permalink / raw)
  To: libc-alpha; +Cc: DJ Delorie

From: DJ Delorie <dj@redhat.com>

(cherry picked from commit 7e04eb2932d3126c721ee2bc0d664a5bbea2f41f)
---
 ChangeLog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ChangeLog b/ChangeLog
index 394f6703638..23ff0ea3057 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 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.
-- 
2.16.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [2.27 COMMITTED 1/3] RISC-V: Do not initialize $gp in TLS macros.
  2018-03-19 18:42 [2.27 COMMITTED 1/3] RISC-V: Do not initialize $gp in TLS macros Aurelien Jarno
  2018-03-19 18:42 ` [2.27 COMMITTED 2/3] RISC-V: fmax/fmin: Handle signalling NaNs correctly Aurelien Jarno
  2018-03-19 18:42 ` [2.27 COMMITTED 3/3] Update ChangeLog for BZ 22884 - riscv fmax/fmin Aurelien Jarno
@ 2018-03-19 18:44 ` Aurelien Jarno
  2 siblings, 0 replies; 4+ messages in thread
From: Aurelien Jarno @ 2018-03-19 18:44 UTC (permalink / raw)
  To: libc-alpha

On 2018-03-19 19:42, Aurelien Jarno wrote:
> From: DJ Delorie <dj@redhat.com>
> 
> RISC-V TLS doesn't require GP to be initialized, and doing so breaks
> TLS in a shared object.
> 
> (cherry picked from commit 8090720a87e42fddc31396f6126112d4b8014d8e)
> ---
>  ChangeLog                  |  4 ++++
>  sysdeps/riscv/tls-macros.h | 20 +++-----------------
>  2 files changed, 7 insertions(+), 17 deletions(-)

Oops as the subject says, those patches are for 2.27. Sorry for sending
them to the wrong list, please ignore.

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-19 18:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-19 18:42 [2.27 COMMITTED 1/3] RISC-V: Do not initialize $gp in TLS macros Aurelien Jarno
2018-03-19 18:42 ` [2.27 COMMITTED 2/3] RISC-V: fmax/fmin: Handle signalling NaNs correctly Aurelien Jarno
2018-03-19 18:42 ` [2.27 COMMITTED 3/3] Update ChangeLog for BZ 22884 - riscv fmax/fmin Aurelien Jarno
2018-03-19 18:44 ` [2.27 COMMITTED 1/3] RISC-V: Do not initialize $gp in TLS macros Aurelien Jarno

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).