exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / fenv-except-state-test.c
blob1c3e9583c5cb9b29cb8dc6ae0e34213bc7bd2c6d
1 /* Functions for saving the floating-point exception status flags.
2 Copyright (C) 1997-2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Based on glibc/math/fetestexceptflag.c
18 together with glibc/sysdeps/<cpu>/{fpu_control.h,fenv_private.h,fenv_libc.h}. */
20 #include <config.h>
22 /* Specification. */
23 #include <fenv.h>
25 #if (defined __x86_64__ || defined _M_X64) || (defined __i386 || defined _M_IX86)
27 int
28 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
30 unsigned int flags = (unsigned int) *saved_flags;
31 return flags & FE_ALL_EXCEPT & exceptions;
34 #elif defined __aarch64__ /* arm64 */
36 int
37 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
39 unsigned long flags = (unsigned long) *saved_flags;
40 return flags & FE_ALL_EXCEPT & exceptions;
43 #elif defined __arm__
45 int
46 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
48 unsigned int flags = (unsigned int) *saved_flags;
49 return flags & FE_ALL_EXCEPT & exceptions;
52 #elif defined __alpha
54 int
55 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
57 unsigned long flags = (unsigned long) *saved_flags;
58 return flags & FE_ALL_EXCEPT & exceptions;
61 #elif defined __hppa
63 int
64 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
66 unsigned int flags = (unsigned int) *saved_flags;
67 return flags & FE_ALL_EXCEPT & exceptions;
70 #elif defined __ia64__
72 int
73 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
75 unsigned long flags = (unsigned long) *saved_flags;
76 return flags & FE_ALL_EXCEPT & exceptions;
79 #elif defined __m68k__
81 int
82 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
84 unsigned int flags = (unsigned int) *saved_flags;
85 return flags & FE_ALL_EXCEPT & exceptions;
88 #elif defined __mips__
90 int
91 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
93 unsigned int flags = (unsigned int) *saved_flags;
94 return flags & FE_ALL_EXCEPT & exceptions;
97 #elif defined __loongarch__
99 int
100 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
102 unsigned int flags = (unsigned int) *saved_flags;
103 return flags & FE_ALL_EXCEPT & exceptions;
106 #elif defined __powerpc__
109 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
111 unsigned int flags = (unsigned int) *saved_flags;
112 return flags & FE_ALL_EXCEPT & exceptions;
115 #elif defined __riscv
118 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
120 unsigned int flags = (unsigned int) *saved_flags;
121 return flags & FE_ALL_EXCEPT & exceptions;
124 #elif defined __s390__ || defined __s390x__
127 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
129 unsigned int flags = (unsigned int) *saved_flags;
130 return flags & FE_ALL_EXCEPT & exceptions;
133 #elif defined __sh__
136 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
138 unsigned int flags = (unsigned int) *saved_flags;
139 return flags & FE_ALL_EXCEPT & exceptions;
142 #elif defined __sparc
145 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
147 unsigned long flags = (unsigned long) *saved_flags;
148 return flags & FE_ALL_EXCEPT & exceptions;
151 #else
153 # if defined __GNUC__ || defined __clang__
154 # warning "Unknown CPU / architecture. Please report your platform and compiler to <bug-gnulib@gnu.org>."
155 # endif
156 # define NEED_FALLBACK 1
158 #endif
160 #if NEED_FALLBACK
162 /* A dummy fallback. */
165 fetestexceptflag (fexcept_t const *saved_flags, int exceptions)
167 return 0;
170 #endif