MicrOS
fenv.h
Go to the documentation of this file.
1 #ifndef FENV_H
2 #define FENV_H
3 
4 #include <stddef.h>
5 
7 #define FE_INVALID 1
8 #define FE_DENORMAL 2
10 #define FE_DIVBYZERO 4
12 #define FE_OVERFLOW 8
14 #define FE_UNDERFLOW 16
16 #define FE_INEXACT 32
18 #define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
20 
22 #define FE_TONEAREST 0
23 #define FE_DOWNWARD 1
25 #define FE_UPWARD 2
27 #define FE_TOWARDZERO 3
29 
31 
32 typedef struct fcontrol_t
33 {
35  unsigned char invalid_operation : 1;
37  unsigned char denormalized_operand : 1;
39  unsigned char zero_divide : 1;
41  unsigned char overflow : 1;
43  unsigned char underflow : 1;
45  unsigned char precision : 1;
47  unsigned char : 2;
49  unsigned char precision_control : 2;
51  unsigned char rounding_control : 2;
53  unsigned char infinity_control : 1;
55  unsigned char : 3;
56 } fcontrol_t;
57 
59 
60 typedef struct fexcept_t
61 {
63  unsigned char invalid_operation : 1;
65  unsigned char denormalized_operand : 1;
67  unsigned char zero_divide : 1;
69  unsigned char overflow : 1;
71  unsigned char underflow : 1;
73  unsigned char precision : 1;
75  unsigned char stack_fault : 1;
77  unsigned char error_summary_status : 1;
79  unsigned char condition_code_0: 1;
81  unsigned char condition_code_1: 1;
83  unsigned char condition_code_2: 1;
85  unsigned char top_of_stack_pointer : 3;
87  unsigned char condition_code_3: 1;
89  unsigned char busy : 1;
90 } fexcept_t;
91 
93 
94 typedef struct ftag_word_t
95 {
97  unsigned char tag0 : 2;
99  unsigned char tag1 : 2;
101  unsigned char tag2 : 2;
103  unsigned char tag3 : 2;
105  unsigned char tag4 : 2;
107  unsigned char tag5 : 2;
109  unsigned char tag6 : 2;
111  unsigned char tag7 : 2;
112 } ftag_word_t;
113 
115 
117 typedef struct fenv_t
118 {
122  unsigned short unused1;
126  unsigned short unused2;
130  unsigned short unused3;
136  unsigned short opcode : 11;
138  unsigned char five_zeros : 5;
140  unsigned int data_pointer_offset;
142  unsigned short data_pointer_selector;
144  unsigned short unused4;
145 } fenv_t;
146 
148 
149 extern const fenv_t * env;
150 
152 
153 #define FE_DFL_ENV (env)
154 
155 #ifdef __cplusplus
156 extern "C" {
157 #endif
158 
159 // Floating-point exceptions
160 
162 
167 int feclearexcept(int excepts);
168 
170 
176 int fegetexceptflag(fexcept_t *flagp, int excepts);
177 
179 
184 int feraiseexcept(int excepts);
185 
187 
193 int fesetexceptflag(const fexcept_t *flagp, int excepts);
194 
196 
201 int fetestexcept(int excepts);
202 
203 // Rounding direction
204 
206 
209 int fegetround(void);
210 
212 
217 int fesetround(int round);
218 
219 // Entire environment
220 
222 
227 int fegetenv(fenv_t *envp);
228 
230 
235 int fesetenv(const fenv_t *envp);
236 
238 
243 int feholdexcept(fenv_t *envp);
244 
246 
251 int feupdateenv(const fenv_t *envp);
252 
253 #ifdef __cplusplus
254 }
255 #endif
256 
257 // Additional content
258 
260 
261 #define __FPU_TAG_WORD_VALID 0
262 
264 #define __FPU_TAG_ZERO 1
265 
267 #define __FPU_TAG_SPECIAL 2
268 
270 #define __FPU_TAG_EMPTY 3
271 
273 #define __FPU_PRECISION_SINGLE 0
274 #define __FPU_PRECISION_DOUBLE 1
276 #define __FPU_PRECISION_EXTENDED 3
278 
280 #define __FPU_ROUNDING_NEAREST_EVEN 0
281 #define __FPU_ROUNDING_FLOOR 1
283 #define __FPU_ROUNDING_CEIL 2
285 #define __FPU_ROUNDING_TRUNCATE 3
287 
289 #define __FPU_INFINITY_CONTROL_PROJECTIVE 0
290 #define __FPU_INFINITY_CONTROL_AFFINE 1
292 
293 #ifdef __cplusplus
294 extern "C" {
295 #endif
296 
298 
302 
304 
308 void __FPU_write_control_word(fcontrol_t control_word);
309 
311 
315 
317 
320 void __FPU_write_environment(fenv_t environment);
321 
323 
327 
330 
331 #ifdef __cplusplus
332 }
333 #endif
334 
335 #endif // FENV_H
unsigned char overflow
Overflow exception flag.
Definition: fenv.h:41
unsigned char condition_code_3
Condition code 3.
Definition: fenv.h:87
int feraiseexcept(int excepts)
Raise FPU exception flags.
Definition: feraiseexcept.c:3
unsigned char error_summary_status
Error summary status.
Definition: fenv.h:77
int fegetenv(fenv_t *envp)
Get entire environment.
Definition: fegetenv.c:3
int feholdexcept(fenv_t *envp)
Hold floating-point exceptions.
Definition: feholdexcept.c:3
int feclearexcept(int excepts)
Clear FPU exception flags.
Definition: feclearexcept.c:3
fcontrol_t control_word
FPU control word.
Definition: fenv.h:120
void __FPU_write_control_word(fcontrol_t control_word)
Write FPU control word.
Definition: __FPU_write_control_word.c:3
unsigned char busy
Indicates if FPU is busy.
Definition: fenv.h:89
unsigned char condition_code_1
Condition code 1.
Definition: fenv.h:81
unsigned short unused2
Unused.
Definition: fenv.h:126
unsigned short unused4
Unused.
Definition: fenv.h:144
unsigned short unused1
Unused.
Definition: fenv.h:122
const fenv_t * env
Pointer to environment.
Definition: fenv.c:3
Type represent state of floating point environment.
Definition: fenv.h:117
fexcept_t status_word
FPU status word.
Definition: fenv.h:124
fexcept_t __FPU_read_status_word()
Read FPU status word.
Definition: __FPU_read_status_word.c:3
unsigned char tag2
Describes content of 3rd register.
Definition: fenv.h:101
double round(double x)
Round to nearest.
Definition: round.c:3
unsigned char rounding_control
Rounding control flag.
Definition: fenv.h:51
unsigned char tag5
Describes content of 6th register.
Definition: fenv.h:107
unsigned char zero_divide
Zero divide exception.
Definition: fenv.h:67
unsigned short unused3
Unused.
Definition: fenv.h:130
unsigned char five_zeros
Five zeros.
Definition: fenv.h:138
int fegetround(void)
Get current rounding direction.
Definition: fegetround.c:3
fcontrol_t __FPU_read_control_word()
Read FPU control word.
Definition: __FPU_read_control_word.c:3
void __FPU_clear_exceptions()
Clear all FPU exceptions.
Definition: __FPU_clear_exceptions.c:3
unsigned int data_pointer_offset
Data pointer offset.
Definition: fenv.h:140
unsigned char tag0
Describes content of 1st register.
Definition: fenv.h:97
unsigned char zero_divide
Zero divide exception flag.
Definition: fenv.h:39
unsigned short opcode
Last used opcode.
Definition: fenv.h:136
Tag words.
Definition: fenv.h:94
unsigned char infinity_control
Infinity control flag.
Definition: fenv.h:53
Type represent state of floating point status word.
Definition: fenv.h:60
int fesetexceptflag(const fexcept_t *flagp, int excepts)
Set exception flags.
Definition: fesetexceptflag.c:3
unsigned char
Dummy field to align.
Definition: fenv.h:47
fenv_t __FPU_read_environment()
Read FPU environment.
Definition: __FPU_read_environment.c:3
unsigned char condition_code_0
Condition code 0.
Definition: fenv.h:79
unsigned char stack_fault
Stack fault flag.
Definition: fenv.h:75
unsigned char precision_control
Precision control flag.
Definition: fenv.h:49
unsigned char condition_code_2
Condition code 2.
Definition: fenv.h:83
int fegetexceptflag(fexcept_t *flagp, int excepts)
Get exception flags.
Definition: fegetexceptflag.c:3
void __FPU_write_environment(fenv_t environment)
Write FPU environment.
Definition: __FPU_write_environment.c:3
unsigned char tag6
Describes content of 7th register.
Definition: fenv.h:109
unsigned short data_pointer_selector
Data pointer selector.
Definition: fenv.h:142
int feupdateenv(const fenv_t *envp)
Update floating-point environment.
Definition: feupdateenv.c:3
ftag_word_t tag_word
FPU tag word.
Definition: fenv.h:128
unsigned char top_of_stack_pointer
Points to top of stack pointer.
Definition: fenv.h:85
unsigned char precision
Precision exception.
Definition: fenv.h:73
unsigned char underflow
Underflow exception flag.
Definition: fenv.h:43
unsigned char tag7
Describes content of 8th register.
Definition: fenv.h:111
unsigned char overflow
Overflow exception.
Definition: fenv.h:69
unsigned char underflow
Underflow exception.
Definition: fenv.h:71
unsigned char tag3
Describes content of 4th register.
Definition: fenv.h:103
Type represent state of floating point control word.
Definition: fenv.h:32
int fesetround(int round)
Set rounding direction.
Definition: fesetround.c:3
int fesetenv(const fenv_t *envp)
Set entire environment.
Definition: fesetenv.c:3
unsigned char denormalized_operand
Denormalized operand exception flag.
Definition: fenv.h:37
unsigned char tag1
Describes content of 2nd register.
Definition: fenv.h:99
unsigned char invalid_operation
Invalid operation exception.
Definition: fenv.h:63
unsigned char invalid_operation
Invalid operation exception flag.
Definition: fenv.h:35
int fetestexcept(int excepts)
Test for floating-point exceptions.
Definition: fetestexcept.c:3
unsigned char precision
Precision exception flag.
Definition: fenv.h:45
unsigned short instruction_pointer_selector
Instruction pointer selector.
Definition: fenv.h:134
unsigned int instruction_pointer_offset
Instruction pointer offset.
Definition: fenv.h:132
unsigned char denormalized_operand
Denormalized operand exception.
Definition: fenv.h:65
unsigned char tag4
Describes content of 5th register.
Definition: fenv.h:105