xref: /openbsd/sys/arch/amd64/include/fenv.h (revision 3d8817e4)
1 /*	$OpenBSD: fenv.h,v 1.2 2011/04/23 21:54:20 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		\
52 	(FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW | \
53 	 FE_DENORMAL)
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  * As compared to the x87 control word, the SSE unit's control word
68  * has the rounding control bits offset by 3 and the exception mask
69  * bits offset by 7.
70  */
71 #define	_X87_ROUND_MASK		0xC00
72 #define	_SSE_ROUND_MASK		(0xC00 << 3)
73 #define	_SSE_ROUND_SHIFT	3
74 #define	_SSE_EMASK_SHIFT	7
75 
76 /*
77  * fenv_t represents the entire floating-point environment
78  */
79 typedef struct {
80 	struct {
81 		unsigned int __control;		/* Control word register */
82 		unsigned int __status;		/* Status word register */
83 		unsigned int __tag;		/* Tag word register */
84 		unsigned int __others[4];	/* EIP, Pointer Selector, etc */
85 	} __x87;
86 	unsigned int __mxcsr;			/* Control, status register */
87 } fenv_t;
88 
89 extern fenv_t			__fe_dfl_env;
90 #define	FE_DFL_ENV		((const fenv_t *) &__fe_dfl_env)
91 
92 /*
93  * fexcept_t represents the floating-point status flags collectively, including
94  * any status the implementation associates with the flags.
95  *
96  * A floating-point status flag is a system variable whose value is set (but
97  * never cleared) when a floating-point exception is raised, which occurs as a
98  * side effect of exceptional floating-point arithmetic to provide auxiliary
99  * information.
100  *
101  * A floating-point control mode is a system variable whose value may be set by
102  * the user to affect the subsequent behavior of floating-point arithmetic.
103  */
104 typedef unsigned int fexcept_t;
105 
106 #endif	/* ! _AMD64_FENV_H_ */
107