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