From 7655a6462e34fe3a9ec0f66c2d6d0ce57aff26eb Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 30 Oct 2023 16:49:25 +0100 Subject: [PATCH] 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 @@ 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 index 0000000000..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 __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 ." +# endif +# define NEED_FALLBACK 1 + +#endif + +#if NEED_FALLBACK + +/* A dummy fallback. */ + +int +fetestexceptflag (fexcept_t const *saved_flags, int exceptions) +{ + return 0; +} + +#endif diff --git a/lib/fenv.in.h b/lib/fenv.in.h index ad61e2c4c0..2b2f770e2c 100644 --- a/lib/fenv.in.h +++ b/lib/fenv.in.h @@ -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 index 0000000000..999fd43de7 --- /dev/null +++ b/m4/fenv-exceptions-state-c23.m4 @@ -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 + 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 index 0000000000..487913c076 --- /dev/null +++ b/modules/fenv-exceptions-state-c23 @@ -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 + +Link: +$(FENV_EXCEPTIONS_STATE_LIBM) + +License: +LGPLv2+ + +Maintainer: +all -- 2.39.5