Deleted Added
full compact
fenv.c (230367) fenv.c (263210)
1/*-
2 * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
1/*-
2 * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
3 * Copyright (c) 2013 Andrew Turner <andrew@FreeBSD.ORG>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 7 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright

--- 7 unchanged lines hidden (view full) ---

19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
26 * $FreeBSD: head/lib/msun/arm/fenv.c 230367 2012-01-20 06:54:30Z das $
27 * $FreeBSD: head/lib/msun/arm/fenv.c 263210 2014-03-15 21:58:07Z andrew $
27 */
28
29#define __fenv_static
30#include "fenv.h"
31
28 */
29
30#define __fenv_static
31#include "fenv.h"
32
33/* When SOFTFP_ABI is defined we are using the softfp ABI. */
34#if defined(__VFP_FP__) && !defined(__ARM_PCS_VFP)
35#define SOFTFP_ABI
36#endif
37
38
39#ifndef FENV_MANGLE
32/*
40/*
41 * Hopefully the system ID byte is immutable, so it's valid to use
42 * this as a default environment.
43 */
44const fenv_t __fe_dfl_env = 0;
45#endif
46
47
48/* If this is a non-mangled softfp version special processing is required */
49#if defined(FENV_MANGLE) || !defined(SOFTFP_ABI)
50
51/*
33 * The following macros map between the softfloat emulator's flags and
34 * the hardware's FPSR. The hardware this file was written for doesn't
35 * have rounding control bits, so we stick those in the system ID byte.
36 */
52 * The following macros map between the softfloat emulator's flags and
53 * the hardware's FPSR. The hardware this file was written for doesn't
54 * have rounding control bits, so we stick those in the system ID byte.
55 */
56#ifndef __ARM_PCS_VFP
37#define __set_env(env, flags, mask, rnd) env = ((flags) \
38 | (mask)<<_FPUSW_SHIFT \
39 | (rnd) << 24)
40#define __env_flags(env) ((env) & FE_ALL_EXCEPT)
41#define __env_mask(env) (((env) >> _FPUSW_SHIFT) \
42 & FE_ALL_EXCEPT)
43#define __env_round(env) (((env) >> 24) & _ROUND_MASK)
44#include "fenv-softfloat.h"
57#define __set_env(env, flags, mask, rnd) env = ((flags) \
58 | (mask)<<_FPUSW_SHIFT \
59 | (rnd) << 24)
60#define __env_flags(env) ((env) & FE_ALL_EXCEPT)
61#define __env_mask(env) (((env) >> _FPUSW_SHIFT) \
62 & FE_ALL_EXCEPT)
63#define __env_round(env) (((env) >> 24) & _ROUND_MASK)
64#include "fenv-softfloat.h"
65#endif
45
46#ifdef __GNUC_GNU_INLINE__
47#error "This file must be compiled with C99 'inline' semantics"
48#endif
49
66
67#ifdef __GNUC_GNU_INLINE__
68#error "This file must be compiled with C99 'inline' semantics"
69#endif
70
50/*
51 * Hopefully the system ID byte is immutable, so it's valid to use
52 * this as a default environment.
53 */
54const fenv_t __fe_dfl_env = 0;
55
56extern inline int feclearexcept(int __excepts);
57extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts);
58extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts);
59extern inline int feraiseexcept(int __excepts);
60extern inline int fetestexcept(int __excepts);
61extern inline int fegetround(void);
62extern inline int fesetround(int __round);
63extern inline int fegetenv(fenv_t *__envp);
64extern inline int feholdexcept(fenv_t *__envp);
65extern inline int fesetenv(const fenv_t *__envp);
66extern inline int feupdateenv(const fenv_t *__envp);
71extern inline int feclearexcept(int __excepts);
72extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts);
73extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts);
74extern inline int feraiseexcept(int __excepts);
75extern inline int fetestexcept(int __excepts);
76extern inline int fegetround(void);
77extern inline int fesetround(int __round);
78extern inline int fegetenv(fenv_t *__envp);
79extern inline int feholdexcept(fenv_t *__envp);
80extern inline int fesetenv(const fenv_t *__envp);
81extern inline int feupdateenv(const fenv_t *__envp);
82extern inline int feenableexcept(int __mask);
83extern inline int fedisableexcept(int __mask);
84extern inline int fegetexcept(void);
85
86#else /* !FENV_MANGLE && SOFTFP_ABI */
87/* Set by libc when the VFP unit is enabled */
88extern int _libc_arm_fpu_present;
89
90int __softfp_feclearexcept(int __excepts);
91int __softfp_fegetexceptflag(fexcept_t *__flagp, int __excepts);
92int __softfp_fesetexceptflag(const fexcept_t *__flagp, int __excepts);
93int __softfp_feraiseexcept(int __excepts);
94int __softfp_fetestexcept(int __excepts);
95int __softfp_fegetround(void);
96int __softfp_fesetround(int __round);
97int __softfp_fegetenv(fenv_t *__envp);
98int __softfp_feholdexcept(fenv_t *__envp);
99int __softfp_fesetenv(const fenv_t *__envp);
100int __softfp_feupdateenv(const fenv_t *__envp);
101int __softfp_feenableexcept(int __mask);
102int __softfp_fedisableexcept(int __mask);
103int __softfp_fegetexcept(void);
104
105int __vfp_feclearexcept(int __excepts);
106int __vfp_fegetexceptflag(fexcept_t *__flagp, int __excepts);
107int __vfp_fesetexceptflag(const fexcept_t *__flagp, int __excepts);
108int __vfp_feraiseexcept(int __excepts);
109int __vfp_fetestexcept(int __excepts);
110int __vfp_fegetround(void);
111int __vfp_fesetround(int __round);
112int __vfp_fegetenv(fenv_t *__envp);
113int __vfp_feholdexcept(fenv_t *__envp);
114int __vfp_fesetenv(const fenv_t *__envp);
115int __vfp_feupdateenv(const fenv_t *__envp);
116int __vfp_feenableexcept(int __mask);
117int __vfp_fedisableexcept(int __mask);
118int __vfp_fegetexcept(void);
119
120static int
121__softfp_round_to_vfp(int round)
122{
123
124 switch (round) {
125 case FE_TONEAREST:
126 default:
127 return VFP_FE_TONEAREST;
128 case FE_TOWARDZERO:
129 return VFP_FE_TOWARDZERO;
130 case FE_UPWARD:
131 return VFP_FE_UPWARD;
132 case FE_DOWNWARD:
133 return VFP_FE_DOWNWARD;
134 }
135}
136
137static int
138__softfp_round_from_vfp(int round)
139{
140
141 switch (round) {
142 case VFP_FE_TONEAREST:
143 default:
144 return FE_TONEAREST;
145 case VFP_FE_TOWARDZERO:
146 return FE_TOWARDZERO;
147 case VFP_FE_UPWARD:
148 return FE_UPWARD;
149 case VFP_FE_DOWNWARD:
150 return FE_DOWNWARD;
151 }
152}
153
154int feclearexcept(int __excepts)
155{
156
157 if (_libc_arm_fpu_present)
158 __vfp_feclearexcept(__excepts);
159 __softfp_feclearexcept(__excepts);
160
161 return (0);
162}
163
164int fegetexceptflag(fexcept_t *__flagp, int __excepts)
165{
166 fexcept_t __vfp_flagp;
167
168 __vfp_flagp = 0;
169 if (_libc_arm_fpu_present)
170 __vfp_fegetexceptflag(&__vfp_flagp, __excepts);
171 __softfp_fegetexceptflag(__flagp, __excepts);
172
173 *__flagp |= __vfp_flagp;
174
175 return (0);
176}
177
178int fesetexceptflag(const fexcept_t *__flagp, int __excepts)
179{
180
181 if (_libc_arm_fpu_present)
182 __vfp_fesetexceptflag(__flagp, __excepts);
183 __softfp_fesetexceptflag(__flagp, __excepts);
184
185 return (0);
186}
187
188int feraiseexcept(int __excepts)
189{
190
191 if (_libc_arm_fpu_present)
192 __vfp_feraiseexcept(__excepts);
193 __softfp_feraiseexcept(__excepts);
194
195 return (0);
196}
197
198int fetestexcept(int __excepts)
199{
200 int __got_excepts;
201
202 __got_excepts = 0;
203 if (_libc_arm_fpu_present)
204 __got_excepts = __vfp_fetestexcept(__excepts);
205 __got_excepts |= __softfp_fetestexcept(__excepts);
206
207 return (__got_excepts);
208}
209
210int fegetround(void)
211{
212
213 if (_libc_arm_fpu_present)
214 return __softfp_round_from_vfp(__vfp_fegetround());
215 return __softfp_fegetround();
216}
217
218int fesetround(int __round)
219{
220
221 if (_libc_arm_fpu_present)
222 __vfp_fesetround(__softfp_round_to_vfp(__round));
223 __softfp_fesetround(__round);
224
225 return (0);
226}
227
228int fegetenv(fenv_t *__envp)
229{
230 fenv_t __vfp_envp;
231
232 __vfp_envp = 0;
233 if (_libc_arm_fpu_present)
234 __vfp_fegetenv(&__vfp_envp);
235 __softfp_fegetenv(__envp);
236 *__envp |= __vfp_envp;
237
238 return (0);
239}
240
241int feholdexcept(fenv_t *__envp)
242{
243 fenv_t __vfp_envp;
244
245 __vfp_envp = 0;
246 if (_libc_arm_fpu_present)
247 __vfp_feholdexcept(&__vfp_envp);
248 __softfp_feholdexcept(__envp);
249 *__envp |= __vfp_envp;
250
251 return (0);
252}
253
254int fesetenv(const fenv_t *__envp)
255{
256
257 if (_libc_arm_fpu_present)
258 __vfp_fesetenv(__envp);
259 __softfp_fesetenv(__envp);
260
261 return (0);
262}
263
264int feupdateenv(const fenv_t *__envp)
265{
266
267 if (_libc_arm_fpu_present)
268 __vfp_feupdateenv(__envp);
269 __softfp_feupdateenv(__envp);
270
271 return (0);
272}
273
274int feenableexcept(int __mask)
275{
276 int __unmasked;
277
278 __unmasked = 0;
279 if (_libc_arm_fpu_present)
280 __unmasked = __vfp_feenableexcept(__mask);
281 __unmasked |= __softfp_feenableexcept(__mask);
282
283 return (__unmasked);
284}
285
286int fedisableexcept(int __mask)
287{
288 int __unmasked;
289
290 __unmasked = 0;
291 if (_libc_arm_fpu_present)
292 __unmasked = __vfp_fedisableexcept(__mask);
293 __unmasked |= __softfp_fedisableexcept(__mask);
294
295 return (__unmasked);
296}
297
298int fegetexcept(void)
299{
300 int __unmasked;
301
302 __unmasked = 0;
303 if (_libc_arm_fpu_present)
304 __unmasked = __vfp_fegetexcept();
305 __unmasked |= __softfp_fegetexcept();
306
307 return (__unmasked);
308}
309
310#endif
311