xref: /openbsd/sys/arch/sh/include/fenv.h (revision d6f349c8)
1*d6f349c8Smartynas /*	$OpenBSD: fenv.h,v 1.2 2011/04/28 17:34:23 martynas Exp $	*/
26e40b843Smartynas 
36e40b843Smartynas /*
46e40b843Smartynas  * Copyright (c) 2011 Martynas Venckus <martynas@openbsd.org>
56e40b843Smartynas  *
66e40b843Smartynas  * Permission to use, copy, modify, and distribute this software for any
76e40b843Smartynas  * purpose with or without fee is hereby granted, provided that the above
86e40b843Smartynas  * copyright notice and this permission notice appear in all copies.
96e40b843Smartynas  *
106e40b843Smartynas  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
116e40b843Smartynas  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
126e40b843Smartynas  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
136e40b843Smartynas  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
146e40b843Smartynas  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
156e40b843Smartynas  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
166e40b843Smartynas  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
176e40b843Smartynas  */
186e40b843Smartynas 
196e40b843Smartynas #ifndef	_SH_FENV_H_
206e40b843Smartynas #define	_SH_FENV_H_
216e40b843Smartynas 
226e40b843Smartynas /*
236e40b843Smartynas  * Each symbol representing a floating point exception expands to an integer
246e40b843Smartynas  * constant expression with values, such that bitwise-inclusive ORs of _all
256e40b843Smartynas  * combinations_ of the constants result in distinct values.
266e40b843Smartynas  *
276e40b843Smartynas  * We use such values that allow direct bitwise operations on FPU registers.
286e40b843Smartynas  */
296e40b843Smartynas #define	FE_INEXACT		0x04
306e40b843Smartynas #define	FE_UNDERFLOW		0x08
316e40b843Smartynas #define	FE_OVERFLOW		0x10
326e40b843Smartynas #define	FE_DIVBYZERO		0x20
336e40b843Smartynas #define	FE_INVALID		0x40
346e40b843Smartynas 
356e40b843Smartynas /*
366e40b843Smartynas  * The following symbol is simply the bitwise-inclusive OR of all floating-point
376e40b843Smartynas  * exception constants defined above.
386e40b843Smartynas  */
39*d6f349c8Smartynas #define	FE_ALL_EXCEPT		(FE_INEXACT | FE_UNDERFLOW | FE_OVERFLOW | \
40*d6f349c8Smartynas 				 FE_DIVBYZERO | FE_INVALID)
41*d6f349c8Smartynas #define	_MASK_SHIFT		5
426e40b843Smartynas 
436e40b843Smartynas /*
446e40b843Smartynas  * Each symbol representing the rounding direction, expands to an integer
456e40b843Smartynas  * constant expression whose value is distinct non-negative value.
466e40b843Smartynas  *
476e40b843Smartynas  * We use such values that allow direct bitwise operations on FPU registers.
486e40b843Smartynas  */
496e40b843Smartynas #define	FE_TONEAREST		0x0
506e40b843Smartynas #define	FE_TOWARDZERO		0x1
516e40b843Smartynas #define	FE_UPWARD		0x2
526e40b843Smartynas #define	FE_DOWNWARD		0x3
536e40b843Smartynas 
546e40b843Smartynas /*
55*d6f349c8Smartynas  * The following symbol is simply the bitwise-inclusive OR of all floating-point
56*d6f349c8Smartynas  * rounding direction constants defined above.
576e40b843Smartynas  */
58*d6f349c8Smartynas #define	_ROUND_MASK		(FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD | \
59*d6f349c8Smartynas 				 FE_DOWNWARD)
606e40b843Smartynas 
616e40b843Smartynas /*
62*d6f349c8Smartynas  * fenv_t represents the entire floating-point environment.
636e40b843Smartynas  */
646e40b843Smartynas typedef	unsigned int		fenv_t;
656e40b843Smartynas 
66*d6f349c8Smartynas /*
67*d6f349c8Smartynas  * The following constant represents the default floating-point environment
68*d6f349c8Smartynas  * (that is, the one installed at program startup) and has type pointer to
69*d6f349c8Smartynas  * const-qualified fenv_t.
70*d6f349c8Smartynas  *
71*d6f349c8Smartynas  * It can be used as an argument to the functions within the <fenv.h> header
72*d6f349c8Smartynas  * that manage the floating-point environment, namely fesetenv() and
73*d6f349c8Smartynas  * feupdateenv().
74*d6f349c8Smartynas  */
756e40b843Smartynas extern	fenv_t			__fe_dfl_env;
766e40b843Smartynas #define	FE_DFL_ENV		((const fenv_t *)&__fe_dfl_env)
776e40b843Smartynas 
786e40b843Smartynas /*
796e40b843Smartynas  * fexcept_t represents the floating-point status flags collectively, including
806e40b843Smartynas  * any status the implementation associates with the flags.
816e40b843Smartynas  *
826e40b843Smartynas  * A floating-point status flag is a system variable whose value is set (but
836e40b843Smartynas  * never cleared) when a floating-point exception is raised, which occurs as a
846e40b843Smartynas  * side effect of exceptional floating-point arithmetic to provide auxiliary
856e40b843Smartynas  * information.
866e40b843Smartynas  *
876e40b843Smartynas  * A floating-point control mode is a system variable whose value may be set by
886e40b843Smartynas  * the user to affect the subsequent behavior of floating-point arithmetic.
896e40b843Smartynas  */
906e40b843Smartynas typedef	unsigned int		fexcept_t;
916e40b843Smartynas 
926e40b843Smartynas #endif	/* !_SH_FENV_H_ */
93