3 * Copyright 2012, 2013 MinGW.org project
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
26 #pragma GCC system_header
29 /* FPU status word exception flags */
30 #define FE_INVALID 0x01
31 #define FE_DENORMAL 0x02
32 #define FE_DIVBYZERO 0x04
33 #define FE_OVERFLOW 0x08
34 #define FE_UNDERFLOW 0x10
35 #define FE_INEXACT 0x20
36 #define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO \
37 | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
39 /* FPU control word rounding flags */
40 #define FE_TONEAREST 0x0000
41 #define FE_DOWNWARD 0x0400
42 #define FE_UPWARD 0x0800
43 #define FE_TOWARDZERO 0x0c00
45 /* The MXCSR exception flags are the same as the
47 #define __MXCSR_EXCEPT_FLAG_SHIFT 0
49 /* How much to shift FE status word exception flags
50 to get the MXCSR exeptions masks, */
51 #define __MXCSR_EXCEPT_MASK_SHIFT 7
53 /* How much to shift FE control word rounding flags
54 to get MXCSR rounding flags, */
55 #define __MXCSR_ROUND_FLAG_SHIFT 3
59 For now, support only for the basic abstraction of flags that are
60 either set or clear. fexcept_t could be structure that holds more
61 info about the fp environment.
63 typedef unsigned short fexcept_t;
65 /* This 32-byte struct represents the entire floating point
66 environment as stored by fnstenv or fstenv, augmented by
67 the contents of the MXCSR register, as stored by stmxcsr
68 (if CPU supports it). */
71 unsigned short __control_word;
72 unsigned short __unused0;
73 unsigned short __status_word;
74 unsigned short __unused1;
75 unsigned short __tag_word;
76 unsigned short __unused2;
77 unsigned int __ip_offset; /* instruction pointer offset */
78 unsigned short __ip_selector;
79 unsigned short __opcode;
80 unsigned int __data_offset;
81 unsigned short __data_selector;
82 unsigned short __unused3;
83 unsigned int __mxcsr; /* contents of the MXCSR register */
87 /*The C99 standard (7.6.9) allows us to define implementation-specific macros for
88 different fp environments */
90 /* The default Intel x87 floating point environment (64-bit mantissa) */
91 #define FE_PC64_ENV ((const fenv_t *)-1)
93 /* The floating point environment set by MSVCRT _fpreset (53-bit mantissa) */
94 #define FE_PC53_ENV ((const fenv_t *)-2)
96 /* The FE_DFL_ENV macro is required by standard.
97 fesetenv will use the environment set at app startup.*/
98 #define FE_DFL_ENV ((const fenv_t *) 0)
104 /*TODO: Some of these could be inlined */
105 /* 7.6.2 Exception */
107 extern int __cdecl __MINGW_NOTHROW feclearexcept (int);
108 extern int __cdecl __MINGW_NOTHROW fegetexceptflag (fexcept_t * flagp, int excepts);
109 extern int __cdecl __MINGW_NOTHROW feraiseexcept (int excepts );
110 extern int __cdecl __MINGW_NOTHROW fesetexceptflag (const fexcept_t *, int);
111 extern int __cdecl __MINGW_NOTHROW fetestexcept (int excepts);
115 extern int __cdecl __MINGW_NOTHROW fegetround (void);
116 extern int __cdecl __MINGW_NOTHROW fesetround (int mode);
118 /* 7.6.4 Environment */
120 extern int __cdecl __MINGW_NOTHROW fegetenv (fenv_t * envp);
121 extern int __cdecl __MINGW_NOTHROW fesetenv (const fenv_t * );
122 extern int __cdecl __MINGW_NOTHROW feupdateenv (const fenv_t *);
123 extern int __cdecl __MINGW_NOTHROW feholdexcept (fenv_t *);
128 #endif /* Not RC_INVOKED */
130 #endif /* ndef _FENV_H */