xref: /openbsd/sys/arch/powerpc/include/fenv.h (revision c9683224)
1*c9683224Smartynas /*	$OpenBSD: fenv.h,v 1.3 2011/05/25 21:46:49 martynas Exp $	*/
20503db22Smartynas 
30503db22Smartynas /*
40503db22Smartynas  * Copyright (c) 2011 Martynas Venckus <martynas@openbsd.org>
50503db22Smartynas  *
60503db22Smartynas  * Permission to use, copy, modify, and distribute this software for any
70503db22Smartynas  * purpose with or without fee is hereby granted, provided that the above
80503db22Smartynas  * copyright notice and this permission notice appear in all copies.
90503db22Smartynas  *
100503db22Smartynas  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
110503db22Smartynas  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
120503db22Smartynas  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
130503db22Smartynas  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
140503db22Smartynas  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
150503db22Smartynas  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
160503db22Smartynas  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
170503db22Smartynas  */
180503db22Smartynas 
190503db22Smartynas #ifndef	_POWERPC_FENV_H_
200503db22Smartynas #define	_POWERPC_FENV_H_
210503db22Smartynas 
220503db22Smartynas /*
230503db22Smartynas  * Each symbol representing a floating point exception expands to an integer
240503db22Smartynas  * constant expression with values, such that bitwise-inclusive ORs of _all
250503db22Smartynas  * combinations_ of the constants result in distinct values.
260503db22Smartynas  *
270503db22Smartynas  * We use such values that allow direct bitwise operations on FPU registers.
280503db22Smartynas  */
290503db22Smartynas #define	FE_INEXACT		0x02000000
300503db22Smartynas #define	FE_DIVBYZERO		0x04000000
310503db22Smartynas #define	FE_UNDERFLOW		0x08000000
320503db22Smartynas #define	FE_OVERFLOW		0x10000000
330503db22Smartynas #define	FE_INVALID		0x20000000
340503db22Smartynas #define	_FE_INVALID_SOFT	0x00000400
350503db22Smartynas #define	_FE_INVALID_ALL		0x01f80700
360503db22Smartynas 
370503db22Smartynas /*
380503db22Smartynas  * The following symbol is simply the bitwise-inclusive OR of all floating-point
390503db22Smartynas  * exception constants defined above.
400503db22Smartynas  */
41d6f349c8Smartynas #define	FE_ALL_EXCEPT		(FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | \
42d6f349c8Smartynas 				 FE_OVERFLOW | FE_INVALID)
43d6f349c8Smartynas #define	_MASK_SHIFT		22
440503db22Smartynas 
450503db22Smartynas /*
460503db22Smartynas  * Each symbol representing the rounding direction, expands to an integer
470503db22Smartynas  * constant expression whose value is distinct non-negative value.
480503db22Smartynas  *
490503db22Smartynas  * We use such values that allow direct bitwise operations on FPU registers.
500503db22Smartynas  */
510503db22Smartynas #define	FE_TONEAREST		0x0
520503db22Smartynas #define	FE_TOWARDZERO		0x1
530503db22Smartynas #define	FE_UPWARD		0x2
540503db22Smartynas #define	FE_DOWNWARD		0x3
550503db22Smartynas 
560503db22Smartynas /*
57d6f349c8Smartynas  * The following symbol is simply the bitwise-inclusive OR of all floating-point
58d6f349c8Smartynas  * rounding direction constants defined above.
590503db22Smartynas  */
60d6f349c8Smartynas #define	_ROUND_MASK		(FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD | \
61d6f349c8Smartynas 				 FE_DOWNWARD)
620503db22Smartynas 
630503db22Smartynas /*
64d6f349c8Smartynas  * fenv_t represents the entire floating-point environment.
650503db22Smartynas  */
660503db22Smartynas typedef	unsigned int		fenv_t;
670503db22Smartynas 
68d6f349c8Smartynas /*
69d6f349c8Smartynas  * The following constant represents the default floating-point environment
70d6f349c8Smartynas  * (that is, the one installed at program startup) and has type pointer to
71d6f349c8Smartynas  * const-qualified fenv_t.
72d6f349c8Smartynas  *
73d6f349c8Smartynas  * It can be used as an argument to the functions within the <fenv.h> header
74d6f349c8Smartynas  * that manage the floating-point environment, namely fesetenv() and
75d6f349c8Smartynas  * feupdateenv().
76d6f349c8Smartynas  */
77*c9683224Smartynas __BEGIN_DECLS
780503db22Smartynas extern	fenv_t			__fe_dfl_env;
79*c9683224Smartynas __END_DECLS
800503db22Smartynas #define	FE_DFL_ENV		((const fenv_t *)&__fe_dfl_env)
810503db22Smartynas 
820503db22Smartynas /*
830503db22Smartynas  * fexcept_t represents the floating-point status flags collectively, including
840503db22Smartynas  * any status the implementation associates with the flags.
850503db22Smartynas  *
860503db22Smartynas  * A floating-point status flag is a system variable whose value is set (but
870503db22Smartynas  * never cleared) when a floating-point exception is raised, which occurs as a
880503db22Smartynas  * side effect of exceptional floating-point arithmetic to provide auxiliary
890503db22Smartynas  * information.
900503db22Smartynas  *
910503db22Smartynas  * A floating-point control mode is a system variable whose value may be set by
920503db22Smartynas  * the user to affect the subsequent behavior of floating-point arithmetic.
930503db22Smartynas  */
940503db22Smartynas typedef	unsigned int		fexcept_t;
950503db22Smartynas 
960503db22Smartynas #endif	/* !_POWERPC_FENV_H_ */
97