]> Savannah Git Hosting - gnulib.git/commitdiff
fenv-exceptions-state-c23: New module.
authorBruno Haible <bruno@clisp.org>
Mon, 30 Oct 2023 15:49:25 +0000 (16:49 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 30 Oct 2023 15:51:51 +0000 (16:51 +0100)
* 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
doc/posix-functions/fetestexceptflag.texi
lib/fenv-except-state-test.c [new file with mode: 0644]
lib/fenv.in.h
m4/fenv-exceptions-state-c23.m4 [new file with mode: 0644]
modules/fenv-exceptions-state-c23 [new file with mode: 0644]

index e1f5066d4fb7b838f172e4a343469fcc1050cbe8..a513bcf2af28d43c33b10d161f8b76bd9ca713f8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-10-30  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        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.
index 88c3db59291802cbd193ff78a74fed98c5129540..b78278d6cf775bd3d0f35520504dffb3fafc7a5d 100644 (file)
@@ -10,15 +10,15 @@ Documentation:@*
 @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 (file)
index 0000000..fa40a80
--- /dev/null
@@ -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 <https://www.gnu.org/licenses/>.  */
+
+/* Based on glibc/math/fetestexceptflag.c
+   together with glibc/sysdeps/<cpu>/{fpu_control.h,fenv_private.h,fenv_libc.h}.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <fenv.h>
+
+#if (defined __x86_64__ || defined _M_X64) || (defined __i386 || defined _M_IX86)
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned int flags = (unsigned int) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __aarch64__ /* arm64 */
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned long flags = (unsigned long) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __arm__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned int flags = (unsigned int) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __alpha
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned long flags = (unsigned long) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __hppa
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned int flags = (unsigned int) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __ia64__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned long flags = (unsigned long) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __m68k__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned int flags = (unsigned int) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __mips__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned int flags = (unsigned int) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __loongarch__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned int flags = (unsigned int) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __powerpc__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned int flags = (unsigned int) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __riscv
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned int flags = (unsigned int) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __s390__ || defined __s390x__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned int flags = (unsigned int) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __sh__
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned int flags = (unsigned int) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __sparc
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  unsigned long flags = (unsigned long) *saved_flags;
+  return flags & FE_ALL_EXCEPT & exceptions;
+}
+
+#else
+
+# if defined __GNUC__ || defined __clang__
+#   warning "Unknown CPU / architecture. Please report your platform and compiler to <bug-gnulib@gnu.org>."
+#  endif
+# define NEED_FALLBACK 1
+
+#endif
+
+#if NEED_FALLBACK
+
+/* A dummy fallback.  */
+
+int
+fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
+{
+  return 0;
+}
+
+#endif
index ad61e2c4c0176ed66df6928b94827152ef6831ec..2b2f770e2c66fb8ec779416c974f6815c277e8a3 100644 (file)
@@ -657,6 +657,37 @@ _GL_CXXALIAS_SYS (fesetexceptflag, int,
 _GL_CXXALIASWARN (fesetexceptflag);
 #endif
 
+/* Added in ISO C 23 ยง 7.6.4 Floating-point exceptions.  */
+
+#if @GNULIB_FETESTEXCEPTFLAG@
+/* Copies the flags denoted by EXCEPTIONS from *SAVED_FLAGS to the
+   floating-point exception status flags.  */
+# if 0
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fetestexceptflag
+#   define fetestexceptflag rpl_fetestexceptflag
+#  endif
+_GL_FUNCDECL_RPL (fetestexceptflag, int,
+                  (fexcept_t const *saved_flags, int exceptions));
+_GL_CXXALIAS_RPL (fetestexceptflag, int,
+                  (fexcept_t const *saved_flags, int exceptions));
+# else
+#  if !@HAVE_FETESTEXCEPTFLAG@
+_GL_FUNCDECL_SYS (fetestexceptflag, int,
+                  (fexcept_t const *saved_flags, int exceptions));
+#  endif
+_GL_CXXALIAS_SYS (fetestexceptflag, int,
+                  (fexcept_t const *saved_flags, int exceptions));
+# endif
+_GL_CXXALIASWARN (fetestexceptflag);
+#elif defined GNULIB_POSIXCHECK
+# undef fetestexceptflag
+# if HAVE_RAW_DECL_FETESTEXCEPTFLAG
+_GL_WARN_ON_USE (fetestexceptflag, "fetestexceptflag is unportable - "
+                 "use gnulib module fenv-exceptions-state-c23 for portability");
+# endif
+#endif
+
 
 #endif /* _@GUARD_PREFIX@_FENV_H */
 #endif /* _@GUARD_PREFIX@_FENV_H */
diff --git a/m4/fenv-exceptions-state-c23.m4 b/m4/fenv-exceptions-state-c23.m4
new file mode 100644 (file)
index 0000000..999fd43
--- /dev/null
@@ -0,0 +1,19 @@
+# fenv-exceptions-state-c23.m4 serial 1
+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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FENV_EXCEPTIONS_STATE_C23],
+[
+  AC_REQUIRE([gl_FENV_H_DEFAULTS])
+
+  gl_MATHFUNC([fetestexceptflag], [int], [(fexcept_t const *, int)],
+    [#include <fenv.h>
+     fexcept_t fx_ret;
+    ])
+  if test $gl_cv_func_fetestexceptflag_no_libm != yes \
+     && test $gl_cv_func_fetestexceptflag_in_libm != yes; then
+    HAVE_FETESTEXCEPTFLAG=0
+  fi
+])
diff --git a/modules/fenv-exceptions-state-c23 b/modules/fenv-exceptions-state-c23
new file mode 100644 (file)
index 0000000..487913c
--- /dev/null
@@ -0,0 +1,35 @@
+Description:
+Functions for saving the floating-point exception status flags:
+fegetexceptflag, fesetexceptflag, fetestexceptflag.
+
+Files:
+lib/fenv-except-state-test.c
+m4/fenv-exceptions-state-c23.m4
+m4/mathfunc.m4
+
+Depends-on:
+fenv
+fenv-exceptions-state-c99
+
+configure.ac:
+gl_FENV_EXCEPTIONS_STATE_C23
+gl_CONDITIONAL([GL_COND_OBJ_FENV_EXCEPTIONS_STATE_C23],
+               [test $HAVE_FETESTEXCEPTFLAG = 0])
+gl_FENV_MODULE_INDICATOR([fetestexceptflag])
+
+Makefile.am:
+if GL_COND_OBJ_FENV_EXCEPTIONS_STATE_C23
+lib_SOURCES += fenv-except-state-test.c
+endif
+
+Include:
+#include <fenv.h>
+
+Link:
+$(FENV_EXCEPTIONS_STATE_LIBM)
+
+License:
+LGPLv2+
+
+Maintainer:
+all