File: fenv-except-state-test.c

package info (click to toggle)
gnulib 20250303-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 188,836 kB
  • sloc: ansic: 378,598; sh: 30,630; python: 8,358; cpp: 2,811; yacc: 1,846; perl: 920; makefile: 577; lisp: 328; sed: 11; java: 5
file content (170 lines) | stat: -rw-r--r-- 4,138 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* Functions for saving the floating-point exception status flags.
   Copyright (C) 1997-2025 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