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