Check for SYS/GL during library init. Reason is that
[AROS.git] / arch / arm-all / include / aros / fenv_vfp.h
blob416e4fc10baa15046955645eba43baba7fd02e2d
1 /*-
2 * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
3 * All rights reserved.
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
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
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.
26 * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5.20.1 2009/04/15 03:14:26 kensmith Exp $
29 #ifndef _FENV_VFP_H_
30 #define _FENV_VFP_H_
32 #include <aros/system.h>
33 #include <aros/types/int_t.h>
35 typedef uint32_t fenv_t;
36 typedef uint32_t fexcept_t;
38 /* Exception flags */
39 #define FE_INVALID 0x0001
40 #define FE_DIVBYZERO 0x0002
41 #define FE_OVERFLOW 0x0004
42 #define FE_UNDERFLOW 0x0008
43 #define FE_INEXACT 0x0010
44 #define FE_DENORMAL 0x0080
45 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
46 FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW | FE_DENORMAL)
48 /* Rounding modes */
49 #define FE_TONEAREST 0x00000000
50 #define FE_TOWARDZERO 0x00c00000
51 #define FE_UPWARD 0x00400000
52 #define FE_DOWNWARD 0x00800000
53 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
54 FE_UPWARD | FE_TOWARDZERO)
55 __BEGIN_DECLS
57 /* Default floating-point environment */
58 extern const fenv_t __fe_dfl_env;
59 #define FE_DFL_ENV (&__fe_dfl_env)
61 /* We need to be able to map status flag positions to mask flag positions */
62 #define _FPUSW_SHIFT 8
63 #define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT)
65 #define __rfs(__fpscr) asm volatile("fmrx %0, fpscr" : "=r"(*(__fpscr)))
66 #define __wfs(__fpscr) asm volatile("fmxr fpscr, %0" :: "r"(__fpscr))
68 #ifndef STDC_NOINLINE
69 static __inline int
70 feclearexcept(int __excepts)
72 fexcept_t __fpsr;
74 __rfs(&__fpsr);
75 __fpsr &= ~__excepts;
76 __wfs(__fpsr);
77 return (0);
80 static __inline int
81 fegetexceptflag(fexcept_t *__flagp, int __excepts)
83 fexcept_t __fpsr;
85 __rfs(&__fpsr);
86 *__flagp = __fpsr & __excepts;
87 return (0);
90 static __inline int
91 fesetexceptflag(const fexcept_t *__flagp, int __excepts)
93 fexcept_t __fpsr;
95 __rfs(&__fpsr);
96 __fpsr &= ~__excepts;
97 __fpsr |= *__flagp & __excepts;
98 __wfs(__fpsr);
99 return (0);
102 static __inline int
103 feraiseexcept(int __excepts)
105 fexcept_t __ex = __excepts;
107 fesetexceptflag(&__ex, __excepts); /* XXX */
108 return (0);
111 static __inline int
112 fetestexcept(int __excepts)
114 fexcept_t __fpsr;
116 __rfs(&__fpsr);
117 return (__fpsr & __excepts);
120 static __inline int
121 fegetround(void)
123 fexcept_t __fpsr;
125 __rfs(&__fpsr);
126 return (__fpsr & _ROUND_MASK);
129 static __inline int
130 fesetround(int __round)
132 fexcept_t __fpsr;
134 if (__round & ~_ROUND_MASK)
135 return (-1);
137 __rfs(&__fpsr);
138 __fpsr &= ~_ROUND_MASK;
139 __fpsr |= __round;
140 __wfs(__fpsr);
142 return (0);
145 static __inline int
146 fegetenv(fenv_t *__envp)
149 __rfs(__envp);
150 return (0);
153 static __inline int
154 feholdexcept(fenv_t *__envp)
156 fenv_t __env;
158 __rfs(&__env);
159 *__envp = __env;
160 __env &= ~(FE_ALL_EXCEPT | _ENABLE_MASK);
161 __wfs(__env);
162 return (0);
165 static __inline int
166 fesetenv(const fenv_t *__envp)
169 __wfs(*__envp);
170 return (0);
173 static __inline int
174 feupdateenv(const fenv_t *__envp)
176 fexcept_t __fpsr;
178 __rfs(&__fpsr);
179 __wfs(*__envp);
180 feraiseexcept(__fpsr & FE_ALL_EXCEPT);
181 return (0);
183 #endif /* !STDC_NOINLINE */
185 #if __BSD_VISIBLE
187 #ifndef STDC_NOINLINE
188 static __inline int
189 feenableexcept(int __mask)
191 fenv_t __old_fpsr, __new_fpsr;
193 __rfs(&__old_fpsr);
194 __new_fpsr = __old_fpsr | (__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT;
195 __wfs(__new_fpsr);
196 return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
199 static __inline int
200 fedisableexcept(int __mask)
202 fenv_t __old_fpsr, __new_fpsr;
204 __rfs(&__old_fpsr);
205 __new_fpsr = __old_fpsr & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT);
206 __wfs(__new_fpsr);
207 return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
210 static __inline int
211 fegetexcept(void)
213 fenv_t __fpsr;
215 __rfs(&__fpsr);
216 return ((__fpsr & _ENABLE_MASK) >> _FPUSW_SHIFT);
218 #endif /* !STDC_NOINLINE */
220 #endif /* __BSD_VISIBLE */
222 __END_DECLS
224 #endif /* !_FENV_VFP_H_ */