Home | History | Annotate | Line # | Download | only in include
ieeefp.h revision 1.4.62.2
      1 /* $NetBSD: ieeefp.h,v 1.4.62.2 2017/04/26 02:57:17 pgoyette Exp $ */
      2 
      3 /*
      4  * Written by J.T. Conklin, Apr 6, 1995
      5  * Public domain.
      6  */
      7 
      8 #ifndef _SH3_IEEEFP_H_
      9 #define	_SH3_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_DENORMAL	0x02	/* denormalization exception */
     20 #define	FE_DIVBYZERO	0x04	/* divide-by-zero exception */
     21 #define	FE_OVERFLOW	0x08	/* overflow exception */
     22 #define	FE_UNDERFLOW	0x10	/* underflow exception */
     23 #define	FE_INEXACT	0x20	/* imprecise (loss of precision) */
     24 
     25 #define	FE_ALL_EXCEPT	0x3f
     26 
     27 #define	FE_TONEAREST	0	/* round to nearest representable number */
     28 #define	FE_DOWNWARD	1	/* round toward negative infinity */
     29 #define	FE_UPWARD	2	/* round toward positive infinity */
     30 #define	FE_TOWARDZERO	3	/* round to zero (truncate) */
     31 
     32 #if defined(_NETBSD_SOURCE)
     33 
     34 typedef int fp_except;
     35 
     36 #ifdef	__SH_FPU_ANY__
     37 
     38 /* hardfloat */
     39 
     40 #define	FP_X_INV	FE_INVALID	/* invalid operation exception */
     41 #define	FP_X_DNML	FE_DENORMAL	/* denormalization exception */
     42 #define	FP_X_DZ		FE_DIVBYZERO	/* divide-by-zero exception */
     43 #define	FP_X_OFL	FE_OVERFLOW	/* overflow exception */
     44 #define	FP_X_UFL	FE_UNDERFLOW	/* underflow exception */
     45 #define	FP_X_IMP	FE_INEXACT	/* imprecise (loss of precision) */
     46 
     47 typedef enum {
     48 	FP_RN=FE_TONEAREST,	/* round to nearest representable number */
     49 	FP_RM=FE_DOWNWARD,	/* round toward negative infinity */
     50 	FP_RP=FE_UPWARD,	/* round toward positive infinity */
     51 	FP_RZ=FE_TOWARDZERO	/* round to zero (truncate) */
     52 } fp_rnd;
     53 
     54 #else /* __SH_FPU_ANY__ */
     55 
     56 /* softfloat */
     57 
     58 #define	FP_X_INV	0x01	/* invalid operation exception */
     59 #define	FP_X_DZ		0x04	/* divide-by-zero exception */
     60 #define	FP_X_OFL	0x08	/* overflow exception */
     61 #define	FP_X_UFL	0x10	/* underflow exception */
     62 #define	FP_X_IMP	0x20	/* imprecise (loss of precision) */
     63 
     64 typedef enum {
     65 	FP_RN=0,		/* round to nearest representable number */
     66 	FP_RM=1,		/* round toward negative infinity */
     67 	FP_RP=2,        	/* round toward positive infinity */
     68 	FP_RZ=3			/* round to zero (truncate) */
     69 } fp_rnd;
     70 
     71 /* adjust for FP_* and FE_* value differences */
     72 
     73 static inline fp_except
     74 __FPE(int __fe)
     75 {
     76 	int __fp = 0;
     77 
     78 	if (__fe & FE_DIVBYZERO)
     79 		__fp |= FP_X_DZ;
     80 	if (__fe & FE_INEXACT)
     81 		__fp |= FP_X_IMP;
     82 	if (__fe & FE_INVALID)
     83 		__fp |= FP_X_INV;
     84 	if (__fe & FE_OVERFLOW)
     85 		__fp |= FP_X_OFL;
     86 	if (__fe & FE_UNDERFLOW)
     87 		__fp |= FP_X_UFL;
     88 	return __fp;
     89 }
     90 
     91 static inline int
     92 __FEE(fp_except __fp)
     93 {
     94 	int __fe = 0;
     95 
     96 	if (__fp & FP_X_DZ)
     97 		__fe |= FE_DIVBYZERO;
     98 	if (__fp & FP_X_IMP)
     99 		__fe |= FE_INEXACT;
    100 	if (__fp & FP_X_INV)
    101 		__fe |= FE_INVALID;
    102 	if (__fp & FP_X_OFL)
    103 		__fe |= FE_OVERFLOW;
    104 	if (__fp & FP_X_UFL)
    105 		__fe |= FE_UNDERFLOW;
    106 	return __fe;
    107 }
    108 
    109 static inline fp_rnd
    110 __FPR(int __fe)
    111 {
    112 
    113 	switch (__fe) {
    114 	case FE_TONEAREST:
    115 		return FP_RN;
    116 	case FE_DOWNWARD:
    117 		return FP_RM;
    118 	case FE_UPWARD:
    119 		return FP_RP;
    120 	case FE_TOWARDZERO:
    121 		return FP_RZ;
    122 	default:
    123 		return FP_RN;
    124 	}
    125 }
    126 
    127 static inline int
    128 __FER(fp_rnd __fp)
    129 {
    130 
    131 	switch (__fp) {
    132 	case FP_RN:
    133 		return FE_TONEAREST;
    134 	case FP_RM:
    135 		return FE_DOWNWARD;
    136 	case FP_RP:
    137 		return FE_UPWARD;
    138 	case FP_RZ:
    139 		return FE_TOWARDZERO;
    140 	default:
    141 		return FE_TONEAREST;
    142 	}
    143 }
    144 
    145 #endif /* __SH_FPU_ANY__ */
    146 
    147 #endif /* !_ISOC99_SOURCE */
    148 
    149 #endif /* _NETBSD_SOURCE || _ISOC99_SOURCE */
    150 
    151 #endif /* !_SH3_IEEEFP_H_ */
    152