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