new module 'fenv-environment'

2023-11-05 Thread Bruno Haible
Here comes the module 'fenv-environment', which implements the ISO C 99 
functions
  fegetenv
  feholdexcept
  fesetenv
  feupdateenv
and the macro
  FE_DFL_ENV.

This is the largest module in the fenv-* series, because of the massive amount
of platform bugs that need to be worked around. No operating system gets all
four functions right on all CPUs! On many platforms, there's even two or three
bugs to work around together. Really, it feels like I'm the first person in the
world who has written unit tests for these functions.

Additionally, it has complexity because the fenv_t type is dependent on OS and
architecture. But fortunately, for most architectures, it is merely binary-
equivalent to an 'unsigned int' or 'unsigned long'.


2023-11-05  Bruno Haible  

fenv-environment: Add tests.
* tests/test-fenv-env-1.c: New file.
* tests/test-fenv-env-2.c: New file.
* tests/test-fenv-env-3.c: New file.
* tests/test-fenv-env-4.c: New file.
* tests/test-fenv-env-5.sh: New file.
* tests/test-fenv-env-5.c: New file.
* modules/fenv-environment-tests: New file.

fenv-environment: New module.
* lib/fenv.in.h (fenv_t) [hppa]: Remove the __exception field.
(FE_DFL_ENV): Override if  exists but HAVE_FE_DFL_ENV is not
defined.
(fegetenv, fesetenv, feupdateenv, feholdexcept): New declarations.
* lib/fenv-env.c: New file, based on glibc.
* lib/fenv-env-hold.c: New file.
* lib/fenv-env-update.c: New file.
* m4/fenv-environment.m4: New file.
* m4/mathfunc.m4 (gl_MATHFUNC): Handle also the 'fenv_t *' type.
* m4/fenv_h.m4 (gl_FENV_H_DEFAULTS): Initialize REPLACE_FEGETENV,
REPLACE_FEHOLDEXCEPT, REPLACE_FESETENV, REPLACE_FEUPDATEENV.
* modules/fenv (Makefile.am): Substitute REPLACE_FEGETENV,
REPLACE_FEHOLDEXCEPT, REPLACE_FESETENV, REPLACE_FEUPDATEENV.
* modules/fenv-environment: New file.
* doc/posix-functions/fegetenv.texi: Mention the new module and the bugs
on glibc, macOS, AIX.
* doc/posix-functions/feholdexcept.texi: Mention the new module and the
bugs on glibc, musl libc, FreeBSD, AIX, mingw, MSVC.
* doc/posix-functions/fesetenv.texi: Mention the new module and the bugs
on musl libc, FreeBSD, NetBSD, AIX, Solaris, Cygwin, mingw, MSVC.
* doc/posix-functions/feupdateenv.texi: Mention the new module and the
bugs on glibc, musl libc, macOS, FreeBSD, AIX, Solaris, mingw, MSVC.

From c19cabc0bf5d8e1afec9fd50fee47104000fa3e4 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 5 Nov 2023 15:00:29 +0100
Subject: [PATCH 1/2] fenv-environment: New module.

* lib/fenv.in.h (fenv_t) [hppa]: Remove the __exception field.
(FE_DFL_ENV): Override if  exists but HAVE_FE_DFL_ENV is not
defined.
(fegetenv, fesetenv, feupdateenv, feholdexcept): New declarations.
* lib/fenv-env.c: New file, based on glibc.
* lib/fenv-env-hold.c: New file.
* lib/fenv-env-update.c: New file.
* m4/fenv-environment.m4: New file.
* m4/mathfunc.m4 (gl_MATHFUNC): Handle also the 'fenv_t *' type.
* m4/fenv_h.m4 (gl_FENV_H_DEFAULTS): Initialize REPLACE_FEGETENV,
REPLACE_FEHOLDEXCEPT, REPLACE_FESETENV, REPLACE_FEUPDATEENV.
* modules/fenv (Makefile.am): Substitute REPLACE_FEGETENV,
REPLACE_FEHOLDEXCEPT, REPLACE_FESETENV, REPLACE_FEUPDATEENV.
* modules/fenv-environment: New file.
* doc/posix-functions/fegetenv.texi: Mention the new module and the bugs
on glibc, macOS, AIX.
* doc/posix-functions/feholdexcept.texi: Mention the new module and the
bugs on glibc, musl libc, FreeBSD, AIX, mingw, MSVC.
* doc/posix-functions/fesetenv.texi: Mention the new module and the bugs
on musl libc, FreeBSD, NetBSD, AIX, Solaris, Cygwin, mingw, MSVC.
* doc/posix-functions/feupdateenv.texi: Mention the new module and the
bugs on glibc, musl libc, macOS, FreeBSD, AIX, Solaris, mingw, MSVC.
---
 ChangeLog |   26 +
 doc/posix-functions/fegetenv.texi |   16 +-
 doc/posix-functions/feholdexcept.texi |   25 +-
 doc/posix-functions/fesetenv.texi |   25 +-
 doc/posix-functions/feupdateenv.texi  |   35 +-
 lib/fenv-env-hold.c   |   32 +
 lib/fenv-env-update.c |   31 +
 lib/fenv-env.c| 1165 +
 lib/fenv.in.h |   91 +-
 m4/fenv-environment.m4|  515 +++
 m4/fenv_h.m4  |6 +-
 m4/mathfunc.m4|6 +-
 modules/fenv  |4 +
 modules/fenv-environment  |   56 ++
 14 files changed, 2013 insertions(+), 20 deletions(-)
 create mode 100644 lib/fenv-env-hold.c
 create mode 100644 lib/fenv-env-update.c
 create mode 100644 lib/fenv-env.c
 create mode 100644 m4/fenv-environment.m4
 create mode 100644 modules/fenv-environment

diff --git a/ChangeLog b/ChangeLog
index 7c2d58913d..18ee7639c2 100644
--- a/ChangeLog
+++ 

Re: new module 'fenv-exceptions-state-c99'

2023-11-04 Thread Bruno Haible
This patch fixes a compilation error on FreeBSD, when I use

  gl_cv_func_fesetexceptflag_in_libm=no \
  gl_cv_func_fesetexceptflag_no_libm=no \
  ./configure

for testing the override code.


2023-11-04  Bruno Haible  

fenv-exceptions-state-c99: Fix compilation error on FreeBSD.
* lib/fenv.in.h (fegetexceptflag, fesetexceptflag): On FreeBSD, use an
rpl_ prefix, to avoid a conflict with an inline definition in FreeBSD's
.

diff --git a/lib/fenv.in.h b/lib/fenv.in.h
index 4fd5ea2f1a..b1c52d6e27 100644
--- a/lib/fenv.in.h
+++ b/lib/fenv.in.h
@@ -708,7 +708,7 @@ typedef unsigned long fexcept_t;
 #if @GNULIB_FEGETEXCEPTFLAG@
 /* Stores the current floating-point exception status flags denoted
by EXCEPTIONS in *SAVED_FLAGS.  */
-# if @REPLACE_FEGETEXCEPTFLAG@
+# if @REPLACE_FEGETEXCEPTFLAG@ || (!@HAVE_FEGETEXCEPTFLAG@ && defined 
__FreeBSD__) /* has an inline definition */
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef fegetexceptflag
 #   define fegetexceptflag rpl_fegetexceptflag
@@ -731,7 +731,7 @@ _GL_CXXALIASWARN (fegetexceptflag);
 #if @GNULIB_FESETEXCEPTFLAG@
 /* Copies the flags denoted by EXCEPTIONS from *SAVED_FLAGS to the
floating-point exception status flags.  */
-# if @REPLACE_FESETEXCEPTFLAG@
+# if @REPLACE_FESETEXCEPTFLAG@ || (!@HAVE_FESETEXCEPTFLAG@ && defined 
__FreeBSD__) /* has an inline definition */
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef fesetexceptflag
 #   define fesetexceptflag rpl_fesetexceptflag






Re: new module 'fenv-exceptions-tracking-c99'

2023-11-04 Thread Bruno Haible
Two small patches:
1) On NetBSD 8.0/sparc, I see a test failure of test-fenv-except-tracking-2
   regarding 'long double's. Certainly due to the software floating-point
   routines.
2) The Cygwin fraiseexcept bug has been acknowledged and fixed:
   


2023-11-04  Bruno Haible  

doc: Update info about Cygwin feraiseexcept bug.
* doc/posix-functions/feraiseexcept.texi: Update info regarding Cygwin.

2023-11-04  Bruno Haible  

fenv-exceptions-tracking-c99 tests: Avoid test failure on NetBSD/sparc.
* tests/test-fenv-except-tracking-2.c (main): On NetBSD/sparc, skip the
'long double' test.

