Home | History | Annotate | Line # | Download | only in include
ieeefp.h revision 1.6
      1  1.6     matt /* $NetBSD: ieeefp.h,v 1.6 2008/08/05 16:47:41 matt Exp $ */
      2  1.1      cgd 
      3  1.1      cgd /*
      4  1.1      cgd  * Written by J.T. Conklin, Apr 28, 1995
      5  1.1      cgd  * Public domain.
      6  1.1      cgd  */
      7  1.1      cgd 
      8  1.1      cgd #ifndef _ALPHA_IEEEFP_H_
      9  1.1      cgd #define _ALPHA_IEEEFP_H_
     10  1.1      cgd 
     11  1.6     matt #include <sys/featuretest.h>
     12  1.6     matt 
     13  1.6     matt #if defined(_NETBSD_SOURCE) || defined(_ISOC99_SOURCE)
     14  1.6     matt 
     15  1.6     matt typedef int fenv_t;
     16  1.6     matt typedef int fexcept_t;
     17  1.6     matt 
     18  1.6     matt #define	FE_INVALID	0x01	/* invalid operation exception */
     19  1.6     matt #define	FE_DIVBYZERO	0x02	/* divide-by-zero exception */
     20  1.6     matt #define	FE_OVERFLOW	0x04	/* overflow exception */
     21  1.6     matt #define	FE_UNDERFLOW	0x08	/* underflow exception */
     22  1.6     matt #define	FE_INEXACT	0x10	/* imprecise (loss of precision; "inexact") */
     23  1.6     matt #define	FP_IOVERFLOW	0x20    /* integer overflow */
     24  1.6     matt 
     25  1.6     matt #define	FE_ALL_EXCEPT	0x3f
     26  1.6     matt 
     27  1.6     matt /*
     28  1.6     matt  * These bits match the fpcr as well as bits 12:11
     29  1.6     matt  * in fp operate instructions
     30  1.6     matt  */
     31  1.6     matt #define	FE_TOWARDZERO	0	/* round to zero (truncate) */
     32  1.6     matt #define	FE_DOWNWARD	1	/* round toward negative infinity */
     33  1.6     matt #define	FE_TONEAREST	2	/* round to nearest representable number */
     34  1.6     matt #define	FE_UPWARD	3	/* round toward positive infinity */
     35  1.6     matt 
     36  1.6     matt #if !defined(_ISOC99_SOURCE)
     37  1.6     matt 
     38  1.1      cgd typedef int fp_except;
     39  1.4     ross 
     40  1.6     matt #if defined(_KERNEL)
     41  1.4     ross 
     42  1.4     ross #include <sys/param.h>
     43  1.4     ross #include <sys/proc.h>
     44  1.4     ross #include <machine/fpu.h>
     45  1.4     ross #include <machine/alpha.h>
     46  1.4     ross 
     47  1.4     ross /* FP_X_IOV is intentionally omitted from the architecture flags mask */
     48  1.4     ross 
     49  1.4     ross #define	FP_AA_FLAGS (FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP)
     50  1.4     ross 
     51  1.4     ross #define float_raise(f)						\
     52  1.5  thorpej 	do curlwp->l_md.md_flags |= NETBSD_FLAG_TO_FP_C(f);	\
     53  1.4     ross 	while(0)
     54  1.4     ross 
     55  1.4     ross #define float_set_inexact()	float_raise(FP_X_IMP)
     56  1.4     ross #define float_set_invalid()	float_raise(FP_X_INV)
     57  1.4     ross #define	fpgetround()		(alpha_read_fpcr() >> 58 & 3)
     58  1.4     ross 
     59  1.6     matt #endif /* _KERNEL */
     60  1.4     ross 
     61  1.6     matt #define	FP_X_INV	FE_INVALID	/* invalid operation exception */
     62  1.6     matt #define	FP_X_DZ		FE_DIVBYZERO	/* divide-by-zero exception */
     63  1.6     matt #define	FP_X_OFL	FE_OVERFLOW	/* overflow exception */
     64  1.6     matt #define	FP_X_UFL	FE_UNDERFLOW	/* underflow exception */
     65  1.6     matt #define	FP_X_IMP	FE_INEXACT	/* imprecise (prec. loss; "inexact") */
     66  1.6     matt #define	FP_X_IOV	FE_IOVERFLOW	/* integer overflow */
     67  1.1      cgd 
     68  1.4     ross /*
     69  1.4     ross  * fp_rnd bits match the fpcr, below, as well as bits 12:11
     70  1.4     ross  * in fp operate instructions
     71  1.4     ross  */
     72  1.1      cgd typedef enum {
     73  1.6     matt     FP_RZ = FE_TOWARDZERO,	/* round to zero (truncate) */
     74  1.6     matt     FP_RM = FE_DOWNWARD,	/* round toward negative infinity */
     75  1.6     matt     FP_RN = FE_TONEAREST,	/* round to nearest representable number */
     76  1.6     matt     FP_RP = FE_UPWARD,		/* round toward positive infinity */
     77  1.4     ross     _FP_DYNAMIC=FP_RP
     78  1.1      cgd } fp_rnd;
     79  1.1      cgd 
     80  1.6     matt #endif /* !_ISOC99_SOURCE */
     81  1.6     matt 
     82  1.6     matt #endif	/* _NETBSD_SOURCE || _ISOC99_SOURCE */
     83  1.6     matt 
     84  1.1      cgd #endif /* _ALPHA_IEEEFP_H_ */
     85