1 /* Software floating-point emulation. 2 Copyright (C) 1997,1998,1999,2000,2002,2003,2005,2006,2007 3 Free Software Foundation, Inc. 4 This file is part of the GNU C Library. 5 Contributed by Richard Henderson (rth@cygnus.com), 6 Jakub Jelinek (jj@ultra.linux.cz), 7 David S. Miller (davem@redhat.com) and 8 Peter Maydell (pmaydell@chiark.greenend.org.uk). 9 10 The GNU C Library is free software; you can redistribute it and/or 11 modify it under the terms of the GNU Lesser General Public 12 License as published by the Free Software Foundation; either 13 version 2.1 of the License, or (at your option) any later version. 14 15 In addition to the permissions in the GNU Lesser General Public 16 License, the Free Software Foundation gives you unlimited 17 permission to link the compiled version of this file into 18 combinations with other programs, and to distribute those 19 combinations without any restriction coming from the use of this 20 file. (The Lesser General Public License restrictions do apply in 21 other respects; for example, they cover modification of the file, 22 and distribution when not linked into a combine executable.) 23 24 The GNU C Library is distributed in the hope that it will be useful, 25 but WITHOUT ANY WARRANTY; without even the implied warranty of 26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 Lesser General Public License for more details. 28 29 You should have received a copy of the GNU Lesser General Public 30 License along with the GNU C Library; if not, see 31 <http://www.gnu.org/licenses/>. */ 32 33 #ifndef SOFT_FP_H 34 #define SOFT_FP_H 35 36 #include "sfp-machine.h" 37 38 /* Allow sfp-machine to have its own byte order definitions. */ 39 #ifndef __BYTE_ORDER 40 #ifdef _LIBC 41 #include <endian.h> 42 #else 43 #error "endianness not defined by sfp-machine.h" 44 #endif 45 #endif 46 47 #define _FP_WORKBITS 3 48 #define _FP_WORK_LSB ((_FP_W_TYPE)1 << 3) 49 #define _FP_WORK_ROUND ((_FP_W_TYPE)1 << 2) 50 #define _FP_WORK_GUARD ((_FP_W_TYPE)1 << 1) 51 #define _FP_WORK_STICKY ((_FP_W_TYPE)1 << 0) 52 53 #ifndef FP_RND_NEAREST 54 # define FP_RND_NEAREST 0 55 # define FP_RND_ZERO 1 56 # define FP_RND_PINF 2 57 # define FP_RND_MINF 3 58 #endif 59 #ifndef FP_ROUNDMODE 60 # define FP_ROUNDMODE FP_RND_NEAREST 61 #endif 62 63 /* By default don't care about exceptions. */ 64 #ifndef FP_EX_INVALID 65 #define FP_EX_INVALID 0 66 #endif 67 #ifndef FP_EX_OVERFLOW 68 #define FP_EX_OVERFLOW 0 69 #endif 70 #ifndef FP_EX_UNDERFLOW 71 #define FP_EX_UNDERFLOW 0 72 #endif 73 #ifndef FP_EX_DIVZERO 74 #define FP_EX_DIVZERO 0 75 #endif 76 #ifndef FP_EX_INEXACT 77 #define FP_EX_INEXACT 0 78 #endif 79 #ifndef FP_EX_DENORM 80 #define FP_EX_DENORM 0 81 #endif 82 83 #ifdef _FP_DECL_EX 84 #define FP_DECL_EX \ 85 int _fex = 0; \ 86 _FP_DECL_EX 87 #else 88 #define FP_DECL_EX int _fex = 0 89 #endif 90 91 #ifndef FP_INIT_ROUNDMODE 92 #define FP_INIT_ROUNDMODE do {} while (0) 93 #endif 94 95 #ifndef FP_HANDLE_EXCEPTIONS 96 #define FP_HANDLE_EXCEPTIONS do {} while (0) 97 #endif 98 99 #ifndef FP_INHIBIT_RESULTS 100 /* By default we write the results always. 101 * sfp-machine may override this and e.g. 102 * check if some exceptions are unmasked 103 * and inhibit it in such a case. 104 */ 105 #define FP_INHIBIT_RESULTS 0 106 #endif 107 108 #define FP_SET_EXCEPTION(ex) \ 109 _fex |= (ex) 110 111 #define FP_UNSET_EXCEPTION(ex) \ 112 _fex &= ~(ex) 113 114 #define FP_CLEAR_EXCEPTIONS \ 115 _fex = 0 116 117 #define _FP_ROUND_NEAREST(wc, X) \ 118 do { \ 119 if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND) \ 120 _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); \ 121 } while (0) 122 123 #define _FP_ROUND_ZERO(wc, X) (void)0 124 125 #define _FP_ROUND_PINF(wc, X) \ 126 do { \ 127 if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \ 128 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \ 129 } while (0) 130 131 #define _FP_ROUND_MINF(wc, X) \ 132 do { \ 133 if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \ 134 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \ 135 } while (0) 136 137 #define _FP_ROUND(wc, X) \ 138 do { \ 139 if (_FP_FRAC_LOW_##wc(X) & 7) \ 140 FP_SET_EXCEPTION(FP_EX_INEXACT); \ 141 switch (FP_ROUNDMODE) \ 142 { \ 143 case FP_RND_NEAREST: \ 144 _FP_ROUND_NEAREST(wc,X); \ 145 break; \ 146 case FP_RND_ZERO: \ 147 _FP_ROUND_ZERO(wc,X); \ 148 break; \ 149 case FP_RND_PINF: \ 150 _FP_ROUND_PINF(wc,X); \ 151 break; \ 152 case FP_RND_MINF: \ 153 _FP_ROUND_MINF(wc,X); \ 154 break; \ 155 } \ 156 } while (0) 157 158 #define FP_CLS_NORMAL 0 159 #define FP_CLS_ZERO 1 160 #define FP_CLS_INF 2 161 #define FP_CLS_NAN 3 162 163 #define _FP_CLS_COMBINE(x,y) (((x) << 2) | (y)) 164 165 #include "op-1.h" 166 #include "op-2.h" 167 #include "op-4.h" 168 #include "op-8.h" 169 #include "op-common.h" 170 171 /* Sigh. Silly things longlong.h needs. */ 172 #define UWtype _FP_W_TYPE 173 #define W_TYPE_SIZE _FP_W_TYPE_SIZE 174 175 typedef int QItype __attribute__((mode(QI))); 176 typedef int SItype __attribute__((mode(SI))); 177 typedef int DItype __attribute__((mode(DI))); 178 typedef unsigned int UQItype __attribute__((mode(QI))); 179 typedef unsigned int USItype __attribute__((mode(SI))); 180 typedef unsigned int UDItype __attribute__((mode(DI))); 181 #if _FP_W_TYPE_SIZE == 32 182 typedef unsigned int UHWtype __attribute__((mode(HI))); 183 #elif _FP_W_TYPE_SIZE == 64 184 typedef USItype UHWtype; 185 #endif 186 187 #ifndef CMPtype 188 #define CMPtype int 189 #endif 190 191 #define SI_BITS (__CHAR_BIT__ * (int)sizeof(SItype)) 192 #define DI_BITS (__CHAR_BIT__ * (int)sizeof(DItype)) 193 194 #ifndef umul_ppmm 195 #include "longlong.h" 196 #endif 197 198 #ifdef _LIBC 199 #include <stdlib.h> 200 #else 201 extern void abort (void); 202 #endif 203 204 #endif 205