1 /* Software floating-point emulation. 1 /* Software floating-point emulation. 2 Copyright (C) 1997,1998,1999 Free Software 2 Copyright (C) 1997,1998,1999 Free Software Foundation, Inc. 3 This file is part of the GNU C Library. 3 This file is part of the GNU C Library. 4 Contributed by Richard Henderson (rth@cygnu 4 Contributed by Richard Henderson (rth@cygnus.com), 5 Jakub Jelinek (jj@ultra.linu 5 Jakub Jelinek (jj@ultra.linux.cz), 6 David S. Miller (davem@redha 6 David S. Miller (davem@redhat.com) and 7 Peter Maydell (pmaydell@chia 7 Peter Maydell (pmaydell@chiark.greenend.org.uk). 8 8 9 The GNU C Library is free software; you can 9 The GNU C Library is free software; you can redistribute it and/or 10 modify it under the terms of the GNU Librar 10 modify it under the terms of the GNU Library General Public License as 11 published by the Free Software Foundation; 11 published by the Free Software Foundation; either version 2 of the 12 License, or (at your option) any later vers 12 License, or (at your option) any later version. 13 13 14 The GNU C Library is distributed in the hop 14 The GNU C Library is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 Library General Public License for more det 17 Library General Public License for more details. 18 18 19 You should have received a copy of the GNU 19 You should have received a copy of the GNU Library General Public 20 License along with the GNU C Library; see t 20 License along with the GNU C Library; see the file COPYING.LIB. If 21 not, write to the Free Software Foundation, 21 not, write to the Free Software Foundation, Inc., 22 59 Temple Place - Suite 330, Boston, MA 021 22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 23 23 24 #ifndef __MATH_EMU_SOFT_FP_H__ 24 #ifndef __MATH_EMU_SOFT_FP_H__ 25 #define __MATH_EMU_SOFT_FP_H__ 25 #define __MATH_EMU_SOFT_FP_H__ 26 26 27 #include <asm/sfp-machine.h> 27 #include <asm/sfp-machine.h> 28 28 29 /* Allow sfp-machine to have its own byte orde 29 /* Allow sfp-machine to have its own byte order definitions. */ 30 #ifndef __BYTE_ORDER 30 #ifndef __BYTE_ORDER 31 #include <endian.h> 31 #include <endian.h> 32 #endif 32 #endif 33 33 34 #define _FP_WORKBITS 3 34 #define _FP_WORKBITS 3 35 #define _FP_WORK_LSB ((_FP_W_TYPE)1 35 #define _FP_WORK_LSB ((_FP_W_TYPE)1 << 3) 36 #define _FP_WORK_ROUND ((_FP_W_TYPE)1 36 #define _FP_WORK_ROUND ((_FP_W_TYPE)1 << 2) 37 #define _FP_WORK_GUARD ((_FP_W_TYPE)1 37 #define _FP_WORK_GUARD ((_FP_W_TYPE)1 << 1) 38 #define _FP_WORK_STICKY ((_FP_W_TYPE)1 38 #define _FP_WORK_STICKY ((_FP_W_TYPE)1 << 0) 39 39 40 #ifndef FP_RND_NEAREST 40 #ifndef FP_RND_NEAREST 41 # define FP_RND_NEAREST 0 41 # define FP_RND_NEAREST 0 42 # define FP_RND_ZERO 1 42 # define FP_RND_ZERO 1 43 # define FP_RND_PINF 2 43 # define FP_RND_PINF 2 44 # define FP_RND_MINF 3 44 # define FP_RND_MINF 3 45 #ifndef FP_ROUNDMODE 45 #ifndef FP_ROUNDMODE 46 # define FP_ROUNDMODE FP_RND_NEAREST 46 # define FP_ROUNDMODE FP_RND_NEAREST 47 #endif 47 #endif 48 #endif 48 #endif 49 49 50 /* By default don't care about exceptions. */ 50 /* By default don't care about exceptions. */ 51 #ifndef FP_EX_INVALID 51 #ifndef FP_EX_INVALID 52 #define FP_EX_INVALID 0 52 #define FP_EX_INVALID 0 53 #endif 53 #endif 54 #ifndef FP_EX_INVALID_SNAN 54 #ifndef FP_EX_INVALID_SNAN 55 #define FP_EX_INVALID_SNAN 0 55 #define FP_EX_INVALID_SNAN 0 56 #endif 56 #endif 57 /* inf - inf */ 57 /* inf - inf */ 58 #ifndef FP_EX_INVALID_ISI 58 #ifndef FP_EX_INVALID_ISI 59 #define FP_EX_INVALID_ISI 0 59 #define FP_EX_INVALID_ISI 0 60 #endif 60 #endif 61 /* inf / inf */ 61 /* inf / inf */ 62 #ifndef FP_EX_INVALID_IDI 62 #ifndef FP_EX_INVALID_IDI 63 #define FP_EX_INVALID_IDI 0 63 #define FP_EX_INVALID_IDI 0 64 #endif 64 #endif 65 /* 0 / 0 */ 65 /* 0 / 0 */ 66 #ifndef FP_EX_INVALID_ZDZ 66 #ifndef FP_EX_INVALID_ZDZ 67 #define FP_EX_INVALID_ZDZ 0 67 #define FP_EX_INVALID_ZDZ 0 68 #endif 68 #endif 69 /* inf * 0 */ 69 /* inf * 0 */ 70 #ifndef FP_EX_INVALID_IMZ 70 #ifndef FP_EX_INVALID_IMZ 71 #define FP_EX_INVALID_IMZ 0 71 #define FP_EX_INVALID_IMZ 0 72 #endif 72 #endif 73 #ifndef FP_EX_OVERFLOW 73 #ifndef FP_EX_OVERFLOW 74 #define FP_EX_OVERFLOW 0 74 #define FP_EX_OVERFLOW 0 75 #endif 75 #endif 76 #ifndef FP_EX_UNDERFLOW 76 #ifndef FP_EX_UNDERFLOW 77 #define FP_EX_UNDERFLOW 77 #define FP_EX_UNDERFLOW 78 #endif 78 #endif 79 #ifndef FP_EX_DIVZERO 79 #ifndef FP_EX_DIVZERO 80 #define FP_EX_DIVZERO 0 80 #define FP_EX_DIVZERO 0 81 #endif 81 #endif 82 #ifndef FP_EX_INEXACT 82 #ifndef FP_EX_INEXACT 83 #define FP_EX_INEXACT 0 83 #define FP_EX_INEXACT 0 84 #endif 84 #endif 85 #ifndef FP_EX_DENORM 85 #ifndef FP_EX_DENORM 86 #define FP_EX_DENORM 0 86 #define FP_EX_DENORM 0 87 #endif 87 #endif 88 88 89 #ifdef _FP_DECL_EX 89 #ifdef _FP_DECL_EX 90 #define FP_DECL_EX 90 #define FP_DECL_EX \ 91 int _fex = 0; 91 int _fex = 0; \ 92 _FP_DECL_EX 92 _FP_DECL_EX 93 #else 93 #else 94 #define FP_DECL_EX int _fex = 0 94 #define FP_DECL_EX int _fex = 0 95 #endif 95 #endif 96 96 97 #ifndef FP_INIT_ROUNDMODE 97 #ifndef FP_INIT_ROUNDMODE 98 #define FP_INIT_ROUNDMODE do {} while (0) 98 #define FP_INIT_ROUNDMODE do {} while (0) 99 #endif 99 #endif 100 100 101 #ifndef FP_HANDLE_EXCEPTIONS 101 #ifndef FP_HANDLE_EXCEPTIONS 102 #define FP_HANDLE_EXCEPTIONS do {} while (0) 102 #define FP_HANDLE_EXCEPTIONS do {} while (0) 103 #endif 103 #endif 104 104 105 /* By default we never flush denormal input op 105 /* By default we never flush denormal input operands to signed zero. */ 106 #ifndef FP_DENORM_ZERO 106 #ifndef FP_DENORM_ZERO 107 #define FP_DENORM_ZERO 0 107 #define FP_DENORM_ZERO 0 108 #endif 108 #endif 109 109 110 #ifndef FP_INHIBIT_RESULTS 110 #ifndef FP_INHIBIT_RESULTS 111 /* By default we write the results always. 111 /* By default we write the results always. 112 * sfp-machine may override this and e.g. 112 * sfp-machine may override this and e.g. 113 * check if some exceptions are unmasked 113 * check if some exceptions are unmasked 114 * and inhibit it in such a case. 114 * and inhibit it in such a case. 115 */ 115 */ 116 #define FP_INHIBIT_RESULTS 0 116 #define FP_INHIBIT_RESULTS 0 117 #endif 117 #endif 118 118 119 #ifndef FP_TRAPPING_EXCEPTIONS 119 #ifndef FP_TRAPPING_EXCEPTIONS 120 #define FP_TRAPPING_EXCEPTIONS 0 120 #define FP_TRAPPING_EXCEPTIONS 0 121 #endif 121 #endif 122 122 123 #define FP_SET_EXCEPTION(ex) 123 #define FP_SET_EXCEPTION(ex) \ 124 _fex |= (ex) 124 _fex |= (ex) 125 125 126 #define FP_UNSET_EXCEPTION(ex) 126 #define FP_UNSET_EXCEPTION(ex) \ 127 _fex &= ~(ex) 127 _fex &= ~(ex) 128 128 129 #define FP_CUR_EXCEPTIONS 129 #define FP_CUR_EXCEPTIONS \ 130 (_fex) 130 (_fex) 131 131 132 #define FP_CLEAR_EXCEPTIONS 132 #define FP_CLEAR_EXCEPTIONS \ 133 _fex = 0 133 _fex = 0 134 134 135 #define _FP_ROUND_NEAREST(wc, X) 135 #define _FP_ROUND_NEAREST(wc, X) \ 136 do { 136 do { \ 137 if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WOR 137 if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND) \ 138 _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); 138 _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); \ 139 } while (0) 139 } while (0) 140 140 141 #define _FP_ROUND_ZERO(wc, X) (void) 141 #define _FP_ROUND_ZERO(wc, X) (void)0 142 142 143 #define _FP_ROUND_PINF(wc, X) 143 #define _FP_ROUND_PINF(wc, X) \ 144 do { 144 do { \ 145 if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) 145 if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \ 146 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); 146 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \ 147 } while (0) 147 } while (0) 148 148 149 #define _FP_ROUND_MINF(wc, X) 149 #define _FP_ROUND_MINF(wc, X) \ 150 do { 150 do { \ 151 if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) 151 if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \ 152 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); 152 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \ 153 } while (0) 153 } while (0) 154 154 155 #define _FP_ROUND(wc, X) 155 #define _FP_ROUND(wc, X) \ 156 do { 156 do { \ 157 if (_FP_FRAC_LOW_##wc(X) & 7) 157 if (_FP_FRAC_LOW_##wc(X) & 7) \ 158 FP_SET_EXCEPTION(FP_EX_INEXACT); 158 FP_SET_EXCEPTION(FP_EX_INEXACT); \ 159 switch (FP_ROUNDMODE) 159 switch (FP_ROUNDMODE) \ 160 { 160 { \ 161 case FP_RND_NEAREST: 161 case FP_RND_NEAREST: \ 162 _FP_ROUND_NEAREST(wc,X); 162 _FP_ROUND_NEAREST(wc,X); \ 163 break; 163 break; \ 164 case FP_RND_ZERO: 164 case FP_RND_ZERO: \ 165 _FP_ROUND_ZERO(wc,X); 165 _FP_ROUND_ZERO(wc,X); \ 166 break; 166 break; \ 167 case FP_RND_PINF: 167 case FP_RND_PINF: \ 168 _FP_ROUND_PINF(wc,X); 168 _FP_ROUND_PINF(wc,X); \ 169 break; 169 break; \ 170 case FP_RND_MINF: 170 case FP_RND_MINF: \ 171 _FP_ROUND_MINF(wc,X); 171 _FP_ROUND_MINF(wc,X); \ 172 break; 172 break; \ 173 } 173 } \ 174 } while (0) 174 } while (0) 175 175 176 #define FP_CLS_NORMAL 0 176 #define FP_CLS_NORMAL 0 177 #define FP_CLS_ZERO 1 177 #define FP_CLS_ZERO 1 178 #define FP_CLS_INF 2 178 #define FP_CLS_INF 2 179 #define FP_CLS_NAN 3 179 #define FP_CLS_NAN 3 180 180 181 #define _FP_CLS_COMBINE(x,y) (((x) << 2) | 181 #define _FP_CLS_COMBINE(x,y) (((x) << 2) | (y)) 182 182 183 #include <math-emu/op-1.h> 183 #include <math-emu/op-1.h> 184 #include <math-emu/op-2.h> 184 #include <math-emu/op-2.h> 185 #include <math-emu/op-4.h> 185 #include <math-emu/op-4.h> 186 #include <math-emu/op-8.h> 186 #include <math-emu/op-8.h> 187 #include <math-emu/op-common.h> 187 #include <math-emu/op-common.h> 188 188 189 /* Sigh. Silly things longlong.h needs. */ 189 /* Sigh. Silly things longlong.h needs. */ 190 #define UWtype _FP_W_TYPE 190 #define UWtype _FP_W_TYPE 191 #define W_TYPE_SIZE _FP_W_TYPE_SIZE 191 #define W_TYPE_SIZE _FP_W_TYPE_SIZE 192 192 193 typedef int SItype __attribute__((mode(SI))); 193 typedef int SItype __attribute__((mode(SI))); 194 typedef int DItype __attribute__((mode(DI))); 194 typedef int DItype __attribute__((mode(DI))); 195 typedef unsigned int USItype __attribute__((mo 195 typedef unsigned int USItype __attribute__((mode(SI))); 196 typedef unsigned int UDItype __attribute__((mo 196 typedef unsigned int UDItype __attribute__((mode(DI))); 197 #if _FP_W_TYPE_SIZE == 32 197 #if _FP_W_TYPE_SIZE == 32 198 typedef unsigned int UHWtype __attribute__((mo 198 typedef unsigned int UHWtype __attribute__((mode(HI))); 199 #elif _FP_W_TYPE_SIZE == 64 199 #elif _FP_W_TYPE_SIZE == 64 200 typedef USItype UHWtype; 200 typedef USItype UHWtype; 201 #endif 201 #endif 202 202 203 #ifndef umul_ppmm 203 #ifndef umul_ppmm 204 #include <stdlib/longlong.h> 204 #include <stdlib/longlong.h> 205 #endif 205 #endif 206 206 207 #endif /* __MATH_EMU_SOFT_FP_H__ */ 207 #endif /* __MATH_EMU_SOFT_FP_H__ */ 208 208
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.