OSDN Git Service

Redo the filters based on assumptions discussed in mingw-dvlpr list.
[mingw/mingw-org-wsl.git] / include / fenv.h
1 /**
2  * @file fenv.h
3  * @copy 2012 MinGW.org project
4  *
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:
11  * 
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
14  * Software.
15  * 
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.
23  */
24 #ifndef _FENV_H_
25 #define _FENV_H_
26 #pragma GCC system_header
27
28 #include <_mingw.h>
29
30 /* FPU status word exception flags */
31 #define FE_INVALID      0x01
32 #define FE_DENORMAL     0x02
33 #define FE_DIVBYZERO    0x04
34 #define FE_OVERFLOW     0x08
35 #define FE_UNDERFLOW    0x10
36 #define FE_INEXACT      0x20
37 #define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO \
38                        | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
39
40 /* FPU control word rounding flags */
41 #define FE_TONEAREST    0x0000
42 #define FE_DOWNWARD     0x0400
43 #define FE_UPWARD       0x0800
44 #define FE_TOWARDZERO   0x0c00
45
46 /* The MXCSR exception flags are the same as the
47    FE flags. */
48 #define __MXCSR_EXCEPT_FLAG_SHIFT 0
49
50 /* How much to shift FE status word exception flags
51    to get the MXCSR exeptions masks,  */
52 #define __MXCSR_EXCEPT_MASK_SHIFT 7
53
54 /* How much to shift FE control word rounding flags
55    to get MXCSR rounding flags,  */
56 #define __MXCSR_ROUND_FLAG_SHIFT 3
57
58 #ifndef RC_INVOKED
59 /*
60   For now, support only for the basic abstraction of flags that are
61   either set or clear. fexcept_t could be  structure that holds more
62   info about the fp environment.
63 */
64 typedef unsigned short fexcept_t;
65
66 /* This 32-byte struct represents the entire floating point
67    environment as stored by fnstenv or fstenv, augmented by
68    the  contents of the MXCSR register, as stored by stmxcsr
69    (if CPU supports it). */
70 typedef struct
71 {
72   unsigned short __control_word;
73   unsigned short __unused0;
74   unsigned short __status_word;
75   unsigned short __unused1;
76   unsigned short __tag_word;
77   unsigned short __unused2;  
78   unsigned int   __ip_offset;    /* instruction pointer offset */
79   unsigned short __ip_selector;  
80   unsigned short __opcode;
81   unsigned int   __data_offset;
82   unsigned short __data_selector;
83   unsigned short  __unused3;
84   unsigned int __mxcsr; /* contents of the MXCSR register  */
85 } fenv_t;
86
87
88 /*The C99 standard (7.6.9) allows us to define implementation-specific macros for
89   different fp environments */
90   
91 /* The default Intel x87 floating point environment (64-bit mantissa) */
92 #define FE_PC64_ENV ((const fenv_t *)-1)
93
94 /* The floating point environment set by MSVCRT _fpreset (53-bit mantissa) */
95 #define FE_PC53_ENV ((const fenv_t *)-2)
96
97 /* The FE_DFL_ENV macro is required by standard.
98   fesetenv will use the environment set at app startup.*/
99 #define FE_DFL_ENV ((const fenv_t *) 0)
100
101 #ifdef __cplusplus
102 extern "C" {
103 #endif
104
105 /*TODO: Some of these could be inlined */
106 /* 7.6.2 Exception */
107
108 extern int __cdecl __MINGW_NOTHROW feclearexcept (int);
109 extern int __cdecl __MINGW_NOTHROW fegetexceptflag (fexcept_t * flagp, int excepts);
110 extern int __cdecl __MINGW_NOTHROW feraiseexcept (int excepts );
111 extern int __cdecl __MINGW_NOTHROW fesetexceptflag (const fexcept_t *, int);
112 extern int __cdecl __MINGW_NOTHROW fetestexcept (int excepts);
113
114 /* 7.6.3 Rounding */
115
116 extern int __cdecl __MINGW_NOTHROW fegetround (void);
117 extern int __cdecl __MINGW_NOTHROW fesetround (int mode);
118
119 /* 7.6.4 Environment */
120
121 extern int __cdecl __MINGW_NOTHROW fegetenv (fenv_t * envp);
122 extern int __cdecl __MINGW_NOTHROW fesetenv (const fenv_t * );
123 extern int __cdecl __MINGW_NOTHROW feupdateenv (const fenv_t *);
124 extern int __cdecl __MINGW_NOTHROW feholdexcept (fenv_t *);
125
126 #ifdef __cplusplus
127 }
128 #endif
129 #endif  /* Not RC_INVOKED */
130
131 #endif /* ndef _FENV_H */