>From 10070b43647c633105f2f2f3c91f25410f921e28 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sat, 4 Nov 2023 16:23:16 +0100
Subject: [PATCH 1/2] fenv-exceptions-tracking-c99 tests: Avoid test failure on
 NetBSD/sparc.

* tests/test-fenv-except-tracking-2.c (main): On NetBSD/sparc, skip the
'long double' test.
---
 ChangeLog   | 6 ++
 tests/test-fenv-except-tracking-2.c | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b6f7d339d1..a5bd7473c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-11-04  Bruno Haible  
+
+	fenv-exceptions-tracking-c99 tests: Avoid test failure on NetBSD/sparc.
+	* tests/test-fenv-except-tracking-2.c (main): On NetBSD/sparc, skip the
+	'long double' test.
+
 2023-11-04  Bruno Haible  
 
 	fenv-exceptions-tracking-c99: Fix fetestexcept() override for AIX.
diff --git a/tests/test-fenv-except-tracking-2.c b/tests/test-fenv-except-tracking-2.c
index e6f9bf1f9d..1d8529ad04 100644
--- a/tests/test-fenv-except-tracking-2.c
+++ b/tests/test-fenv-except-tracking-2.c
@@ -66,11 +66,11 @@ main (int argc, char *argv[])
   case 'l':
 /* This test does not work on Linux/loongarch64 with glibc 2.37.
Likewise on Linux/alpha with glibc 2.7 on Linux 2.6.26.
-   Likewise on FreeBSD 12.2/sparc.
+   Likewise on FreeBSD 12.2/sparc and NetBSD 8.0/sparc.
Cause unknown.  */
 #if !((__GLIBC__ >= 2 && defined __loongarch__) \
   || ((__GLIBC__ == 2 && __GLIBC_MINOR__ < 36) && defined __alpha) \
-  || (defined __FreeBSD__ && defined __sparc))
+  || ((defined __FreeBSD__ || defined __NetBSD__) && defined __sparc))
 {
   volatile long double a, b;
   _GL_UNUSED volatile long double c;
-- 
2.34.1

>From 421e04d7f60aba683c00bd071dca47dcce8d5b50 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sat, 4 Nov 2023 16:27:09 +0100
Subject: [PATCH 2/2] doc: Update info about Cygwin feraiseexcept bug.

* doc/posix-functions/feraiseexcept.texi: Update info regarding Cygwin.
---
 ChangeLog  | 5 +
 doc/posix-functions/feraiseexcept.texi | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index a5bd7473c4..423b490331 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-11-04  Bruno Haible  
+
+	doc: Update info about Cygwin feraiseexcept bug.
+	* doc/posix-functions/feraiseexcept.texi: Update info regarding Cygwin.
+
 2023-11-04  Bruno Haible  
 
 	fenv-exceptions-tracking-c99 tests: Avoid test failure on NetBSD/sparc.
diff --git a/doc/posix-functions/feraiseexcept.texi b/doc/posix-functions/feraiseexcept.texi
index a4f2ebab01..63a79a 100644
--- a/doc/posix-functions/feraiseexcept.texi
+++ b/doc/posix-functions/feraiseexcept.texi
@@ -17,7 +17,7 @@
 @item
 This function does not trigger traps on
 @c https://sourceware.org/pipermail/cygwin/2023-October/254667.html
-Cygwin 3.4.6/x86_64.
+Cygwin 3.4.9/x86_64.
 @end itemize
 
 Portability problems not fixed by Gnulib:
-- 
2.34.1



Re: new module 'fenv-rounding'

2023-11-04 Thread Bruno Haible
On NetBSD 8.0/sparc64, I see a test failure of the fenv-rounding test for
'long double' operations. On this platform, 'long double' operations are
implemented by a software floating-point library. Apparently this library
code ignores the rounding direction.

This patch avoids the test failure and documents the problem.


2023-11-04  Bruno Haible  

fenv-rounding: Avoid a test failure on NetBSD/sparc64.
* tests/test-fenv-round.c (test_towardzero, test_upward, test_downward):
Skip the 'long double' tests on NetBSD/sparc64.
* doc/posix-functions/fesetround.texi: Mention the problem with
'long double' operations on some platforms.

diff --git a/doc/posix-functions/fesetround.texi 
b/doc/posix-functions/fesetround.texi
index f0c74c3467..73d6c034fa 100644
--- a/doc/posix-functions/fesetround.texi
+++ b/doc/posix-functions/fesetround.texi
@@ -18,4 +18,7 @@
 
 Portability problems not fixed by Gnulib:
 @itemize
+@item
+The rounding mode has no effect on @code{long double} operations on some 
platforms:
+FreeBSD/arm64, NetBSD/sparc64.
 @end itemize
diff --git a/tests/test-fenv-round.c b/tests/test-fenv-round.c
index aba783cc79..b697fb1301 100644
--- a/tests/test-fenv-round.c
+++ b/tests/test-fenv-round.c
@@ -45,7 +45,7 @@ test_towardzero ()
 a = -1; b = 3; q = a / b; p = b * q;
 ASSERT (p > a);
   }
-#if !(defined __FreeBSD__ && defined __aarch64__)
+#if !((defined __FreeBSD__ && defined __aarch64__) || (defined __NetBSD__ && 
defined __sparcv9 /* sparc64 */))
   {
 long double volatile a, b, q, p;
 
@@ -80,7 +80,7 @@ test_upward ()
 a = -1; b = 3; q = a / b; p = b * q;
 ASSERT (p > a);
   }
-#if !(defined __FreeBSD__ && defined __aarch64__)
+#if !((defined __FreeBSD__ && defined __aarch64__) || (defined __NetBSD__ && 
defined __sparcv9 /* sparc64 */))
   {
 long double volatile a, b, q, p;
 
@@ -115,7 +115,7 @@ test_downward ()
 a = -1; b = 3; q = a / b; p = b * q;
 ASSERT (p < a);
   }
