From: Keith Packard <keithp@keithp.com>
To: newlib@sourceware.org
Subject: [PATCH 2/2] libm: Set math_errhandling to match library and hardware
Date: Mon, 3 Aug 2020 10:55:04 -0700 [thread overview]
Message-ID: <20200803175504.844738-3-keithp@keithp.com> (raw)
In-Reply-To: <20200803175504.844738-1-keithp@keithp.com>
math_errhandling is specified to contain two bits of information:
1. MATH_ERRNO -- Set when the library sets errno
2. MATH_ERREXCEPT -- Set when math operations report exceptions
MATH_ERRNO should match whether the original math code is compiled in
_IEEE_LIBM mode and the new math code has WANT_ERRNO == 1.
MATH_ERREXCEPT should match whether the underlying hardware has
exception support. This patch adds configurations of this value for
RISC-V, ARM, Aarch64, x86 and x86_64 when using HW float.
Signed-off-by: Keith Packard <keithp@keithp.com>
---
newlib/libc/include/machine/ieeefp.h | 11 +++++++++++
newlib/libc/include/math.h | 12 +++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/newlib/libc/include/machine/ieeefp.h b/newlib/libc/include/machine/ieeefp.h
index aa8a1903b..b0042bbf6 100644
--- a/newlib/libc/include/machine/ieeefp.h
+++ b/newlib/libc/include/machine/ieeefp.h
@@ -87,6 +87,9 @@
# define __IEEE_BYTES_LITTLE_ENDIAN
# endif
#endif
+#ifndef __SOFTFP__
+# define _SUPPORTS_ERREXCEPT
+#endif
#endif
#if defined (__aarch64__)
@@ -96,6 +99,9 @@
#define __IEEE_BIG_ENDIAN
#endif
#define __OBSOLETE_MATH_DEFAULT 0
+#ifdef __ARM_FP
+# define _SUPPORTS_ERREXCEPT
+#endif
#endif
#ifdef __epiphany__
@@ -189,10 +195,14 @@
#ifdef __i386__
#define __IEEE_LITTLE_ENDIAN
+# define _SUPPORTS_ERREXCEPT
#endif
#ifdef __riscv
#define __IEEE_LITTLE_ENDIAN
+#ifdef __riscv_flen
+# define _SUPPORTS_ERREXCEPT
+#endif
#endif
#ifdef __i960__
@@ -386,6 +396,7 @@
#ifdef __x86_64__
#define __IEEE_LITTLE_ENDIAN
+# define _SUPPORTS_ERREXCEPT
#endif
#ifdef __mep__
diff --git a/newlib/libc/include/math.h b/newlib/libc/include/math.h
index 1efc5b92c..4a99b322e 100644
--- a/newlib/libc/include/math.h
+++ b/newlib/libc/include/math.h
@@ -188,7 +188,17 @@ extern int isnan (double);
# define MATH_ERREXCEPT 2
#endif
#ifndef math_errhandling
-# define math_errhandling MATH_ERRNO
+# ifdef _IEEE_LIBM
+# define _MATH_ERRHANDLING_ERRNO MATH_ERRNO
+# else
+# define _MATH_ERRHANDLING_ERRNO 0
+# endif
+# ifdef _SUPPORTS_ERREXCEPT
+# define _MATH_ERRHANDLING_ERREXCEPT MATH_ERREXCEPT
+# else
+# define _MATH_ERRHANDLING_ERREXCEPT 0
+# endif
+# define math_errhandling (_MATH_ERRHANDLING_ERRNO | _MATH_ERRHANDLING_ERREXCEPT)
#endif
extern int __isinff (float x);
--
2.28.0
next prev parent reply other threads:[~2020-08-03 17:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-03 17:55 [PATCH 0/2] libm: Changes to errno and math_errhandling Keith Packard
2020-08-03 17:55 ` [PATCH 1/2] libm/common: Set WANT_ERRNO based on _IEEE_LIBM value Keith Packard
2020-08-03 17:55 ` Keith Packard [this message]
2020-08-04 8:57 ` [PATCH 2/2] libm: Set math_errhandling to match library and hardware Corinna Vinschen
2020-08-04 18:11 ` Keith Packard
2020-08-04 17:31 ` [PATCH 0/2] libm: Changes to errno and math_errhandling Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200803175504.844738-3-keithp@keithp.com \
--to=keithp@keithp.com \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).