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