diff mbox series

Improve math_errhandling

Message ID HE1PR0801MB2058FC670374E87D486379C783560@HE1PR0801MB2058.eurprd08.prod.outlook.com
State New
Headers show
Series Improve math_errhandling | expand

Commit Message

Wilco Dijkstra Nov. 8, 2017, 2:41 p.m. UTC
This is based on discussion in https://gcc.gnu.org/ml/gcc-patches/2017-10/msg02096.html.

Currently math_errhandling is always set to MATH_ERRNO | MATH_ERREXCEPT
even if -fno-math-errno is used.  It is not defined at all when fast-math
is used, eventhough the GLIBC implementation always supports exceptions
(on hardware floating point implementations).  Improve this to take
__NO_MATH_ERRNO__ into account and update comment.

OK for commit?

ChangeLog:
2017-11-08  Wilco Dijkstra  <wdijkstr@arm.com>

	* math/math.h (math_errhandling): Add __NO_MATH_ERRNO__ check.

--

Comments

Joseph Myers Nov. 8, 2017, 4:47 p.m. UTC | #1
On Wed, 8 Nov 2017, Wilco Dijkstra wrote:

> This is based on discussion in https://gcc.gnu.org/ml/gcc-patches/2017-10/msg02096.html.
> 
> Currently math_errhandling is always set to MATH_ERRNO | MATH_ERREXCEPT
> even if -fno-math-errno is used.  It is not defined at all when fast-math
> is used, eventhough the GLIBC implementation always supports exceptions
> (on hardware floating point implementations).  Improve this to take
> __NO_MATH_ERRNO__ into account and update comment.

Some bits/mathinline.h implementations might not produce appropriate 
exceptions with -ffast-math.  Likewise versions inlined by GCC.

The header definitely needs to check for __FAST_MATH__.  There is a case 
for defining math_errhandling to 0 in the __FAST_MATH__ case (a 
nonconforming value, but -ffast-math is a nonconforming mode, and 0 
accurately reflects the situation that neither errno nor exceptions can be 
relied upon in that case) rather than the existing state of being 
undefined (also nonconforming).  Note that GCC versions before GCC 5 don't 
define __NO_MATH_ERRNO__ at all.
Wilco Dijkstra Dec. 21, 2017, 7:53 p.m. UTC | #2
Joseph Myers wrote:
>
> The header definitely needs to check for __FAST_MATH__.  There is a case 
> for defining math_errhandling to 0 in the __FAST_MATH__ case (a 
> nonconforming value, but -ffast-math is a nonconforming mode, and 0 
> accurately reflects the situation that neither errno nor exceptions can be 
> relied upon in that case) rather than the existing state of being 
> undefined (also nonconforming).  Note that GCC versions before GCC 5 don't 
> define __NO_MATH_ERRNO__ at all.

OK, setting to 0 for __FAST_MATH__ seems reasonable. Here is the revised patch:

Currently math_errhandling is always set to MATH_ERRNO | MATH_ERREXCEPT
even if -fno-math-errno is used.  It is not defined at all when fast-math
is used.  Set it to 0 with fast-math - this is noncomforming but more
useful than not define math_errhandling at all. Also take __NO_MATH_ERRNO__
into account and update comment.

ChangeLog:
2017-12-21  Wilco Dijkstra  <wdijkstr@arm.com>

	* math/math.h (math_errhandling): Add __NO_MATH_ERRNO__ check.
--

diff --git a/math/math.h b/math/math.h
index 72d7dc59391af71c4db9634998463b4f947b9f09..9bf0c66e862d15277f8e4f31f3b35b9d4a3ad958 100644
--- a/math/math.h
+++ b/math/math.h
@@ -665,10 +665,16 @@ enum
 # define MATH_ERRNO	1	/* errno set by math functions.  */
 # define MATH_ERREXCEPT	2	/* Exceptions raised by math functions.  */
 
-/* By default all functions support both errno and exception handling.
-   In gcc's fast math mode and if inline functions are defined this
-   might not be true.  */
-# ifndef __FAST_MATH__
+/* By default all math functions support both errno and exception handling
+   (except for soft floating point implementations which may only support
+   errno handling).  If errno handling is disabled, exceptions are still
+   supported by GLIBC.  Set math_errhandling to 0 with -ffast-math (this is
+   nonconforming but it is more useful than leaving it undefined).  */
+# ifdef __FAST_MATH__
+#  define math_errhandling	0
+# elif defined __NO_MATH_ERRNO__
+#  define math_errhandling	(MATH_ERREXCEPT)
+# else
 #  define math_errhandling	(MATH_ERRNO | MATH_ERREXCEPT)
 # endif
Joseph Myers Dec. 21, 2017, 8:41 p.m. UTC | #3
On Thu, 21 Dec 2017, Wilco Dijkstra wrote:

> OK, setting to 0 for __FAST_MATH__ seems reasonable. Here is the revised patch:
> 
> Currently math_errhandling is always set to MATH_ERRNO | MATH_ERREXCEPT
> even if -fno-math-errno is used.  It is not defined at all when fast-math
> is used.  Set it to 0 with fast-math - this is noncomforming but more
> useful than not define math_errhandling at all. Also take __NO_MATH_ERRNO__
> into account and update comment.
> 
> ChangeLog:
> 2017-12-21  Wilco Dijkstra  <wdijkstr@arm.com>
> 
> 	* math/math.h (math_errhandling): Add __NO_MATH_ERRNO__ check.

This patch is OK.
diff mbox series

Patch

diff --git a/math/math.h b/math/math.h
index 5ad8156555daf583514e214c2de0aca782871788..d46c26533eff01dfbcee8f59d022febdbdb8d769 100644
--- a/math/math.h
+++ b/math/math.h
@@ -506,10 +506,15 @@  enum
 # define MATH_ERRNO	1	/* errno set by math functions.  */
 # define MATH_ERREXCEPT	2	/* Exceptions raised by math functions.  */
 
-/* By default all functions support both errno and exception handling.
-   In gcc's fast math mode and if inline functions are defined this
-   might not be true.  */
-# ifndef __FAST_MATH__
+/* By default all math functions support both errno and exception handling
+   (except for soft floating point implementations which may only support
+   errno handling).  If errno handling is disabled, exceptions are still
+   supported by GLIBC.  If a target adds inlines which do not support
+   exceptions, math_errhandling must be undefined (since setting it to 0
+   is not standard compliant).  */
+# ifdef __NO_MATH_ERRNO__
+#  define math_errhandling	(MATH_ERREXCEPT)
+# else
 #  define math_errhandling	(MATH_ERRNO | MATH_ERREXCEPT)
 # endif