-#if !(defined __FreeBSD__ && defined __aarch64__)
+#if !((defined __FreeBSD__ && defined __aarch64__) || (defined __NetBSD__ && 
defined __sparcv9 /* sparc64 */))
   {
 long double volatile a, b, q, p;
 






Re: new module 'fenv-rounding'

2023-11-04 Thread Bruno Haible
>   * m4/fenv-rounding.m4: New file.

Oops, there was a mistake here, and in other places as well: Everywhere where
an Autoconf macro uses $host, $host_os, or $host_cpu, it needs to first
require AC_CANONICAL_HOST. Otherwise the value of such a variable may come out
as empty.


2023-11-04  Bruno Haible  

fenv-rounding et al.: Require AC_CANONICAL_HOST before accessing $host.
* m4/fenv-rounding.m4 (gl_FENV_ROUNDING): Require AC_CANONICAL_HOST.
* m4/c32rtomb.m4 (gl_FUNC_C32RTOMB): Likewise.
* m4/getrandom.m4 (gl_FUNC_GETRANDOM): Likewise.
* m4/iswdigit.m4 (gl_FUNC_ISWDIGIT): Likewise.
* m4/iswpunct.m4 (gl_FUNC_ISWPUNCT): Likewise.
* m4/iswxdigit.m4 (gl_FUNC_ISWXDIGIT): Likewise.
* m4/strerrorname_np.m4 (gl_FUNC_STRERRORNAME_NP): Likewise.
* m4/strfmon_l.m4 (gl_FUNC_STRFMON_L): Likewise.
* m4/unlink-busy.m4 (gl_FUNC_UNLINK_BUSY_TEXT): Likewise.
* m4/vasnprintf.m4 (gl_PREREQ_VASNWPRINTF): Likewise.
* m4/wcscmp.m4 (gl_FUNC_WCSCMP): Likewise.
* m4/wcsncmp.m4 (gl_FUNC_WCSNCMP): Likewise.

diff --git a/m4/c32rtomb.m4 b/m4/c32rtomb.m4
index 5073865d48..5f1db25208 100644
--- a/m4/c32rtomb.m4
+++ b/m4/c32rtomb.m4
@@ -1,4 +1,4 @@
-# c32rtomb.m4 serial 6
+# c32rtomb.m4 serial 7
 dnl Copyright (C) 2020-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -7,6 +7,7 @@
 AC_DEFUN([gl_FUNC_C32RTOMB],
 [
   AC_REQUIRE([gl_UCHAR_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
 
   AC_REQUIRE([gl_MBRTOC32_SANITYCHECK])
 
diff --git a/m4/fenv-rounding.m4 b/m4/fenv-rounding.m4
index f52937c307..fc4e9a819d 100644
--- a/m4/fenv-rounding.m4
+++ b/m4/fenv-rounding.m4
@@ -1,4 +1,4 @@
-# fenv-rounding.m4 serial 1
+# fenv-rounding.m4 serial 2
 dnl Copyright (C) 2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -7,6 +7,7 @@
 AC_DEFUN([gl_FENV_ROUNDING],
 [
   AC_REQUIRE([gl_FENV_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
 
   dnl On FreeBSD 11/i386, fesetround needs -lm while fegetround doesn't.
   gl_MATHFUNC([fesetround], [int], [(int)], [#include ])
diff --git a/m4/getrandom.m4 b/m4/getrandom.m4
index fd73191b7b..0f7d60246a 100644
--- a/m4/getrandom.m4
+++ b/m4/getrandom.m4
@@ -1,4 +1,4 @@
-# getrandom.m4 serial 12
+# getrandom.m4 serial 13
 dnl Copyright 2020-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,6 +9,8 @@
 AC_DEFUN([gl_FUNC_GETRANDOM],
 [
   AC_REQUIRE([gl_SYS_RANDOM_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+
   gl_CHECK_FUNCS_ANDROID([getrandom],
 [[/* Additional includes are needed before  on uClibc
  and Mac OS X.  */
diff --git a/m4/iswdigit.m4 b/m4/iswdigit.m4
index b0572819ce..5bb7e6c7dc 100644
--- a/m4/iswdigit.m4
+++ b/m4/iswdigit.m4
@@ -1,4 +1,4 @@
-# iswdigit.m4 serial 5
+# iswdigit.m4 serial 6
 dnl Copyright (C) 2020-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -12,6 +12,7 @@ AC_DEFUN([gl_FUNC_ISWDIGIT]
   AC_REQUIRE([gt_LOCALE_JA])
   AC_REQUIRE([gt_LOCALE_FR_UTF8])
   AC_REQUIRE([gt_LOCALE_ZH_CN])
+  AC_REQUIRE([AC_CANONICAL_HOST])
 
   if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
 dnl  redefines iswdigit already.
diff --git a/m4/iswpunct.m4 b/m4/iswpunct.m4
index 14691154cf..7d033f1d98 100644
--- a/m4/iswpunct.m4
+++ b/m4/iswpunct.m4
@@ -1,4 +1,4 @@
-# iswpunct.m4 serial 1
+# iswpunct.m4 serial 2
 dnl Copyright (C) 2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,6 +8,7 @@ AC_DEFUN([gl_FUNC_ISWPUNCT]
 [
   AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
   AC_REQUIRE([gl_WCTYPE_H])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
 
   if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
 dnl  redefines iswpunct already.
diff --git a/m4/iswxdigit.m4 b/m4/iswxdigit.m4
index 7321807bc6..5de1003269 100644
--- a/m4/iswxdigit.m4
+++ b/m4/iswxdigit.m4
@@ -1,4 +1,4 @@
-# iswxdigit.m4 serial 5
+# iswxdigit.m4 serial 6
 dnl Copyright (C) 2020-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_ISWXDIGIT]
   AC_REQUIRE([gt_LOCALE_JA])
   AC_REQUIRE([gt_LOCALE_FR_UTF8])
   AC_REQUIRE([gt_LOCALE_ZH_CN])
+  AC_REQUIRE([AC_CANONICAL_HOST])
 
   if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
 dnl  redefines iswxdigit already.
diff --git a/m4/strerrorname_np.m4 b/m4/strerrorname_np.m4
index cb160e102d..2894f72449 100644
--- 

Re: new module 'fenv'

2023-11-04 Thread Bruno Haible
Here's a doc addition, regarding a problem with MSVC, for which Gnulib
cannot provide a workaround:


2023-11-04  Bruno Haible  

fenv: Document an ABI break on MSVC.
* doc/posix-headers/fenv.texi: Document why fegetround and fesetround
are seemingly broken on MSVC.

diff --git a/doc/posix-headers/fenv.texi b/doc/posix-headers/fenv.texi
index 36c636d7db..25e306d579 100644
--- a/doc/posix-headers/fenv.texi
+++ b/doc/posix-headers/fenv.texi
@@ -14,4 +14,9 @@
 
 Portability problems not fixed by Gnulib:
 @itemize
+@item
+On MSVC, the values of the rounding direction macros have changed:
+@c https://github.com/MicrosoftDocs/cpp-docs/issues/4796
+In MSVC 14, @code{FE_UPWARD} is 0x100 and @code{FE_DOWNWARD} is 0x200,
+whereas in MSVC 14.30, it's the opposite.
 @end itemize






new module 'fenv-exceptions-trapping'

2023-10-31 Thread Bruno Haible
These patches add a module 'fenv-exceptions-trapping', that portably implement
the GNU functions
  feenableexcept
  fedisableexcept
  fegetexcept   (a terrible misnomer, btw)

Again, the unit tests uncovered several problems on several platforms.


2023-10-31  Bruno Haible  

fenv-exceptions-trapping: Add tests.
* tests/test-fenv-except-trapping-1.c: New file.
* tests/test-fenv-except-trapping-2.sh: New file.
* tests/test-fenv-except-trapping-2.c: New file.
* modules/fenv-exceptions-trapping-tests: New file.

fenv-exceptions-trapping: New module.
* lib/fenv.in.h (feenableexcept, fedisableexcept, fegetexcept): New
declarations.
* lib/fenv-except-trapping.c: New file, based on glibc.
* m4/fenv_h.m4 (gl_FENV_H): Test also whether fegetexcept is declared.
* m4/fenv-exceptions-trapping.m4: New file.
* modules/fenv-exceptions-trapping: New file.
* doc/glibc-functions/fegetexcept.texi: Mention the new module.
* doc/glibc-functions/fedisableexcept.texi: Likewise.
* doc/glibc-functions/feenableexcept.texi: Likewise. Mention the glibc,
macOS, FreeBSD bugs.

From e5a52e29dfa5a292f9f94c56c9ed2f3c9ff189af Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Tue, 31 Oct 2023 21:46:13 +0100
Subject: [PATCH 1/2] fenv-exceptions-trapping: New module.

* lib/fenv.in.h (feenableexcept, fedisableexcept, fegetexcept): New
declarations.
* lib/fenv-except-trapping.c: New file, based on glibc.
* m4/fenv_h.m4 (gl_FENV_H): Test also whether fegetexcept is declared.
* m4/fenv-exceptions-trapping.m4: New file.
* modules/fenv-exceptions-trapping: New file.
* doc/glibc-functions/fegetexcept.texi: Mention the new module.
* doc/glibc-functions/fedisableexcept.texi: Likewise.
* doc/glibc-functions/feenableexcept.texi: Likewise. Mention the glibc,
macOS, FreeBSD bugs.
---
 ChangeLog|  14 +
 doc/glibc-functions/fedisableexcept.texi |   8 +-
 doc/glibc-functions/feenableexcept.texi  |  13 +-
 doc/glibc-functions/fegetexcept.texi |   8 +-
 lib/fenv-except-trapping.c   | 951 +++
 lib/fenv.in.h|  94 +++
 m4/fenv-exceptions-trapping.m4   | 117 +++
 m4/fenv_h.m4 |   3 +-
 modules/fenv-exceptions-trapping |  40 +
 9 files changed, 1236 insertions(+), 12 deletions(-)
 create mode 100644 lib/fenv-except-trapping.c
 create mode 100644 m4/fenv-exceptions-trapping.m4
 create mode 100644 modules/fenv-exceptions-trapping

diff --git a/ChangeLog b/ChangeLog
index 0476828c50..f7d1a2237e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2023-10-31  Bruno Haible  
+
+	fenv-exceptions-trapping: New module.
+	* lib/fenv.in.h (feenableexcept, fedisableexcept, fegetexcept): New
+	declarations.
+	* lib/fenv-except-trapping.c: New file, based on glibc.
+	* m4/fenv_h.m4 (gl_FENV_H): Test also whether fegetexcept is declared.
+	* m4/fenv-exceptions-trapping.m4: New file.
+	* modules/fenv-exceptions-trapping: New file.
+	* doc/glibc-functions/fegetexcept.texi: Mention the new module.
+	* doc/glibc-functions/fedisableexcept.texi: Likewise.
+	* doc/glibc-functions/feenableexcept.texi: Likewise. Mention the glibc,
+	macOS, FreeBSD bugs.
+
 2023-10-30  Bruno Haible  
 
 	fenv-exceptions-state-c99: Fix the x86_64 and i386 case.
diff --git a/doc/glibc-functions/fedisableexcept.texi b/doc/glibc-functions/fedisableexcept.texi
index 8b41ae4d87..d26397f44f 100644
--- a/doc/glibc-functions/fedisableexcept.texi
+++ b/doc/glibc-functions/fedisableexcept.texi
@@ -17,15 +17,15 @@
 @uref{https://www.kernel.org/doc/man-pages/online/pages/man3/fedisableexcept.3.html,,man fedisableexcept}.
 @end itemize
 
-Gnulib module: ---
+Gnulib module: fenv-exceptions-trapping
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+macOS 11.1, musl libc, FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 1.7.7, mingw, MSVC 14, Android 4.4.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-macOS 11.1, FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 1.7.7, mingw, MSVC 14, Android 4.4.
 @end itemize
diff --git a/doc/glibc-functions/feenableexcept.texi b/doc/glibc-functions/feenableexcept.texi
index dfca91f2a7..a858b4d6c6 100644
--- a/doc/glibc-functions/feenableexcept.texi
+++ b/doc/glibc-functions/feenableexcept.texi
@@ -17,15 +17,22 @@
 @uref{https://www.kernel.org/doc/man-pages/online/pages/man3/feenableexcept.3.html,,man feenableexcept}.
 @end itemize
 
-Gnulib module: ---
+Gnulib module: fenv-exceptions-trapping
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+macOS 11.1, musl libc, FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 

Re: new module 'fenv-exceptions-state-c99'

2023-10-30 Thread Bruno Haible
This one needs the same fix for x86_64 and i386 as the fsetenv() function.


2023-10-30  Bruno Haible  

fenv-exceptions-state-c99: Fix the x86_64 and i386 case.
* lib/fenv-except-state-set.c (fesetexceptflag): Make sure to restore
the exception trap bits in all cases.

From 9c82dee623c1dca092d050d6e2289e9e7e07a687 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Mon, 30 Oct 2023 16:26:46 +0100
Subject: [PATCH 1/8] fenv-exceptions-state-c99: Fix the x86_64 and i386 case.

* lib/fenv-except-state-set.c (fesetexceptflag): Make sure to restore
the exception trap bits in all cases.
---
 ChangeLog   |  6 ++
 lib/fenv-except-state-set.c | 27 ---
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e0bf89a9e2..0476828c50 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-10-30  Bruno Haible  
+
+	fenv-exceptions-state-c99: Fix the x86_64 and i386 case.
+	* lib/fenv-except-state-set.c (fesetexceptflag): Make sure to restore
+	the exception trap bits in all cases.
+
 2023-10-30  Bruno Haible  
 
 	fenv-exceptions-state-c23: Add tests.
diff --git a/lib/fenv-except-state-set.c b/lib/fenv-except-state-set.c
index 6ba4d63a7d..2035f61e27 100644
--- a/lib/fenv-except-state-set.c
+++ b/lib/fenv-except-state-set.c
@@ -72,33 +72,30 @@ fesetexceptflag (fexcept_t const *saved_flags, int exceptions)
   /* Modify the flags in the 387 unit, but only by clearing bits, not by
  setting bits.  */
   x86_387_fenv_t env;
-  unsigned short orig_status_word;
   __asm__ __volatile__ ("fnstenv %0" : "=m" (*));
-  orig_status_word = env.__status_word;
+  /* Note: fnstenv masks all floating-point exceptions until the fldenv
+ below.  */
   env.__status_word &= ~ (exceptions & ~desired_flags);
-  if (env.__status_word != orig_status_word)
-__asm__ __volatile__ ("fldenv %0" : : "m" (*));
+  __asm__ __volatile__ ("fldenv %0" : : "m" (*));
 }
 #   if !(defined __x86_64__ || defined _M_X64)
   else
 {
   /* Modify the flags in the 387 unit.  */
   x86_387_fenv_t env;
-  unsigned short orig_status_word;
   __asm__ __volatile__ ("fnstenv %0" : "=m" (*));
-  orig_status_word = env.__status_word;
+  /* Note: fnstenv masks all floating-point exceptions until the fldenv
+ or fldcw below.  */
   env.__status_word ^= ((env.__status_word ^ desired_flags) & exceptions);
-  if (env.__status_word != orig_status_word)
+  if ((~env.__control_word) & env.__status_word & exceptions)
 {
-  if ((~env.__control_word) & env.__status_word & exceptions)
-{
-  /* Setting the exception flags may trigger a trap (at the next
- floating-point instruction, but that does not matter).
- ISO C 23 § 7.6.4.5 does not allow it.  */
-  return -1;
-}
-  __asm__ __volatile__ ("fldenv %0" : : "m" (*));
+  /* Setting the exception flags may trigger a trap (at the next
+ floating-point instruction, but that does not matter).
+ ISO C 23 § 7.6.4.5 does not allow it.  */
+  __asm__ __volatile__ ("fldcw %0" : : "m" (*__control_word));
+  return -1;
 }
+  __asm__ __volatile__ ("fldenv %0" : : "m" (*));
 }
 #   endif
 #  endif
-- 
2.34.1



new module 'fenv-exceptions-state-c23'

2023-10-30 Thread Bruno Haible
This module implements the ISO C 23 API for saving and restoring the
floating-point exception flags. Compare to ISO C 99, only the function
  fetestexceptflag
has been added.


2023-10-30  Bruno Haible  

fenv-exceptions-state-c23: Add tests.
* tests/test-fenv-except-state-3.c: New file.
* modules/fenv-exceptions-state-c23-tests: New file.

fenv-exceptions-state-c23: New module.
* lib/fenv.in.h (fetestexceptflag): New declaration.
* lib/fenv-except-state-test.c: New file, based on glibc.
* m4/fenv-exceptions-state-c23.m4: New file.
* modules/fenv-exceptions-state-c23: New file.
* doc/posix-functions/fetestexceptflag.texi: Mention the new module.

From 7655a6462e34fe3a9ec0f66c2d6d0ce57aff26eb Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Mon, 30 Oct 2023 16:49:25 +0100
Subject: [PATCH 1/2] fenv-exceptions-state-c23: New module.

* lib/fenv.in.h (fetestexceptflag): New declaration.
* lib/fenv-except-state-test.c: New file, based on glibc.
* m4/fenv-exceptions-state-c23.m4: New file.
* modules/fenv-exceptions-state-c23: New file.
* doc/posix-functions/fetestexceptflag.texi: Mention the new module.
---
 ChangeLog |  13 +-
 doc/posix-functions/fetestexceptflag.texi |   8 +-
 lib/fenv-except-state-test.c  | 170 ++
 lib/fenv.in.h |  31 
 m4/fenv-exceptions-state-c23.m4   |  19 +++
 modules/fenv-exceptions-state-c23 |  35 +
 6 files changed, 270 insertions(+), 6 deletions(-)
 create mode 100644 lib/fenv-except-state-test.c
 create mode 100644 m4/fenv-exceptions-state-c23.m4
 create mode 100644 modules/fenv-exceptions-state-c23

diff --git a/ChangeLog b/ChangeLog
index e1f5066d4f..a513bcf2af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-10-30  Bruno Haible  
+
+	fenv-exceptions-state-c23: New module.
+	* lib/fenv.in.h (fetestexceptflag): New declaration.
+	* lib/fenv-except-state-test.c: New file, based on glibc.
+	* m4/fenv-exceptions-state-c23.m4: New file.
+	* modules/fenv-exceptions-state-c23: New file.
+	* doc/posix-functions/fetestexceptflag.texi: Mention the new module.
+
 2023-10-30  Bruno Haible  
 
 	fenv-exceptions-state-c99: Add tests.
@@ -7,8 +16,8 @@
 
 	fenv-exceptions-state-c99: New module.
 	* lib/fenv.in.h (fegetexceptflag, fesetexceptflag): New declarations.
-	* lib/fenv-except-state-get.c: New file, baed on glibc.
-	* lib/fenv-except-state-set.c: New file, baed on glibc.
+	* lib/fenv-except-state-get.c: New file, based on glibc.
+	* lib/fenv-except-state-set.c: New file, based on glibc.
 	* m4/mathfunc.m4 (gl_MATHFUNC): Handle also the 'fexcept_t *' type.
 	* m4/fenv-exceptions-state.m4: New file.
 	* modules/fenv-exceptions-state-c99: New file.
diff --git a/doc/posix-functions/fetestexceptflag.texi b/doc/posix-functions/fetestexceptflag.texi
index 88c3db5929..b78278d6cf 100644
--- a/doc/posix-functions/fetestexceptflag.texi
+++ b/doc/posix-functions/fetestexceptflag.texi
@@ -10,15 +10,15 @@
 @url{https://www.gnu.org/software/libc/manual/html_node/Status-bit-operations.html}.
 @end ifnotinfo
 
-Gnulib module: ---
+Gnulib module: fenv-exceptions-state-c23
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on all non-glibc platforms:
+glibc 2.24, macOS 11.1, FreeBSD 13.0, NetBSD 9.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on all non-glibc platforms:
-glibc 2.24, macOS 11.1, FreeBSD 13.0, NetBSD 9.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
 @end itemize
diff --git a/lib/fenv-except-state-test.c b/lib/fenv-except-state-test.c
new file mode 100644
index 00..fa40a80280
--- /dev/null
+++ b/lib/fenv-except-state-test.c
@@ -0,0 +1,170 @@
+/* Functions for saving the floating-point exception status flags.
+   Copyright (C) 1997-2023 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   This file is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see .  */
+
+/* Based on glibc/math/fetestexceptflag.c
+   together with glibc/sysdeps//{fpu_control.h,fenv_private.h,fenv_libc.h}.  */
+
+#include 
+
+/* Specification.  */
+#include 
+
+#if (defined 

new module 'fenv-exceptions-state-c99'

2023-10-30 Thread Bruno Haible
This new module implements the ISO C 99 functions for saving and restoring the
floating-point exception flags.

The unit tests uncovered bugs in glibc, musl libc (*), macOS, AIX, mingw.

(*) The one on musl libc is a documented limitation.


2023-10-30  Bruno Haible  

fenv-exceptions-state-c99: Add tests.
* tests/test-fenv-except-state-1.c: New file.
* tests/test-fenv-except-state-2.c: New file.
* modules/fenv-exceptions-state-c99-tests: New file.

fenv-exceptions-state-c99: New module.
* lib/fenv.in.h (fegetexceptflag, fesetexceptflag): New declarations.
* lib/fenv-except-state-get.c: New file, baed on glibc.
* lib/fenv-except-state-set.c: New file, baed on glibc.
* m4/mathfunc.m4 (gl_MATHFUNC): Handle also the 'fexcept_t *' type.
* m4/fenv-exceptions-state.m4: New file.
* modules/fenv-exceptions-state-c99: New file.
* doc/posix-functions/fegetexceptflag.texi: Mention the new module.
* doc/posix-functions/fesetexceptflag.texi: Mention the new module and
the glibc, musl libc, macOS, AIX, mingw bugs.

From ee6460d256b0ba048ef5ecf39f028b10c9986b12 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Mon, 30 Oct 2023 16:39:19 +0100
Subject: [PATCH 1/2] fenv-exceptions-state-c99: New module.

* lib/fenv.in.h (fegetexceptflag, fesetexceptflag): New declarations.
* lib/fenv-except-state-get.c: New file, baed on glibc.
* lib/fenv-except-state-set.c: New file, baed on glibc.
* m4/mathfunc.m4 (gl_MATHFUNC): Handle also the 'fexcept_t *' type.
* m4/fenv-exceptions-state.m4: New file.
* modules/fenv-exceptions-state-c99: New file.
* doc/posix-functions/fegetexceptflag.texi: Mention the new module.
* doc/posix-functions/fesetexceptflag.texi: Mention the new module and
the glibc, musl libc, macOS, AIX, mingw bugs.
---
 ChangeLog|  13 +
 doc/posix-functions/fegetexceptflag.texi |   8 +-
 doc/posix-functions/fesetexceptflag.texi |  23 +-
 lib/fenv-except-state-get.c  | 353 ++
 lib/fenv-except-state-set.c  | 597 +++
 lib/fenv.in.h|  49 +-
 m4/fenv-exceptions-state.m4  | 221 +
 m4/mathfunc.m4   |   6 +-
 modules/fenv-exceptions-state-c99|  43 ++
 9 files changed, 1302 insertions(+), 11 deletions(-)
 create mode 100644 lib/fenv-except-state-get.c
 create mode 100644 lib/fenv-except-state-set.c
 create mode 100644 m4/fenv-exceptions-state.m4
 create mode 100644 modules/fenv-exceptions-state-c99

diff --git a/ChangeLog b/ChangeLog
index 1fc40e4ae2..291e89ec60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2023-10-30  Bruno Haible  
+
+	fenv-exceptions-state-c99: New module.
+	* lib/fenv.in.h (fegetexceptflag, fesetexceptflag): New declarations.
+	* lib/fenv-except-state-get.c: New file, baed on glibc.
+	* lib/fenv-except-state-set.c: New file, baed on glibc.
+	* m4/mathfunc.m4 (gl_MATHFUNC): Handle also the 'fexcept_t *' type.
+	* m4/fenv-exceptions-state.m4: New file.
+	* modules/fenv-exceptions-state-c99: New file.
+	* doc/posix-functions/fegetexceptflag.texi: Mention the new module.
+	* doc/posix-functions/fesetexceptflag.texi: Mention the new module and
+	the glibc, musl libc, macOS, AIX, mingw bugs.
+
 2023-10-30  Bruno Haible  
 
 	fenv-exceptions-tracking-{c99,c23}: Fix the x86_64 and i386 case.
diff --git a/doc/posix-functions/fegetexceptflag.texi b/doc/posix-functions/fegetexceptflag.texi
index 5b45fe8d26..58915e0530 100644
--- a/doc/posix-functions/fegetexceptflag.texi
+++ b/doc/posix-functions/fegetexceptflag.texi
@@ -4,15 +4,15 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/fegetexceptflag.html}
 
-Gnulib module: ---
+Gnulib module: fenv-exceptions-state-c99
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, IRIX 6.5, Solaris 9, Cygwin 1.7.7, MSVC 9, Android 4.4.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, IRIX 6.5, Solaris 9, Cygwin 1.7.7, MSVC 9, Android 4.4.
 @end itemize
diff --git a/doc/posix-functions/fesetexceptflag.texi b/doc/posix-functions/fesetexceptflag.texi
index 5258d35099..66075be675 100644
--- a/doc/posix-functions/fesetexceptflag.texi
+++ b/doc/posix-functions/fesetexceptflag.texi
@@ -4,15 +4,30 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/fesetexceptflag.html}
 
-Gnulib module: ---
+Gnulib module: fenv-exceptions-state-c99
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, IRIX 6.5, Solaris 9, Cygwin 1.7.7, MSVC 9, Android 4.4.
+@item
+This function triggers 

Re: new module 'fenv-exceptions-tracking-c99'

2023-10-30 Thread Bruno Haible
Oops, this code has a bug on x86_64 and i386: It may leave the exception
traps masked, due to a side effect of the 'fnsetenv' instruction. This
patch should fix it.


2023-10-30  Bruno Haible  

fenv-exceptions-tracking-{c99,c23}: Fix the x86_64 and i386 case.
* lib/fenv-except-tracking-clear.c (feclearexcept): Make sure to restore
the exception trap bits in all cases.
* lib/fenv-except-tracking-raise.c (feraiseexcept): Likewise.
* lib/fenv-except-tracking-set.c (fesetexcept): Likewise.

From 6d2dfab57ddfad6bede47999eced62e517e88efd Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Mon, 30 Oct 2023 16:32:30 +0100
Subject: [PATCH 01/14] fenv-exceptions-tracking-{c99,c23}: Fix the x86_64 and
 i386 case.

* lib/fenv-except-tracking-clear.c (feclearexcept): Make sure to restore
the exception trap bits in all cases.
* lib/fenv-except-tracking-raise.c (feraiseexcept): Likewise.
* lib/fenv-except-tracking-set.c (fesetexcept): Likewise.
---
 ChangeLog|  8 
 lib/fenv-except-tracking-clear.c |  7 +++
 lib/fenv-except-tracking-raise.c | 16 ++--
 lib/fenv-except-tracking-set.c   | 20 +---
 4 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 26686c3fb8..1fc40e4ae2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-10-30  Bruno Haible  
+
+	fenv-exceptions-tracking-{c99,c23}: Fix the x86_64 and i386 case.
+	* lib/fenv-except-tracking-clear.c (feclearexcept): Make sure to restore
+	the exception trap bits in all cases.
+	* lib/fenv-except-tracking-raise.c (feraiseexcept): Likewise.
+	* lib/fenv-except-tracking-set.c (fesetexcept): Likewise.
+
 2023-10-29  Bruno Haible  
 
 	fenv-exceptions-tracking-c23: Add tests.
diff --git a/lib/fenv-except-tracking-clear.c b/lib/fenv-except-tracking-clear.c
index 22c85c98e0..9819832a5f 100644
--- a/lib/fenv-except-tracking-clear.c
+++ b/lib/fenv-except-tracking-clear.c
@@ -48,12 +48,11 @@ feclearexcept (int exceptions)
 
   /* Clear the bits in the 387 unit.  */
   x86_387_fenv_t env;
-  unsigned short orig_status_word;
   __asm__ __volatile__ ("fnstenv %0" : "=m" (*));
-  orig_status_word = env.__status_word;
+  /* Note: fnstenv masks all floating-point exceptions until the fldenv
+ below.  */
   env.__status_word &= ~exceptions;
-  if (env.__status_word != orig_status_word)
-__asm__ __volatile__ ("fldenv %0" : : "m" (*));
+  __asm__ __volatile__ ("fldenv %0" : : "m" (*));
 
   if (CPU_HAS_SSE ())
 {
diff --git a/lib/fenv-except-tracking-raise.c b/lib/fenv-except-tracking-raise.c
index 8699662ef5..c263151e60 100644
--- a/lib/fenv-except-tracking-raise.c
+++ b/lib/fenv-except-tracking-raise.c
@@ -106,18 +106,14 @@ feraiseexcept (int exceptions)
 
   /* Set the bits in the 387 unit.  */
   x86_387_fenv_t env;
-  unsigned short orig_status_word;
   __asm__ __volatile__ ("fnstenv %0" : "=m" (*));
-  orig_status_word = env.__status_word;
+  /* Note: fnstenv masks all floating-point exceptions until the fldenv
+ below.  */
   env.__status_word |= exceptions;
-  if (env.__status_word != orig_status_word)
-{
-  __asm__ __volatile__ ("fldenv %0" : : "m" (*));
-  /* A trap (if enabled) is triggered only at the next floating-point
- instruction.  Force it to occur here.  */
-  __asm__ __volatile__ ("fwait");
-}
-
+  __asm__ __volatile__ ("fldenv %0" : : "m" (*));
+  /* A trap (if enabled) is triggered only at the next floating-point
+ instruction.  Force it to occur here.  */
+  __asm__ __volatile__ ("fwait");
 }
 
 #  endif
diff --git a/lib/fenv-except-tracking-set.c b/lib/fenv-except-tracking-set.c
index 73b566cb01..d4237015e8 100644
--- a/lib/fenv-except-tracking-set.c
+++ b/lib/fenv-except-tracking-set.c
@@ -69,21 +69,19 @@ fesetexcept (int exceptions)
 {
   /* Set the flags in the 387 unit.  */
   x86_387_fenv_t env;
-  unsigned short orig_status_word;
   __asm__ __volatile__ ("fnstenv %0" : "=m" (*));
-  orig_status_word = env.__status_word;
+  /* Note: fnstenv masks all floating-point exceptions until the fldenv
+ or fldcw below.  */
   env.__status_word |= exceptions;
-  if (env.__status_word != orig_status_word)
+  if ((~env.__control_word) & exceptions)
 {
-  if ((~env.__control_word) & exceptions)
-{
-  /* Setting the exception flags may trigger a trap (at the next
- floating-point instruction, but that does not matter).
- ISO C 23 § 7.6.4.4 does not allow it.  */
-  return -1;
-}
-  __asm__ __volatile__ ("fldenv %0" : : "m" (*));
+  /* Setting the exception flags may trigger a trap (at the next
+ floating-point instruction, but that does not matter).
+ ISO C 23 § 7.6.4.4 does not allow it.  */
+  __asm__ 

new module 'fenv-exceptions-tracking-c23'

2023-10-29 Thread Bruno Haible
These patch adds a module 'fenv-exceptions-tracking-c23', that implements the
ISO C 23 API for tracking floating-point exceptions.

The new unit tests uncovered two glibc bugs.


2023-10-29  Bruno Haible  

fenv-exceptions-tracking-c23: Add tests.
* tests/test-fenv-except-tracking-4.c: New file.
* tests/test-fenv-except-tracking-5.c: New file.
* modules/fenv-exceptions-tracking-c23-tests: New file.

fenv-exceptions-tracking-c23: New module.
* lib/fenv.in.h (fesetexcept): New declaration.
* lib/fenv-except-tracking-set.c: New file, based on glibc.
* lib/fenv-private.h (_GETMSR, _SETMSR, MSR_FP_EXC_MASK, PR_SET_FPEXC,
PR_FP_EXC_DISABLED, PR_FP_EXC_NONRECOV, PR_FP_EXC_ASYNC,
PR_FP_EXC_PRECISE, prctl) [NetBSD/powerpc]: New macros.
* m4/fenv-exceptions-tracking-c23.m4: New file.
* modules/fenv-exceptions-tracking-c23: New file.
* doc/posix-functions/fesetexcept.texi: Mention the new module and the
glibc bugs.

From b21a4c46d03409e91a44b0dad5fc1e868afe4112 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 29 Oct 2023 22:20:02 +0100
Subject: [PATCH 1/2] fenv-exceptions-tracking-c23: New module.

* lib/fenv.in.h (fesetexcept): New declaration.
* lib/fenv-except-tracking-set.c: New file, based on glibc.
* lib/fenv-private.h (_GETMSR, _SETMSR, MSR_FP_EXC_MASK, PR_SET_FPEXC,
PR_FP_EXC_DISABLED, PR_FP_EXC_NONRECOV, PR_FP_EXC_ASYNC,
PR_FP_EXC_PRECISE, prctl) [NetBSD/powerpc]: New macros.
* m4/fenv-exceptions-tracking-c23.m4: New file.
* modules/fenv-exceptions-tracking-c23: New file.
* doc/posix-functions/fesetexcept.texi: Mention the new module and the
glibc bugs.
---
 ChangeLog|  13 +
 doc/posix-functions/fesetexcept.texi |  14 +-
 lib/fenv-except-tracking-set.c   | 500 +++
 lib/fenv-private.h   |  27 ++
 lib/fenv.in.h|  27 ++
 m4/fenv-exceptions-tracking-c23.m4   |  86 +
 modules/fenv-exceptions-tracking-c23 |  36 ++
 7 files changed, 699 insertions(+), 4 deletions(-)
 create mode 100644 lib/fenv-except-tracking-set.c
 create mode 100644 m4/fenv-exceptions-tracking-c23.m4
 create mode 100644 modules/fenv-exceptions-tracking-c23

diff --git a/ChangeLog b/ChangeLog
index 928ddf72b8..36256c30e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2023-10-29  Bruno Haible  
+
+	fenv-exceptions-tracking-c23: New module.
+	* lib/fenv.in.h (fesetexcept): New declaration.
+	* lib/fenv-except-tracking-set.c: New file, based on glibc.
+	* lib/fenv-private.h (_GETMSR, _SETMSR, MSR_FP_EXC_MASK, PR_SET_FPEXC,
+	PR_FP_EXC_DISABLED, PR_FP_EXC_NONRECOV, PR_FP_EXC_ASYNC,
+	PR_FP_EXC_PRECISE, prctl) [NetBSD/powerpc]: New macros.
+	* m4/fenv-exceptions-tracking-c23.m4: New file.
+	* modules/fenv-exceptions-tracking-c23: New file.
+	* doc/posix-functions/fesetexcept.texi: Mention the new module and the
+	glibc bugs.
+
 2023-10-28  Bruno Haible  
 
 	fenv-exceptions-tracking-c99: Fix feraiseexcept (FE_OVERFLOW) on MSVC.
diff --git a/doc/posix-functions/fesetexcept.texi b/doc/posix-functions/fesetexcept.texi
index e1535f31a5..23c3ea0868 100644
--- a/doc/posix-functions/fesetexcept.texi
+++ b/doc/posix-functions/fesetexcept.texi
@@ -10,15 +10,21 @@
 @url{https://www.gnu.org/software/libc/manual/html_node/Status-bit-operations.html}.
 @end ifnotinfo
 
-Gnulib module: ---
+Gnulib module: fenv-exceptions-tracking-c23
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on all non-glibc platforms:
+glibc 2.24, macOS 11.1, FreeBSD 13.0, NetBSD 9.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
+@item
+This function triggers floating-point exception traps although it shouldn't, on
+@c https://sourceware.org/bugzilla/show_bug.cgi?id=30989
+glibc 2.37/i386,
+@c https://sourceware.org/bugzilla/show_bug.cgi?id=30988
+glibc 2.37/powerpc.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on all non-glibc platforms:
-glibc 2.24, macOS 11.1, FreeBSD 13.0, NetBSD 9.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
 @end itemize
diff --git a/lib/fenv-except-tracking-set.c b/lib/fenv-except-tracking-set.c
new file mode 100644
index 00..73b566cb01
--- /dev/null
+++ b/lib/fenv-except-tracking-set.c
@@ -0,0 +1,500 @@
+/* Functions for tracking which floating-point exceptions have occurred.
+   Copyright (C) 1997-2023 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   This file is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the 

Re: new module 'fenv-exceptions-tracking-c99'

2023-10-28 Thread Bruno Haible
It's interesting to observe that the various architectures have different
semantics for the floating-point exception flags in the presence of traps:

  * On some architectures, modifying bits in some control register does not
actually raise a trap. To raise a trap, feraiseexcept() must do an
actual floating-point operation. This is the case for
- The SSE unit of x86_64 and i386,
- arm64,
- arm,
- alpha,
- hppa,
- ia64,
- m68k,
- loongarch,
- s390,
- sh,
- sparc.

  * On some architectures, setting the floating-point exception flags in
the control register *does* raise a trap:
- The 387 unit of x86_64 and i386,
- powerpc.

  * On some architectures, it's something in between: mips.
Here, setting the floating-point exception flags does not raise a
trap, but setting some other bits in the same register does.

  * Finally, one some architectures, raising traps is unsupported in
hardware (i.e. would require GCC modifications): riscv.

Bruno






Re: new module 'fenv-exceptions-tracking-c99'

2023-10-28 Thread Bruno Haible
Oops, after enhancing a unit test, I noticed that on MSVC, the overridden
feraiseexcept function does not work for FE_OVERFLOW, FE_UNDERFLOW, FE_INEXACT.

This patch fixes it. The enhanced unit test will come later.


2023-10-28  Bruno Haible  

fenv-exceptions-tracking-c99: Fix feraiseexcept (FE_OVERFLOW) on MSVC.
* lib/fenv-except-tracking-raise.c (feraiseexcept): Use the generic
approach for all exceptions.

diff --git a/lib/fenv-except-tracking-raise.c b/lib/fenv-except-tracking-raise.c
index a9f8b04963..8699662ef5 100644
--- a/lib/fenv-except-tracking-raise.c
+++ b/lib/fenv-except-tracking-raise.c
@@ -71,6 +71,14 @@ generic_feraiseexcept (int exceptions)
 int
 feraiseexcept (int exceptions)
 {
+#  if defined _MSC_VER
+
+  /* Setting the exception flags only in the SSE unit (i.e. in the mxcsr
+ register) would not cause the hardware to trap on the exception.  */
+  generic_feraiseexcept (exceptions);
+
+#  else
+
   exceptions &= FE_ALL_EXCEPT;
 
   if ((exceptions & ~(FE_INVALID | FE_DIVBYZERO)) == 0)
@@ -95,18 +103,6 @@ feraiseexcept (int exceptions)
   else
 {
   /* The general case.  */
-#  if defined _MSC_VER
-
-  exceptions = exceptions_to_x86hardware (exceptions);
-
-  /* Set the bits only in the SSE unit.  */
-  unsigned int mxcsr, orig_mxcsr;
-  _FPU_GETSSECW (orig_mxcsr);
-  mxcsr = orig_mxcsr | exceptions;
-  if (mxcsr != orig_mxcsr)
-_FPU_SETSSECW (mxcsr);
-
-#  else
 
   /* Set the bits in the 387 unit.  */
   x86_387_fenv_t env;
@@ -122,8 +118,9 @@ feraiseexcept (int exceptions)
   __asm__ __volatile__ ("fwait");
 }
 
-#  endif
 }
+
+#  endif
   return 0;
 }
 
@@ -168,6 +165,8 @@ feraiseexcept (int exceptions)
  the overflow/underflow exception follows the inexact exception.  After
  each exception we read from the fpscr, to force the exception to be
  raised immediately.  */
+  /* XXX Probably this should do actual floating-point operations, like in
+ generic_feraiseexcept, not just setting flag bits in the fpscr.  */
   unsigned int fpscr, orig_fpscr;
   /* First: invalid exception.  */
   if (exceptions & FE_INVALID)






new module 'fenv-exceptions-tracking-c99'

2023-10-28 Thread Bruno Haible
This module adds the  functions that deal with tracking which
floating-point exceptions have occurred:
  feclearexcept
  feraiseexcept
  fetestexcept

It not only adds the functions for old platforms, but also provides
workarounds for glibc and Cygwin bugs.

With this done, it is possible to fix a deficiency in the 'fpe-trapping'
module: Although sigfpe_on_invalid is documented to first clear
the FE_INVALID exception flag — which is needed in order to avoid an
undesired trap —, for some platforms I had omitted that code, because
I had not considered feclearexcept to be portable. Now that we have
feclearexcept on all platform, we can fix this.


2023-10-28  Bruno Haible  

fpe-trapping: Always clear the FE_INVALID exception flag first.
* lib/fpe-trapping.h: Include  on all platforms.
(sigfpe_on_invalid) [AIX, HP-UX, IRIX, Solaris] : Clear the FE_INVALID
exception flag first.
* modules/fpe-trapping (Depends-on): Add fenv-exceptions-tracking-c99.

2023-10-28  Bruno Haible  

fenv-exceptions-tracking-c99: Add tests.
* tests/test-fenv-except-tracking-1.c: New file.
* tests/test-fenv-except-tracking-2.sh: New file.
* tests/test-fenv-except-tracking-2.c: New file.
* tests/test-fenv-except-tracking-3.sh: New file.
* tests/test-fenv-except-tracking-3.c: New file.
* modules/fenv-exceptions-tracking-c99-tests: New file.

fenv-exceptions-tracking-c99: New module.
* lib/fenv.in.h (feclearexcept, feraiseexcept, fetestexcept): New
declarations.
* lib/fenv-except-tracking-clear.c: New file, based on glibc.
* lib/fenv-except-tracking-raise.c: New file, based on glibc.
* lib/fenv-except-tracking-test.c: New file, based on glibc.
* m4/fenv-exceptions-tracking.m4: New file.
* m4/fenv-exceptions.m4: New file.
* modules/fenv-exceptions-tracking-c99: New file.
* doc/posix-functions/feclearexcept.texi: Mention the new module.
* doc/posix-functions/fetestexcept.texi: Likewise.
* doc/posix-functions/feraiseexcept.texi: Likewise. Mention the glibc
and Cygwin bugs.

From 2ce970a2718bdf9685517fba9efa5ec60d773953 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sat, 28 Oct 2023 18:31:22 +0200
Subject: [PATCH 1/3] fenv-exceptions-tracking-c99: New module.

* lib/fenv.in.h (feclearexcept, feraiseexcept, fetestexcept): New
declarations.
* lib/fenv-except-tracking-clear.c: New file, based on glibc.
* lib/fenv-except-tracking-raise.c: New file, based on glibc.
* lib/fenv-except-tracking-test.c: New file, based on glibc.
* m4/fenv-exceptions-tracking.m4: New file.
* m4/fenv-exceptions.m4: New file.
* modules/fenv-exceptions-tracking-c99: New file.
* doc/posix-functions/feclearexcept.texi: Mention the new module.
* doc/posix-functions/fetestexcept.texi: Likewise.
* doc/posix-functions/feraiseexcept.texi: Likewise. Mention the glibc
and Cygwin bugs.
---
 ChangeLog  |  16 +
 doc/posix-functions/feclearexcept.texi |   8 +-
 doc/posix-functions/feraiseexcept.texi |  15 +-
 doc/posix-functions/fetestexcept.texi  |   8 +-
 lib/fenv-except-tracking-clear.c   | 392 +
 lib/fenv-except-tracking-raise.c   | 457 +
 lib/fenv-except-tracking-test.c| 266 ++
 lib/fenv.in.h  |  57 +++
 m4/fenv-exceptions-tracking.m4 | 152 
 m4/fenv-exceptions.m4  |  23 ++
 modules/fenv-exceptions-tracking-c99   |  50 +++
 11 files changed, 1432 insertions(+), 12 deletions(-)
 create mode 100644 lib/fenv-except-tracking-clear.c
 create mode 100644 lib/fenv-except-tracking-raise.c
 create mode 100644 lib/fenv-except-tracking-test.c
 create mode 100644 m4/fenv-exceptions-tracking.m4
 create mode 100644 m4/fenv-exceptions.m4
 create mode 100644 modules/fenv-exceptions-tracking-c99

diff --git a/ChangeLog b/ChangeLog
index 2eb57b8d9d..b1c73c0f98 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2023-10-28  Bruno Haible  
+
+	fenv-exceptions-tracking-c99: New module.
+	* lib/fenv.in.h (feclearexcept, feraiseexcept, fetestexcept): New
+	declarations.
+	* lib/fenv-except-tracking-clear.c: New file, based on glibc.
+	* lib/fenv-except-tracking-raise.c: New file, based on glibc.
+	* lib/fenv-except-tracking-test.c: New file, based on glibc.
+	* m4/fenv-exceptions-tracking.m4: New file.
+	* m4/fenv-exceptions.m4: New file.
+	* modules/fenv-exceptions-tracking-c99: New file.
+	* doc/posix-functions/feclearexcept.texi: Mention the new module.
+	* doc/posix-functions/fetestexcept.texi: Likewise.
+	* doc/posix-functions/feraiseexcept.texi: Likewise. Mention the glibc
+	and Cygwin bugs.
+
 2023-10-27  Bruno Haible  
 
 	fenv-rounding: Add tests.
diff --git a/doc/posix-functions/feclearexcept.texi b/doc/posix-functions/feclearexcept.texi
index dc56c3fd45..8b218804bd 100644
--- a/doc/posix-functions/feclearexcept.texi
+++ 

new module 'fenv-rounding'

2023-10-27 Thread Bruno Haible
These patches add a module 'fenv-rounding', that implements the ISO C 99
functions
  fegetround
  fesetround

Most platforms have these functions nowadays, and the unit tests have not
uncovered any bugs. Therefore it's probably only relevant for portability
to older Android versions.

The most interesting file here is probably lib/fenv-private.h, which will
be shared with the other fenv modules.


2023-10-27  Bruno Haible  

fenv-rounding: Add tests.
* tests/test-fenv-round.c: New file.
* modules/fenv-rounding-tests: New file.

fenv-rounding: New module.
* lib/fenv.in.h (fegetround, fesetround): New declarations.
* lib/fenv-private.h: New file, based on glibc.
* lib/fenv-round.c: New file, based on glibc.
* m4/mathfunc.m4 (gl_MATHFUNC): Handle also the type fp_rnd.
* m4/fenv-rounding.m4: New file.
* modules/fenv (Depends-on): Add snippet/c++defs.
(Makefile.am): Substitute $(CXXDEFS_H) into fenv.h.
* modules/fenv-rounding: New file.
* doc/posix-functions/fegetround.texi: Mention the new module.
* doc/posix-functions/fesetround.texi: Likewise.

From 404ce57f190e137da6197e2e8094d3d779472a04 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Fri, 27 Oct 2023 20:16:50 +0200
Subject: [PATCH 1/2] fenv-rounding: New module.

* lib/fenv.in.h (fegetround, fesetround): New declarations.
* lib/fenv-private.h: New file, based on glibc.
* lib/fenv-round.c: New file, based on glibc.
* m4/mathfunc.m4 (gl_MATHFUNC): Handle also the type fp_rnd.
* m4/fenv-rounding.m4: New file.
* modules/fenv (Depends-on): Add snippet/c++defs.
(Makefile.am): Substitute $(CXXDEFS_H) into fenv.h.
* modules/fenv-rounding: New file.
* doc/posix-functions/fegetround.texi: Mention the new module.
* doc/posix-functions/fesetround.texi: Likewise.
---
 ChangeLog   |  14 +
 doc/posix-functions/fegetround.texi |   8 +-
 doc/posix-functions/fesetround.texi |  11 +-
 lib/fenv-private.h  | 379 ++
 lib/fenv-round.c| 572 
 lib/fenv.in.h   |  42 ++
 m4/fenv-rounding.m4 |  77 
 m4/mathfunc.m4  |  16 +-
 modules/fenv|   4 +-
 modules/fenv-rounding   |  36 ++
 10 files changed, 1143 insertions(+), 16 deletions(-)
 create mode 100644 lib/fenv-private.h
 create mode 100644 lib/fenv-round.c
 create mode 100644 m4/fenv-rounding.m4
 create mode 100644 modules/fenv-rounding

diff --git a/ChangeLog b/ChangeLog
index 1b0201ce6c..b4c109b02a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2023-10-27  Bruno Haible  
+
+	fenv-rounding: New module.
+	* lib/fenv.in.h (fegetround, fesetround): New declarations.
+	* lib/fenv-private.h: New file, based on glibc.
+	* lib/fenv-round.c: New file, based on glibc.
+	* m4/mathfunc.m4 (gl_MATHFUNC): Handle also the type fp_rnd.
+	* m4/fenv-rounding.m4: New file.
+	* modules/fenv (Depends-on): Add snippet/c++defs.
+	(Makefile.am): Substitute $(CXXDEFS_H) into fenv.h.
+	* modules/fenv-rounding: New file.
+	* doc/posix-functions/fegetround.texi: Mention the new module.
+	* doc/posix-functions/fesetround.texi: Likewise.
+
 2023-10-27  Bruno Haible  
 
 	tests: Use C99 initializer syntax for memory_long_double.
diff --git a/doc/posix-functions/fegetround.texi b/doc/posix-functions/fegetround.texi
index 869698131f..c32eb4230e 100644
--- a/doc/posix-functions/fegetround.texi
+++ b/doc/posix-functions/fegetround.texi
@@ -4,15 +4,15 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/fegetround.html}
 
-Gnulib module: ---
+Gnulib module: fenv-rounding
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, AIX 5.1, IRIX 6.5, Solaris 9, Cygwin 1.7.7, MSVC 9, Android 4.4.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, AIX 5.1, IRIX 6.5, Solaris 9, Cygwin 1.7.7, MSVC 9, Android 4.4.
 @end itemize
diff --git a/doc/posix-functions/fesetround.texi b/doc/posix-functions/fesetround.texi
index 2efc18f31f..f0c74c3467 100644
--- a/doc/posix-functions/fesetround.texi
+++ b/doc/posix-functions/fesetround.texi
@@ -4,15 +4,18 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/fesetround.html}
 
-Gnulib module: ---
+Gnulib module: fenv-rounding
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, AIX 5.1, IRIX 6.5, Solaris 9, Cygwin 1.7.7, MSVC 9, Android 4.4.
+@item
+This function does not work on some platforms:
+MSVC 14.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-FreeBSD 6.0, NetBSD 5.0, OpenBSD 

new module 'fenv'

2023-10-26 Thread Bruno Haible
When writing the lib/fpe-trapping.h file (needed to verify the quiet vs.
signalling NaNs, which in turn was needed for testing the totalorder*
functions), I was disappointed by the complexity of this file. Ideally
it would contain just two statements:
  feclearexcept (FE_INVALID);
  feenableexcept (FE_INVALID);
but then various portability problems were encountered.

Following the Gnulib philosophy, these portability fixes should be
hidden behind a GNU-like .

Here comes the module for the  header file. More modules to
come in the next days.

There is special code for each CPU, because many CPUs have their
own quirks:
  - x86_64 has two floating point units (387 unit and SSE unit).
Recall the 387 unit's "we compute everything with 80-bits
'long double's, whether you like it or not" philosophy, that
has killed the reproducibility of numerical programs' results
for decades.
  - i386 has one or two floating point units (387 always, SSE unit often).
  - aarch64 may or may not support trapping on floating-point
exceptions.
  - arm likewise. Also armv5 has only software float routines, with
no support for floating-point exceptions and only one rounding
direction.
  - riscv does not support trapping on floating-point exceptions at all.
  - alpha does not support "inexact" floating-point exceptions well.
It also requires system calls to modify the floating-point
control word.
  - m68k has 3 bits for "Invalid operation", not just one. Also it
has 'double's that deviate from IEEE 754.
  - powerpc has its control word stored in a floating-point register,
not in an integer-like register.
  - hppa likewise.
  - sh4 has only two rounding directions, not four.
  - ia64, like x86_64 and i386, has bits that are set when traps
for a certain floating-point exception are *disabled* (the
opposite of all other CPUs).
Only mips, s390, sparc, loongarch are somewhat sane.

Bruno


2023-10-26  Bruno Haible  

fenv: Add tests.
* tests/test-fenv.c: New file.
* modules/fenv-tests: New file.

fenv: New module.
* lib/fenv.in.h: New file, based on glibc.
* m4/fenv_h.m4: New file.
* modules/fenv: New file.
* doc/posix-headers/fenv.texi: Mention the new module.

From b536e9d30d31345f197ccf219378ed3142fc6beb Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Fri, 27 Oct 2023 03:43:15 +0200
Subject: [PATCH 1/2] fenv: New module.

* lib/fenv.in.h: New file, based on glibc.
* m4/fenv_h.m4: New file.
* modules/fenv: New file.
* doc/posix-headers/fenv.texi: Mention the new module.
---
 ChangeLog   |   8 +
 doc/posix-headers/fenv.texi |   8 +-
 lib/fenv.in.h   | 489 
 m4/fenv_h.m4|  98 
 modules/fenv|  87 +++
 5 files changed, 686 insertions(+), 4 deletions(-)
 create mode 100644 lib/fenv.in.h
 create mode 100644 m4/fenv_h.m4
 create mode 100644 modules/fenv

diff --git a/ChangeLog b/ChangeLog
index fed7803763..b89af7a969 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-10-26  Bruno Haible  
+
+	fenv: New module.
+	* lib/fenv.in.h: New file, based on glibc.
+	* m4/fenv_h.m4: New file.
+	* modules/fenv: New file.
+	* doc/posix-headers/fenv.texi: Mention the new module.
+
 2023-10-25  Paul Eggert  
 
 	base32: new function isubase32; also, tune.
diff --git a/doc/posix-headers/fenv.texi b/doc/posix-headers/fenv.texi
index 2e7d10d29e..36c636d7db 100644
--- a/doc/posix-headers/fenv.texi
+++ b/doc/posix-headers/fenv.texi
@@ -3,15 +3,15 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fenv.h.html}
 
-Gnulib module: ---
+Gnulib module: fenv
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This header file is missing on some platforms:
+FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, AIX 5.1, IRIX 6.5, Cygwin 1.7.7, MSVC 9.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This header file is missing on some platforms:
-FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, AIX 5.1, IRIX 6.5, Cygwin 1.7.7, MSVC 9.
 @end itemize
diff --git a/lib/fenv.in.h b/lib/fenv.in.h
new file mode 100644
index 00..c52d0e0ccb
--- /dev/null
+++ b/lib/fenv.in.h
@@ -0,0 +1,489 @@
+/* A GNU-like .
+
+   Copyright (C) 1997-2023 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   This file is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If