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