Home | History | Annotate | Line # | Download | only in soft-fp
soft-fp.h revision 1.1.1.1
      1 /* Software floating-point emulation.
      2    Copyright (C) 1997,1998,1999,2000,2002,2003,2005,2006,2007,2012
      3 	Free Software Foundation, Inc.
      4    This file is part of the GNU C Library.
      5    Contributed by Richard Henderson (rth (at) cygnus.com),
      6 		  Jakub Jelinek (jj (at) ultra.linux.cz),
      7 		  David S. Miller (davem (at) redhat.com) and
      8 		  Peter Maydell (pmaydell (at) 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 #ifdef _LIBC
     37 #include <sfp-machine.h>
     38 #else
     39 #include "sfp-machine.h"
     40 #endif
     41 
     42 /* Allow sfp-machine to have its own byte order definitions. */
     43 #ifndef __BYTE_ORDER
     44 #ifdef _LIBC
     45 #include <endian.h>
     46 #else
     47 #error "endianness not defined by sfp-machine.h"
     48 #endif
     49 #endif
     50 
     51 #define _FP_WORKBITS		3
     52 #define _FP_WORK_LSB		((_FP_W_TYPE)1 << 3)
     53 #define _FP_WORK_ROUND		((_FP_W_TYPE)1 << 2)
     54 #define _FP_WORK_GUARD		((_FP_W_TYPE)1 << 1)
     55 #define _FP_WORK_STICKY		((_FP_W_TYPE)1 << 0)
     56 
     57 #ifndef FP_RND_NEAREST
     58 # define FP_RND_NEAREST		0
     59 # define FP_RND_ZERO		1
     60 # define FP_RND_PINF		2
     61 # define FP_RND_MINF		3
     62 #endif
     63 #ifndef FP_ROUNDMODE
     64 # define FP_ROUNDMODE		FP_RND_NEAREST
     65 #endif
     66 
     67 /* By default don't care about exceptions. */
     68 #ifndef FP_EX_INVALID
     69 #define FP_EX_INVALID		0
     70 #endif
     71 #ifndef FP_EX_OVERFLOW
     72 #define FP_EX_OVERFLOW		0
     73 #endif
     74 #ifndef FP_EX_UNDERFLOW
     75 #define FP_EX_UNDERFLOW		0
     76 #endif
     77 #ifndef FP_EX_DIVZERO
     78 #define FP_EX_DIVZERO		0
     79 #endif
     80 #ifndef FP_EX_INEXACT
     81 #define FP_EX_INEXACT		0
     82 #endif
     83 #ifndef FP_EX_DENORM
     84 #define FP_EX_DENORM		0
     85 #endif
     86 
     87 /* _FP_STRUCT_LAYOUT may be defined as an attribute to determine the
     88    struct layout variant used for structures where bit-fields are used
     89    to access specific parts of binary floating-point numbers.  This is
     90    required for systems where the default ABI uses struct layout with
     91    differences in how consecutive bit-fields are laid out from the
     92    default expected by soft-fp.  */
     93 #ifndef _FP_STRUCT_LAYOUT
     94 #define _FP_STRUCT_LAYOUT
     95 #endif
     96 
     97 #ifdef _FP_DECL_EX
     98 #define FP_DECL_EX					\
     99   int _fex = 0;						\
    100   _FP_DECL_EX
    101 #else
    102 #define FP_DECL_EX int _fex = 0
    103 #endif
    104 
    105 #ifndef FP_INIT_ROUNDMODE
    106 #define FP_INIT_ROUNDMODE do {} while (0)
    107 #endif
    108 
    109 #ifndef FP_HANDLE_EXCEPTIONS
    110 #define FP_HANDLE_EXCEPTIONS do {} while (0)
    111 #endif
    112 
    113 #ifndef FP_INHIBIT_RESULTS
    114 /* By default we write the results always.
    115  * sfp-machine may override this and e.g.
    116  * check if some exceptions are unmasked
    117  * and inhibit it in such a case.
    118  */
    119 #define FP_INHIBIT_RESULTS 0
    120 #endif
    121 
    122 #define FP_SET_EXCEPTION(ex)				\
    123   _fex |= (ex)
    124 
    125 #define FP_UNSET_EXCEPTION(ex)				\
    126   _fex &= ~(ex)
    127 
    128 #define FP_CLEAR_EXCEPTIONS				\
    129   _fex = 0
    130 
    131 #define FP_CUR_EXCEPTIONS				\
    132   (_fex)
    133 
    134 #ifndef FP_TRAPPING_EXCEPTIONS
    135 #define FP_TRAPPING_EXCEPTIONS 0
    136 #endif
    137 
    138 #define _FP_ROUND_NEAREST(wc, X)			\
    139 do {							\
    140     if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND)	\
    141       _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND);		\
    142 } while (0)
    143 
    144 #define _FP_ROUND_ZERO(wc, X)		(void)0
    145 
    146 #define _FP_ROUND_PINF(wc, X)				\
    147 do {							\
    148     if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7))		\
    149       _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB);		\
    150 } while (0)
    151 
    152 #define _FP_ROUND_MINF(wc, X)				\
    153 do {							\
    154     if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7))		\
    155       _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB);		\
    156 } while (0)
    157 
    158 #define _FP_ROUND(wc, X)			\
    159 do {						\
    160 	if (_FP_FRAC_LOW_##wc(X) & 7)		\
    161 	  {					\
    162 	    FP_SET_EXCEPTION(FP_EX_INEXACT);	\
    163 	    switch (FP_ROUNDMODE)		\
    164 	      {					\
    165 	      case FP_RND_NEAREST:		\
    166 		_FP_ROUND_NEAREST(wc,X);	\
    167 		break;				\
    168 	      case FP_RND_ZERO:			\
    169 		_FP_ROUND_ZERO(wc,X);		\
    170 		break;				\
    171 	      case FP_RND_PINF:			\
    172 		_FP_ROUND_PINF(wc,X);		\
    173 		break;				\
    174 	      case FP_RND_MINF:			\
    175 		_FP_ROUND_MINF(wc,X);		\
    176 		break;				\
    177 	      }					\
    178 	  }					\
    179 } while (0)
    180 
    181 #define FP_CLS_NORMAL		0
    182 #define FP_CLS_ZERO		1
    183 #define FP_CLS_INF		2
    184 #define FP_CLS_NAN		3
    185 
    186 #define _FP_CLS_COMBINE(x,y)	(((x) << 2) | (y))
    187 
    188 #include "op-1.h"
    189 #include "op-2.h"
    190 #include "op-4.h"
    191 #include "op-8.h"
    192 #include "op-common.h"
    193 
    194 /* Sigh.  Silly things longlong.h needs.  */
    195 #define UWtype		_FP_W_TYPE
    196 #define W_TYPE_SIZE	_FP_W_TYPE_SIZE
    197 
    198 typedef int QItype __attribute__((mode(QI)));
    199 typedef int SItype __attribute__((mode(SI)));
    200 typedef int DItype __attribute__((mode(DI)));
    201 typedef unsigned int UQItype __attribute__((mode(QI)));
    202 typedef unsigned int USItype __attribute__((mode(SI)));
    203 typedef unsigned int UDItype __attribute__((mode(DI)));
    204 #if _FP_W_TYPE_SIZE == 32
    205 typedef unsigned int UHWtype __attribute__((mode(HI)));
    206 #elif _FP_W_TYPE_SIZE == 64
    207 typedef USItype UHWtype;
    208 #endif
    209 
    210 #ifndef CMPtype
    211 #define CMPtype		int
    212 #endif
    213 
    214 #define SI_BITS		(__CHAR_BIT__ * (int)sizeof(SItype))
    215 #define DI_BITS		(__CHAR_BIT__ * (int)sizeof(DItype))
    216 
    217 #ifndef umul_ppmm
    218 #ifdef _LIBC
    219 #include <stdlib/longlong.h>
    220 #else
    221 #include "longlong.h"
    222 #endif
    223 #endif
    224 
    225 #ifdef _LIBC
    226 #include <stdlib.h>
    227 #else
    228 extern void abort (void);
    229 #endif
    230 
    231 #endif
    232