xref: /reactos/sdk/include/ucrt/fpieee.h (revision 04e0dc4a)
1 //
2 // fpieee.h
3 //
4 //      Copyright (c) Microsoft Corporation. All rights reserved.
5 //
6 // This file contains constant and type definitions for handling floating point
7 // exceptions (IEEE 754).
8 //
9 #pragma once
10 #ifndef _INC_FPIEEE // include guard for 3rd party interop
11 #define _INC_FPIEEE
12 
13 #ifndef __midl
14 
15 #ifdef _M_CEE_PURE
16     #error ERROR: This file is not supported in the pure mode!
17 #endif
18 
19 #include <corecrt.h>
20 
21 #pragma warning(push)
22 #pragma warning(disable: _UCRT_DISABLED_WARNINGS)
23 _UCRT_DISABLE_CLANG_WARNINGS
24 
25 _CRT_BEGIN_C_HEADER
26 
27 
28 
29 #ifndef __assembler
30 
31     // Define floating point IEEE compare result values.
32     typedef enum
33     {
34         _FpCompareEqual,
35         _FpCompareGreater,
36         _FpCompareLess,
37         _FpCompareUnordered
38     } _FPIEEE_COMPARE_RESULT;
39 
40     // Define floating point format and result precision values.
41     typedef enum
42     {
43         _FpFormatFp32,
44         _FpFormatFp64,
45         _FpFormatFp80,
46         _FpFormatFp128,
47         _FpFormatI16,
48         _FpFormatI32,
49         _FpFormatI64,
50         _FpFormatU16,
51         _FpFormatU32,
52         _FpFormatU64,
53         _FpFormatBcd80,
54         _FpFormatCompare,
55         _FpFormatString,
56     } _FPIEEE_FORMAT;
57 
58     // Define operation code values.
59     typedef enum
60     {
61         _FpCodeUnspecified,
62         _FpCodeAdd,
63         _FpCodeSubtract,
64         _FpCodeMultiply,
65         _FpCodeDivide,
66         _FpCodeSquareRoot,
67         _FpCodeRemainder,
68         _FpCodeCompare,
69         _FpCodeConvert,
70         _FpCodeRound,
71         _FpCodeTruncate,
72         _FpCodeFloor,
73         _FpCodeCeil,
74         _FpCodeAcos,
75         _FpCodeAsin,
76         _FpCodeAtan,
77         _FpCodeAtan2,
78         _FpCodeCabs,
79         _FpCodeCos,
80         _FpCodeCosh,
81         _FpCodeExp,
82         _FpCodeFabs,
83         _FpCodeFmod,
84         _FpCodeFrexp,
85         _FpCodeHypot,
86         _FpCodeLdexp,
87         _FpCodeLog,
88         _FpCodeLog10,
89         _FpCodeModf,
90         _FpCodePow,
91         _FpCodeSin,
92         _FpCodeSinh,
93         _FpCodeTan,
94         _FpCodeTanh,
95         _FpCodeY0,
96         _FpCodeY1,
97         _FpCodeYn,
98         _FpCodeLogb,
99         _FpCodeNextafter,
100         _FpCodeNegate,
101         _FpCodeFmin,         // XMMI
102         _FpCodeFmax,         // XMMI
103         _FpCodeConvertTrunc, // XMMI
104         _XMMIAddps,          // XMMI
105         _XMMIAddss,
106         _XMMISubps,
107         _XMMISubss,
108         _XMMIMulps,
109         _XMMIMulss,
110         _XMMIDivps,
111         _XMMIDivss,
112         _XMMISqrtps,
113         _XMMISqrtss,
114         _XMMIMaxps,
115         _XMMIMaxss,
116         _XMMIMinps,
117         _XMMIMinss,
118         _XMMICmpps,
119         _XMMICmpss,
120         _XMMIComiss,
121         _XMMIUComiss,
122         _XMMICvtpi2ps,
123         _XMMICvtsi2ss,
124         _XMMICvtps2pi,
125         _XMMICvtss2si,
126         _XMMICvttps2pi,
127         _XMMICvttss2si,
128         _XMMIAddsubps,       // XMMI for PNI
129         _XMMIHaddps,         // XMMI for PNI
130         _XMMIHsubps,         // XMMI for PNI
131         _XMMIRoundps,        // 66 0F 3A 08
132         _XMMIRoundss,        // 66 0F 3A 0A
133         _XMMIDpps,           // 66 0F 3A 40
134         _XMMI2Addpd,         // XMMI2
135         _XMMI2Addsd,
136         _XMMI2Subpd,
137         _XMMI2Subsd,
138         _XMMI2Mulpd,
139         _XMMI2Mulsd,
140         _XMMI2Divpd,
141         _XMMI2Divsd,
142         _XMMI2Sqrtpd,
143         _XMMI2Sqrtsd,
144         _XMMI2Maxpd,
145         _XMMI2Maxsd,
146         _XMMI2Minpd,
147         _XMMI2Minsd,
148         _XMMI2Cmppd,
149         _XMMI2Cmpsd,
150         _XMMI2Comisd,
151         _XMMI2UComisd,
152         _XMMI2Cvtpd2pi,   // 66 2D
153         _XMMI2Cvtsd2si,   // F2
154         _XMMI2Cvttpd2pi,  // 66 2C
155         _XMMI2Cvttsd2si,  // F2
156         _XMMI2Cvtps2pd,   // 0F 5A
157         _XMMI2Cvtss2sd,   // F3
158         _XMMI2Cvtpd2ps,   // 66
159         _XMMI2Cvtsd2ss,   // F2
160         _XMMI2Cvtdq2ps,   // 0F 5B
161         _XMMI2Cvttps2dq,  // F3
162         _XMMI2Cvtps2dq,   // 66
163         _XMMI2Cvttpd2dq,  // 66 0F E6
164         _XMMI2Cvtpd2dq,   // F2
165         _XMMI2Addsubpd,   // 66 0F D0
166         _XMMI2Haddpd,     // 66 0F 7C
167         _XMMI2Hsubpd,     // 66 0F 7D
168         _XMMI2Roundpd,    // 66 0F 3A 09
169         _XMMI2Roundsd,    // 66 0F 3A 0B
170         _XMMI2Dppd,       // 66 0F 3A 41
171     } _FP_OPERATION_CODE;
172 
173 #endif // __assembler
174 
175 #ifdef _CORECRT_BUILD
176     #ifndef __assembler
177 
178         #define OP_UNSPEC    _FpCodeUnspecified
179         #define OP_ADD       _FpCodeAdd
180         #define OP_SUB       _FpCodeSubtract
181         #define OP_MUL       _FpCodeMultiply
182         #define OP_DIV       _FpCodeDivide
183         #define OP_REM       _FpCodeRemainder
184         #define OP_COMP      _FpCodeCompare
185         #define OP_CVT       _FpCodeConvert
186         #define OP_RND       _FpCodeRound
187         #define OP_TRUNC     _FpCodeTruncate
188 
189         #define OP_EXP       _FpCodeExp
190 
191         #define OP_POW       _FpCodePow
192         #define OP_LOG       _FpCodeLog
193         #define OP_LOG10     _FpCodeLog10
194         #define OP_SINH      _FpCodeSinh
195         #define OP_COSH      _FpCodeCosh
196         #define OP_TANH      _FpCodeTanh
197         #define OP_ASIN      _FpCodeAsin
198         #define OP_ACOS      _FpCodeAcos
199         #define OP_ATAN      _FpCodeAtan
200         #define OP_ATAN2     _FpCodeAtan2
201         #define OP_SQRT      _FpCodeSquareRoot
202         #define OP_SIN       _FpCodeSin
203         #define OP_COS       _FpCodeCos
204         #define OP_TAN       _FpCodeTan
205         #define OP_CEIL      _FpCodeCeil
206         #define OP_FLOOR     _FpCodeFloor
207         #define OP_ABS       _FpCodeFabs
208         #define OP_MODF      _FpCodeModf
209         #define OP_LDEXP     _FpCodeLdexp
210         #define OP_CABS      _FpCodeCabs
211         #define OP_HYPOT     _FpCodeHypot
212         #define OP_FMOD      _FpCodeFmod
213         #define OP_FREXP     _FpCodeFrexp
214         #define OP_Y0        _FpCodeY0
215         #define OP_Y1        _FpCodeY1
216         #define OP_YN        _FpCodeYn
217 
218         #define OP_LOGB       _FpCodeLogb
219         #define OP_NEXTAFTER  _FpCodeNextafter
220 
221         // XMMI
222         #define OP_ADDPS     _XMMIAddps
223         #define OP_ADDSS     _XMMIAddss
224         #define OP_SUBPS     _XMMISubps
225         #define OP_SUBSS     _XMMISubss
226         #define OP_MULPS     _XMMIMulps
227         #define OP_MULSS     _XMMIMulss
228         #define OP_DIVPS     _XMMIDivps
229         #define OP_DIVSS     _XMMIDivss
230         #define OP_SQRTPS    _XMMISqrtps
231         #define OP_SQRTSS    _XMMISqrtss
232         #define OP_MAXPS     _XMMIMaxps
233         #define OP_MAXSS     _XMMIMaxss
234         #define OP_MINPS     _XMMIMinps
235         #define OP_MINSS     _XMMIMinss
236         #define OP_CMPPS     _XMMICmpps
237         #define OP_CMPSS     _XMMICmpss
238         #define OP_COMISS    _XMMIComiss
239         #define OP_UCOMISS   _XMMIUComiss
240         #define OP_CVTPI2PS  _XMMICvtpi2ps
241         #define OP_CVTSI2SS  _XMMICvtsi2ss
242         #define OP_CVTPS2PI  _XMMICvtps2pi
243         #define OP_CVTSS2SI  _XMMICvtss2si
244         #define OP_CVTTPS2PI _XMMICvttps2pi
245         #define OP_CVTTSS2SI _XMMICvttss2si
246         #define OP_ADDSUBPS  _XMMIAddsubps
247         #define OP_HADDPS    _XMMIHaddps
248         #define OP_HSUBPS    _XMMIHsubps
249         #define OP_ROUNDPS   _XMMIRoundps
250         #define OP_ROUNDSS   _XMMIRoundss
251         #define OP_DPPS      _XMMIDpps
252         // XMMI
253 
254         // XMMI2
255         #define OP_ADDPD     _XMMI2Addpd      // XMMI2
256         #define OP_ADDSD     _XMMI2Addsd
257         #define OP_SUBPD     _XMMI2Subpd
258         #define OP_SUBSD     _XMMI2Subsd
259         #define OP_MULPD     _XMMI2Mulpd
260         #define OP_MULSD     _XMMI2Mulsd
261         #define OP_DIVPD     _XMMI2Divpd
262         #define OP_DIVSD     _XMMI2Divsd
263         #define OP_SQRTPD    _XMMI2Sqrtpd
264         #define OP_SQRTSD    _XMMI2Sqrtsd
265         #define OP_MAXPD     _XMMI2Maxpd
266         #define OP_MAXSD     _XMMI2Maxsd
267         #define OP_MINPD     _XMMI2Minpd
268         #define OP_MINSD     _XMMI2Minsd
269         #define OP_CMPPD     _XMMI2Cmppd
270         #define OP_CMPSD     _XMMI2Cmpsd
271         #define OP_COMISD    _XMMI2Comisd
272         #define OP_UCOMISD   _XMMI2UComisd
273         #define OP_CVTPD2PI  _XMMI2Cvtpd2pi   // 66 2D
274         #define OP_CVTSD2SI  _XMMI2Cvtsd2si   // F2
275         #define OP_CVTTPD2PI _XMMI2Cvttpd2pi  // 66 2C
276         #define OP_CVTTSD2SI _XMMI2Cvttsd2si  // F2
277         #define OP_CVTPS2PD  _XMMI2Cvtps2pd   // 0F 5A
278         #define OP_CVTSS2SD  _XMMI2Cvtss2sd   // F3
279         #define OP_CVTPD2PS  _XMMI2Cvtpd2ps   // 66
280         #define OP_CVTSD2SS  _XMMI2Cvtsd2ss   // F2
281         #define OP_CVTDQ2PS  _XMMI2Cvtdq2ps   // 0F 5B
282         #define OP_CVTTPS2DQ _XMMI2Cvttps2dq  // F3
283         #define OP_CVTPS2DQ  _XMMI2Cvtps2dq   // 66
284         #define OP_CVTTPD2DQ _XMMI2Cvttpd2dq  // 66 0F E6
285         #define OP_CVTPD2DQ  _XMMI2Cvtpd2dq   // F2
286         #define OP_ADDSUBPD  _XMMI2Addsubpd   // 66 0F D0
287         #define OP_HADDPD    _XMMI2Haddpd     // 66 0F 7C
288         #define OP_HSUBPD    _XMMI2Hsubpd     // 66 0F 7D
289         #define OP_ROUNDPD   _XMMI2Roundpd    // 66 0F 3A 09
290         #define OP_ROUNDSD   _XMMI2Roundsd    // 66 0F 3A 0B
291         #define OP_DPPD      _XMMI2Dppd       // 66 0F 3A 41
292         // XMMI2
293 
294     #else // __assembler
295 
296         // This must be the same as the enumerator _FP_OPERATION_CODE
297         #define OP_UNSPEC    0
298         #define OP_ADD       1
299         #define OP_SUB       2
300         #define OP_MUL       3
301         #define OP_DIV       4
302         #define OP_SQRT      5
303         #define OP_REM       6
304         #define OP_COMP      7
305         #define OP_CVT       8
306         #define OP_RND       9
307         #define OP_TRUNC     10
308         #define OP_FLOOR     11
309         #define OP_CEIL      12
310         #define OP_ACOS      13
311         #define OP_ASIN      14
312         #define OP_ATAN      15
313         #define OP_ATAN2     16
314         #define OP_CABS      17
315         #define OP_COS       18
316         #define OP_COSH      19
317         #define OP_EXP       20
318         #define OP_ABS       21         // same as OP_FABS
319         #define OP_FABS      21         // same as OP_ABS
320         #define OP_FMOD      22
321         #define OP_FREXP     23
322         #define OP_HYPOT     24
323         #define OP_LDEXP     25
324         #define OP_LOG       26
325         #define OP_LOG10     27
326         #define OP_MODF      28
327         #define OP_POW       29
328         #define OP_SIN       30
329         #define OP_SINH      31
330         #define OP_TAN       32
331         #define OP_TANH      33
332         #define OP_Y0        34
333         #define OP_Y1        35
334         #define OP_YN        36
335         #define OP_LOGB      37
336         #define OP_NEXTAFTER 38
337         #define OP_NEG       39
338 
339     #endif // __assembler
340 #endif // _CORECRT_BUILD
341 
342 // Define rounding modes.
343 #ifndef __assembler
344 
345     typedef enum
346     {
347         _FpRoundNearest,
348         _FpRoundMinusInfinity,
349         _FpRoundPlusInfinity,
350         _FpRoundChopped
351     } _FPIEEE_ROUNDING_MODE;
352 
353     typedef enum
354     {
355         _FpPrecisionFull,
356         _FpPrecision53,
357         _FpPrecision24,
358     } _FPIEEE_PRECISION;
359 
360 
361     // Define floating point context record
362     typedef float          _FP32;
363     typedef double         _FP64;
364     typedef short          _I16;
365     typedef int            _I32;
366     typedef unsigned short _U16;
367     typedef unsigned int   _U32;
368     typedef __int64        _Q64;
369 
370     #ifdef _CORECRT_BUILD
371     typedef struct
372     {
373         unsigned long W[4];
374     } _U32ARRAY;
375     #endif
376 
377     typedef struct
378     {
379         unsigned short W[5];
380     } _FP80;
381 
382     typedef struct _CRT_ALIGN(16)
383     {
384         unsigned long W[4];
385     } _FP128;
386 
387     typedef struct _CRT_ALIGN(8)
388     {
389         unsigned long W[2];
390     } _I64;
391 
392     typedef struct _CRT_ALIGN(8)
393     {
394         unsigned long W[2];
395     } _U64;
396 
397     typedef struct
398     {
399         unsigned short W[5];
400     } _BCD80;
401 
402     typedef struct _CRT_ALIGN(16)
403     {
404         _Q64 W[2];
405     } _FPQ64;
406 
407     typedef struct
408     {
409         union
410         {
411             _FP32        Fp32Value;
412             _FP64        Fp64Value;
413             _FP80        Fp80Value;
414             _FP128       Fp128Value;
415             _I16         I16Value;
416             _I32         I32Value;
417             _I64         I64Value;
418             _U16         U16Value;
419             _U32         U32Value;
420             _U64         U64Value;
421             _BCD80       Bcd80Value;
422             char         *StringValue;
423             int          CompareValue;
424             #ifdef _CORECRT_BUILD
425             _U32ARRAY    U32ArrayValue;
426             #endif
427             _Q64         Q64Value;
428             _FPQ64       Fpq64Value;
429         } Value;
430 
431         unsigned int OperandValid : 1;
432         unsigned int Format       : 4;
433 
434     } _FPIEEE_VALUE;
435 
436     typedef struct
437     {
438         unsigned int Inexact          : 1;
439         unsigned int Underflow        : 1;
440         unsigned int Overflow         : 1;
441         unsigned int ZeroDivide       : 1;
442         unsigned int InvalidOperation : 1;
443     } _FPIEEE_EXCEPTION_FLAGS;
444 
445 
446     typedef struct
447     {
448         unsigned int RoundingMode :  2;
449         unsigned int Precision    :  3;
450         unsigned int Operation    : 12;
451         _FPIEEE_EXCEPTION_FLAGS Cause;
452         _FPIEEE_EXCEPTION_FLAGS Enable;
453         _FPIEEE_EXCEPTION_FLAGS Status;
454         _FPIEEE_VALUE Operand1;
455         _FPIEEE_VALUE Operand2;
456         _FPIEEE_VALUE Result;
457     } _FPIEEE_RECORD, *_PFPIEEE_RECORD;
458 
459 
460     struct _EXCEPTION_POINTERS;
461 
462     typedef int (__cdecl* _FpieeFltHandlerType)(_FPIEEE_RECORD*);
463 
464     // Floating point IEEE exception filter routine
465     _ACRTIMP int __cdecl _fpieee_flt(
466         _In_ unsigned long               _ExceptionCode,
467         _In_ struct _EXCEPTION_POINTERS* _PtExceptionPtr,
468         _In_ _FpieeFltHandlerType        _Handler
469         );
470 
471 #endif // __assembler
472 
473 _CRT_END_C_HEADER
474 
475 _UCRT_RESTORE_CLANG_WARNINGS
476 #pragma warning(pop) // _UCRT_DISABLED_WARNINGS
477 #endif // __midl
478 #endif // _INC_FPIEEE
479