xref: /dflybsd-src/contrib/openbsd_libm/include/amd64/fenv.h (revision 74b7c7a8f84d2074b354ec1a601ec20152ace31f)
105a0b428SJohn Marino /*	$OpenBSD: fenv.h,v 1.4 2011/05/25 21:46:49 martynas Exp $	*/
205a0b428SJohn Marino /*	$NetBSD: fenv.h,v 1.1 2010/07/31 21:47:54 joerg Exp $	*/
305a0b428SJohn Marino 
405a0b428SJohn Marino /*-
505a0b428SJohn Marino  * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG>
605a0b428SJohn Marino  * All rights reserved.
705a0b428SJohn Marino  *
805a0b428SJohn Marino  * Redistribution and use in source and binary forms, with or without
905a0b428SJohn Marino  * modification, are permitted provided that the following conditions
1005a0b428SJohn Marino  * are met:
1105a0b428SJohn Marino  * 1. Redistributions of source code must retain the above copyright
1205a0b428SJohn Marino  *    notice, this list of conditions and the following disclaimer.
1305a0b428SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
1405a0b428SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
1505a0b428SJohn Marino  *    documentation and/or other materials provided with the distribution.
1605a0b428SJohn Marino  *
1705a0b428SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1805a0b428SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1905a0b428SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2005a0b428SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2105a0b428SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2205a0b428SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2305a0b428SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2405a0b428SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2505a0b428SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2605a0b428SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2705a0b428SJohn Marino  * SUCH DAMAGE.
2805a0b428SJohn Marino  */
2905a0b428SJohn Marino 
3005a0b428SJohn Marino #ifndef	_AMD64_FENV_H_
3105a0b428SJohn Marino #define	_AMD64_FENV_H_
3205a0b428SJohn Marino 
33*74b7c7a8SJohn Marino #include <sys/cdefs.h>
34*74b7c7a8SJohn Marino 
3505a0b428SJohn Marino /*
3605a0b428SJohn Marino  * Each symbol representing a floating point exception expands to an integer
3705a0b428SJohn Marino  * constant expression with values, such that bitwise-inclusive ORs of _all
3805a0b428SJohn Marino  * combinations_ of the constants result in distinct values.
3905a0b428SJohn Marino  *
4005a0b428SJohn Marino  * We use such values that allow direct bitwise operations on FPU/SSE registers.
4105a0b428SJohn Marino  */
4205a0b428SJohn Marino #define	FE_INVALID		0x01
4305a0b428SJohn Marino #define	FE_DENORMAL		0x02
4405a0b428SJohn Marino #define	FE_DIVBYZERO		0x04
4505a0b428SJohn Marino #define	FE_OVERFLOW		0x08
4605a0b428SJohn Marino #define	FE_UNDERFLOW		0x10
4705a0b428SJohn Marino #define	FE_INEXACT		0x20
4805a0b428SJohn Marino 
4905a0b428SJohn Marino /*
5005a0b428SJohn Marino  * The following symbol is simply the bitwise-inclusive OR of all floating-point
5105a0b428SJohn Marino  * exception constants defined above.
5205a0b428SJohn Marino  */
5305a0b428SJohn Marino #define	FE_ALL_EXCEPT		(FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \
5405a0b428SJohn Marino 				 FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
5505a0b428SJohn Marino #define	_SSE_MASK_SHIFT		7
5605a0b428SJohn Marino 
5705a0b428SJohn Marino /*
5805a0b428SJohn Marino  * Each symbol representing the rounding direction, expands to an integer
5905a0b428SJohn Marino  * constant expression whose value is distinct non-negative value.
6005a0b428SJohn Marino  *
6105a0b428SJohn Marino  * We use such values that allow direct bitwise operations on FPU/SSE registers.
6205a0b428SJohn Marino  */
6305a0b428SJohn Marino #define	FE_TONEAREST		0x000
6405a0b428SJohn Marino #define	FE_DOWNWARD		0x400
6505a0b428SJohn Marino #define	FE_UPWARD		0x800
6605a0b428SJohn Marino #define	FE_TOWARDZERO		0xc00
6705a0b428SJohn Marino 
6805a0b428SJohn Marino /*
6905a0b428SJohn Marino  * The following symbol is simply the bitwise-inclusive OR of all floating-point
7005a0b428SJohn Marino  * rounding direction constants defined above.
7105a0b428SJohn Marino  */
7205a0b428SJohn Marino #define	_X87_ROUND_MASK		(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | \
7305a0b428SJohn Marino 				 FE_TOWARDZERO)
7405a0b428SJohn Marino #define	_SSE_ROUND_SHIFT	3
7505a0b428SJohn Marino 
7605a0b428SJohn Marino /*
7705a0b428SJohn Marino  * fenv_t represents the entire floating-point environment.
7805a0b428SJohn Marino  */
7905a0b428SJohn Marino typedef	struct {
8005a0b428SJohn Marino 	struct {
8105a0b428SJohn Marino 		unsigned int __control;		/* Control word register */
8205a0b428SJohn Marino 		unsigned int __status;		/* Status word register */
8305a0b428SJohn Marino 		unsigned int __tag;		/* Tag word register */
8405a0b428SJohn Marino 		unsigned int __others[4];	/* EIP, Pointer Selector, etc */
8505a0b428SJohn Marino 	} __x87;
8605a0b428SJohn Marino 	unsigned int __mxcsr;			/* Control, status register */
8705a0b428SJohn Marino } fenv_t;
8805a0b428SJohn Marino 
8905a0b428SJohn Marino /*
9005a0b428SJohn Marino  * The following constant represents the default floating-point environment
9105a0b428SJohn Marino  * (that is, the one installed at program startup) and has type pointer to
9205a0b428SJohn Marino  * const-qualified fenv_t.
9305a0b428SJohn Marino  *
9405a0b428SJohn Marino  * It can be used as an argument to the functions within the <fenv.h> header
9505a0b428SJohn Marino  * that manage the floating-point environment, namely fesetenv() and
9605a0b428SJohn Marino  * feupdateenv().
9705a0b428SJohn Marino  */
9805a0b428SJohn Marino __BEGIN_DECLS
9905a0b428SJohn Marino extern	fenv_t			__fe_dfl_env;
10005a0b428SJohn Marino __END_DECLS
10105a0b428SJohn Marino #define	FE_DFL_ENV		((const fenv_t *)&__fe_dfl_env)
10205a0b428SJohn Marino 
10305a0b428SJohn Marino /*
10405a0b428SJohn Marino  * fexcept_t represents the floating-point status flags collectively, including
10505a0b428SJohn Marino  * any status the implementation associates with the flags.
10605a0b428SJohn Marino  *
10705a0b428SJohn Marino  * A floating-point status flag is a system variable whose value is set (but
10805a0b428SJohn Marino  * never cleared) when a floating-point exception is raised, which occurs as a
10905a0b428SJohn Marino  * side effect of exceptional floating-point arithmetic to provide auxiliary
11005a0b428SJohn Marino  * information.
11105a0b428SJohn Marino  *
11205a0b428SJohn Marino  * A floating-point control mode is a system variable whose value may be set by
11305a0b428SJohn Marino  * the user to affect the subsequent behavior of floating-point arithmetic.
11405a0b428SJohn Marino  */
11505a0b428SJohn Marino typedef	unsigned int		fexcept_t;
11605a0b428SJohn Marino 
11705a0b428SJohn Marino #endif	/* !_AMD64_FENV_H_ */
118