This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Convert 0.0/0.0 to NAN


Whoops, that was the wrong patch. Attached is correct patch.

On Wed, Apr 19, 2017 at 6:50 PM, Richard Allen <rsaxvc@rsaxvc.net> wrote:
> With newlib's default compiler flags(-O2 and whatnot),
> the GCC I'm using creates calls to __aeabi_(f|d)div.
> This causes a little extra register copying
> and an unnecessary branch.
>
> Additionally, __aeabi_?div may throw exceptions,
> which is probably not what we want a
> simple assignment to do.
>
> Compiler version tested:
> arm-none-eabi-gcc (15:5.4.1+svn241155-1) 5.4.1 20160919
>
> -Richard
From 823701d0b25a00b892f55498f611a5222a1b80ee Mon Sep 17 00:00:00 2001
From: Richard <rsaxvc@rsaxvc.net>
Date: Wed, 19 Apr 2017 18:24:22 -0500
Subject: [PATCH 1/2] Convert 0.0/0.0 to NAN

With newlib's default compiler flags(-O2 and whatnot),
the GCC I'm using creates calls to __aeabi_fdiv
or __aeabi_ddiv. This causes a little extra
register allocation and an unnecessary branch.

Additionally, __aeabi_*div may throw exceptions,
which is almost certainly not what we want those
lines to do.

Compiler version tested:
arm-none-eabi-gcc (15:5.4.1+svn241155-1) 5.4.1 20160919
---
 newlib/libm/math/w_acosh.c      | 2 +-
 newlib/libm/math/w_atanh.c      | 2 +-
 newlib/libm/math/w_fmod.c       | 2 +-
 newlib/libm/math/w_pow.c        | 2 +-
 newlib/libm/math/w_remainder.c  | 2 +-
 newlib/libm/math/w_sqrt.c       | 2 +-
 newlib/libm/math/wf_acosh.c     | 2 +-
 newlib/libm/math/wf_atanh.c     | 2 +-
 newlib/libm/math/wf_fmod.c      | 2 +-
 newlib/libm/math/wf_pow.c       | 2 +-
 newlib/libm/math/wf_remainder.c | 2 +-
 newlib/libm/math/wf_sqrt.c      | 2 +-
 12 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/newlib/libm/math/w_acosh.c b/newlib/libm/math/w_acosh.c
index 93032600b..f40d9f291 100644
--- a/newlib/libm/math/w_acosh.c
+++ b/newlib/libm/math/w_acosh.c
@@ -106,7 +106,7 @@ MATHREF
             exc.name = "acosh";
 	    exc.err = 0;
 	    exc.arg1 = exc.arg2 = x;
