xref: /openbsd/sys/arch/amd64/include/fenv.h (revision d89ec533)
1 /*	$OpenBSD: fenv.h,v 1.4 2011/05/25 21:46:49 martynas Exp $	*/
2 /*	$NetBSD: fenv.h,v 1.1 2010/07/31 21:47:54 joerg Exp $	*/
3 
4 /*-
5  * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef	_AMD64_FENV_H_
31 #define	_AMD64_FENV_H_
32 
33 /*
34  * Each symbol representing a floating point exception expands to an integer
35  * constant expression with values, such that bitwise-inclusive ORs of _all
36  * combinations_ of the constants result in distinct values.
37  *
38  * We use such values that allow direct bitwise operations on FPU/SSE registers.
39  */
40 #define	FE_INVALID		0x01
41 #define	FE_DENORMAL		0x02
42 #define	FE_DIVBYZERO		0x04
43 #define	FE_OVERFLOW		0x08
44 #define	FE_UNDERFLOW		0x10
45 #define	FE_INEXACT		0x20
46 
47 /*
48  * The following symbol is simply the bitwise-inclusive OR of all floating-point
49  * exception constants defined above.
50  */
51 #define	FE_ALL_EXCEPT		(FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \
52 				 FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
53 #define	_SSE_MASK_SHIFT		7
54 
55 /*
56  * Each symbol representing the rounding direction, expands to an integer
57  * constant expression whose value is distinct non-negative value.
58  *
59  * We use such values that allow direct bitwise operations on FPU/SSE registers.
60  */
61 #define	FE_TONEAREST		0x000
62 #define	FE_DOWNWARD		0x400
63 #define	FE_UPWARD		0x800
64 #define	FE_TOWARDZERO		0xc00
65 
66 /*
67  * The following symbol is simply the bitwise-inclusive OR of all floating-point
68  * rounding direction constants defined above.
69  */
70 #define	_X87_ROUND_MASK		(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | \
71 				 FE_TOWARDZERO)
72 #define	_SSE_ROUND_SHIFT	3
73 
74 /*
75  * fenv_t represents the entire floating-point environment.
76  */
77 typedef	struct {
78 	struct {
79 		unsigned int __control;		/* Control word register */
80 		unsigned int __status;		/* Status word register */
81 		unsigned int __tag;		/* Tag word register */
82 		unsigned int __others[4];	/* EIP, Pointer Selector, etc */
83 	} __x87;
84 	unsigned int __mxcsr;			/* Control, status register */
85 } fenv_t;
86 
87 /*
88  * The following constant represents the default floating-point environment
89  * (that is, the one installed at program startup) and has type pointer to
90  * const-qualified fenv_t.
91  *
92  * It can be used as an argument to the functions within the <fenv.h> header
93  * that manage the floating-point environment, namely fesetenv() and
94  * feupdateenv().
95  */
96 __BEGIN_DECLS
97 extern	fenv_t			__fe_dfl_env;
98 __END_DECLS
99 #define	FE_DFL_ENV		((const fenv_t *)&__fe_dfl_env)
100 
101 /*
102  * fexcept_t represents the floating-point status flags collectively, including
103  * any status the implementation associates with the flags.
104  *
105  * A floating-point status flag is a system variable whose value is set (but
106  * never cleared) when a floating-point exception is raised, which occurs as a
107  * side effect of exceptional floating-point arithmetic to provide auxiliary
108  * information.
109  *
110  * A floating-point control mode is a system variable whose value may be set by
111  * the user to affect the subsequent behavior of floating-point arithmetic.
112  */
113 typedef	unsigned int		fexcept_t;
114 
115 #endif	/* !_AMD64_FENV_H_ */
116