-            exc.retval = 0.0/0.0;
+            exc.retval = NAN;
             if (_LIB_VERSION == _POSIX_)
                errno = EDOM;
             else if (!matherr(&exc)) {
diff --git a/newlib/libm/math/w_atanh.c b/newlib/libm/math/w_atanh.c
index 07fd45962..9ffa29e48 100644
--- a/newlib/libm/math/w_atanh.c
+++ b/newlib/libm/math/w_atanh.c
@@ -106,7 +106,7 @@ QUICKREF
                 exc.name = "atanh";
 		exc.err = 0;
 		exc.arg1 = exc.arg2 = x;
-                exc.retval = 0.0/0.0;
+                exc.retval = NAN;
                 if (_LIB_VERSION == _POSIX_)
                   errno = EDOM;
                 else if (!matherr(&exc)) {
diff --git a/newlib/libm/math/w_fmod.c b/newlib/libm/math/w_fmod.c
index f9f72c745..616a291bd 100644
--- a/newlib/libm/math/w_fmod.c
+++ b/newlib/libm/math/w_fmod.c
@@ -90,7 +90,7 @@ PORTABILITY
             if (_LIB_VERSION == _SVID_)
                exc.retval = x;
 	    else
-	       exc.retval = 0.0/0.0;
+	       exc.retval = NAN;
             if (_LIB_VERSION == _POSIX_)
                errno = EDOM;
             else if (!matherr(&exc)) {
diff --git a/newlib/libm/math/w_pow.c b/newlib/libm/math/w_pow.c
index ebf7be328..685507124 100644
--- a/newlib/libm/math/w_pow.c
+++ b/newlib/libm/math/w_pow.c
@@ -157,7 +157,7 @@ PORTABILITY
 		    if (_LIB_VERSION == _SVID_) 
 		        exc.retval = 0.0;
 		    else 
-		        exc.retval = 0.0/0.0;	/* X/Open allow NaN */
+		        exc.retval = NAN;	/* X/Open allow NaN */
 		    if (_LIB_VERSION == _POSIX_) 
 		        errno = EDOM;
 		    else if (!matherr(&exc)) {
diff --git a/newlib/libm/math/w_remainder.c b/newlib/libm/math/w_remainder.c
index e4c196716..01245755c 100644
--- a/newlib/libm/math/w_remainder.c
+++ b/newlib/libm/math/w_remainder.c
@@ -74,7 +74,7 @@ PORTABILITY
 	    exc.err = 0;
 	    exc.arg1 = x;
 	    exc.arg2 = y;
-            exc.retval = 0.0/0.0;
+            exc.retval = NAN;
             if (_LIB_VERSION == _POSIX_)
                errno = EDOM;
             else if (!matherr(&exc)) {
diff --git a/newlib/libm/math/w_sqrt.c b/newlib/libm/math/w_sqrt.c
index 23a793ce7..b2b1f8d78 100644
--- a/newlib/libm/math/w_sqrt.c
+++ b/newlib/libm/math/w_sqrt.c
@@ -76,7 +76,7 @@ PORTABILITY
 	  if (_LIB_VERSION == _SVID_)
 	    exc.retval = 0.0;
           else
-            exc.retval = 0.0/0.0;
+            exc.retval = NAN;
           if (_LIB_VERSION == _POSIX_)
             errno = EDOM;
           else if (!matherr(&exc)) {
diff --git a/newlib/libm/math/wf_acosh.c b/newlib/libm/math/wf_acosh.c
index fc8ec3a0a..3c25447e8 100644
--- a/newlib/libm/math/wf_acosh.c
+++ b/newlib/libm/math/wf_acosh.c
@@ -41,7 +41,7 @@
             exc.name = "acoshf";
 	    exc.err = 0;
 	    exc.arg1 = exc.arg2 = (double)x;
-            exc.retval = 0.0/0.0;
+            exc.retval = NAN;
             if (_LIB_VERSION == _POSIX_)
                errno = EDOM;
             else if (!matherr(&exc)) {
diff --git a/newlib/libm/math/wf_atanh.c b/newlib/libm/math/wf_atanh.c
index 565630411..a6a0a28cf 100644
--- a/newlib/libm/math/wf_atanh.c
+++ b/newlib/libm/math/wf_atanh.c
@@ -41,7 +41,7 @@
                 exc.name = "atanhf";
 		exc.err = 0;
 		exc.arg1 = exc.arg2 = (double)x;
-                exc.retval = 0.0/0.0;
+                exc.retval = NAN;
                 if (_LIB_VERSION == _POSIX_)
                   errno = EDOM;
                 else if (!matherr(&exc)) {
diff --git a/newlib/libm/math/wf_fmod.c b/newlib/libm/math/wf_fmod.c
index 030ca3e7a..b14339a20 100644
--- a/newlib/libm/math/wf_fmod.c
+++ b/newlib/libm/math/wf_fmod.c
@@ -44,7 +44,7 @@
             if (_LIB_VERSION == _SVID_)
                exc.retval = x;
 	    else
-	       exc.retval = 0.0/0.0;
+	       exc.retval = NAN;
             if (_LIB_VERSION == _POSIX_)
                errno = EDOM;
             else if (!matherr(&exc)) {
diff --git a/newlib/libm/math/wf_pow.c b/newlib/libm/math/wf_pow.c
index a30f8808e..bd9de0ad0 100644
--- a/newlib/libm/math/wf_pow.c
+++ b/newlib/libm/math/wf_pow.c
@@ -107,7 +107,7 @@
 		    if (_LIB_VERSION == _SVID_) 
 		        exc.retval = 0.0;
 		    else 
-		        exc.retval = 0.0/0.0;	/* X/Open allow NaN */
+		        exc.retval = NAN;	/* X/Open allow NaN */
 		    if (_LIB_VERSION == _POSIX_) 
 		        errno = EDOM;
 		    else if (!matherr(&exc)) {
diff --git a/newlib/libm/math/wf_remainder.c b/newlib/libm/math/wf_remainder.c
index f38c23785..48c395f9c 100644
--- a/newlib/libm/math/wf_remainder.c
+++ b/newlib/libm/math/wf_remainder.c
@@ -41,7 +41,7 @@
 	    exc.err = 0;
 	    exc.arg1 = (double)x;
 	    exc.arg2 = (double)y;
-            exc.retval = 0.0/0.0;
+            exc.retval = NAN;
             if (_LIB_VERSION == _POSIX_)
                errno = EDOM;
             else if (!matherr(&exc)) {
diff --git a/newlib/libm/math/wf_sqrt.c b/newlib/libm/math/wf_sqrt.c
index 4536ba0ac..96814bd73 100644
--- a/newlib/libm/math/wf_sqrt.c
+++ b/newlib/libm/math/wf_sqrt.c
@@ -43,7 +43,7 @@
             if (_LIB_VERSION == _SVID_)
               exc.retval = 0.0;
             else
-              exc.retval = 0.0/0.0;
+              exc.retval = NAN;
             if (_LIB_VERSION == _POSIX_) 
               errno = EDOM;
             else if (!matherr(&exc)) {
-- 
2.11.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]