fp-bit.h

00001 /* Header file for fp-bit.c.  */
00002 /* Copyright (C) 2000, 2002, 2003, 2006 Free Software Foundation, Inc.
00003 
00004 This file is part of GCC.
00005 
00006 GCC is free software; you can redistribute it and/or modify it under
00007 the terms of the GNU General Public License as published by the Free
00008 Software Foundation; either version 2, or (at your option) any later
00009 version.
00010 
00011 In addition to the permissions in the GNU General Public License, the
00012 Free Software Foundation gives you unlimited permission to link the
00013 compiled version of this file into combinations with other programs,
00014 and to distribute those combinations without any restriction coming
00015 from the use of this file.  (The General Public License restrictions
00016 do apply in other respects; for example, they cover modification of
00017 the file, and distribution when not linked into a combine
00018 executable.)
00019 
00020 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
00021 WARRANTY; without even the implied warranty of MERCHANTABILITY or
00022 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00023 for more details.
00024 
00025 You should have received a copy of the GNU General Public License
00026 along with GCC; see the file COPYING.  If not, write to the Free
00027 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
00028 02110-1301, USA.  */
00029 
00030 #ifndef GCC_FP_BIT_H
00031 #define GCC_FP_BIT_H
00032 
00033 /* Defining FINE_GRAINED_LIBRARIES allows one to select which routines
00034    from this file are compiled via additional -D options.
00035 
00036    This avoids the need to pull in the entire fp emulation library
00037    when only a small number of functions are needed.
00038 
00039    If FINE_GRAINED_LIBRARIES is not defined, then compile every
00040    suitable routine.  */
00041 #ifndef FINE_GRAINED_LIBRARIES
00042 #define L_pack_df
00043 #define L_unpack_df
00044 #define L_pack_sf
00045 #define L_unpack_sf
00046 #define L_addsub_sf
00047 #define L_addsub_df
00048 #define L_mul_sf
00049 #define L_mul_df
00050 #define L_div_sf
00051 #define L_div_df
00052 #define L_fpcmp_parts_sf
00053 #define L_fpcmp_parts_df
00054 #define L_compare_sf
00055 #define L_compare_df
00056 #define L_eq_sf
00057 #define L_eq_df
00058 #define L_ne_sf
00059 #define L_ne_df
00060 #define L_gt_sf
00061 #define L_gt_df
00062 #define L_ge_sf
00063 #define L_ge_df
00064 #define L_lt_sf
00065 #define L_lt_df
00066 #define L_le_sf
00067 #define L_le_df
00068 #define L_unord_sf
00069 #define L_unord_df
00070 #define L_usi_to_sf
00071 #define L_usi_to_df
00072 #define L_si_to_sf
00073 #define L_si_to_df
00074 #define L_sf_to_si
00075 #define L_df_to_si
00076 #define L_f_to_usi
00077 #define L_df_to_usi
00078 #define L_negate_sf
00079 #define L_negate_df
00080 #define L_make_sf
00081 #define L_make_df
00082 #define L_sf_to_df
00083 #define L_df_to_sf
00084 #ifdef FLOAT
00085 #define L_thenan_sf
00086 #else
00087 #define L_thenan_df
00088 #endif
00089 #endif /* ! FINE_GRAINED_LIBRARIES */
00090 
00091 #if __LDBL_MANT_DIG__ == 113 || __LDBL_MANT_DIG__ == 106
00092 # if defined(TFLOAT) || defined(L_sf_to_tf) || defined(L_df_to_tf)
00093 #  define TMODES
00094 # endif
00095 #endif
00096 
00097 typedef float SFtype __attribute__ ((mode (SF)));
00098 typedef float DFtype __attribute__ ((mode (DF)));
00099 #ifdef TMODES
00100 typedef float TFtype __attribute__ ((mode (TF)));
00101 #endif
00102 
00103 typedef int HItype __attribute__ ((mode (HI)));
00104 typedef int SItype __attribute__ ((mode (SI)));
00105 typedef int DItype __attribute__ ((mode (DI)));
00106 #ifdef TMODES
00107 typedef int TItype __attribute__ ((mode (TI)));
00108 #endif
00109 
00110 /* The type of the result of a floating point comparison.  This must
00111    match `word_mode' in GCC for the target.  */
00112 #ifndef CMPtype
00113 typedef int CMPtype __attribute__ ((mode (word)));
00114 #endif
00115 
00116 typedef unsigned int UHItype __attribute__ ((mode (HI)));
00117 typedef unsigned int USItype __attribute__ ((mode (SI)));
00118 typedef unsigned int UDItype __attribute__ ((mode (DI)));
00119 #ifdef TMODES
00120 typedef unsigned int UTItype __attribute__ ((mode (TI)));
00121 #endif
00122 
00123 #define MAX_USI_INT  (~(USItype)0)
00124 #define MAX_SI_INT   ((SItype) (MAX_USI_INT >> 1))
00125 #define BITS_PER_SI  (4 * BITS_PER_UNIT)
00126 #ifdef TMODES
00127 #define MAX_UDI_INT  (~(UDItype)0)
00128 #define MAX_DI_INT   ((DItype) (MAX_UDI_INT >> 1))
00129 #define BITS_PER_DI  (8 * BITS_PER_UNIT)
00130 #endif
00131 
00132 #ifdef FLOAT_ONLY
00133 #define NO_DI_MODE
00134 #endif
00135 
00136 #ifdef TFLOAT
00137 # ifndef TMODES
00138 #  error "TFLOAT requires long double to have 113 bits of mantissa"
00139 # endif
00140 
00141 #       define PREFIXFPDP tp
00142 #       define PREFIXSFDF tf
00143 #       define NGARDS 10L /* Is this right? */
00144 #       define GARDROUND 0x1ff
00145 #       define GARDMASK  0x3ff
00146 #       define GARDMSB   0x200
00147 #       define FRAC_NBITS 128
00148 
00149 # if __LDBL_MANT_DIG__ == 113 /* IEEE quad */
00150 #       define EXPBITS 15
00151 #       define EXPBIAS 16383
00152 #       define EXPMAX (0x7fff)
00153 #       define QUIET_NAN ((TItype)0x8 << 108)
00154 #       define FRACHIGH  ((TItype)0x8 << 124)
00155 #       define FRACHIGH2 ((TItype)0xc << 124)
00156 #       define FRACBITS 112
00157 # endif
00158 
00159 # if __LDBL_MANT_DIG__ == 106 /* IBM extended (double+double) */
00160 #       define EXPBITS 11
00161 #       define EXPBIAS 1023
00162 #       define EXPMAX (0x7ff)
00163 #       define QUIET_NAN ((TItype)0x8 << (48 + 64))
00164 #       define FRACHIGH  ((TItype)0x8 << 124)
00165 #       define FRACHIGH2 ((TItype)0xc << 124)
00166 #       define FRACBITS 105
00167 #       define HALFFRACBITS 52
00168 #       define HALFSHIFT 64
00169 # endif
00170 
00171 #       define pack_d __pack_t
00172 #       define unpack_d __unpack_t
00173 #       define __fpcmp_parts __fpcmp_parts_t
00174         typedef UTItype fractype;
00175         typedef UDItype halffractype;
00176         typedef USItype qrtrfractype;
00177 #define qrtrfractype qrtrfractype
00178         typedef TFtype FLO_type;
00179         typedef TItype intfrac;
00180 #elif defined FLOAT
00181 #       define NGARDS    7L
00182 #       define GARDROUND 0x3f
00183 #       define GARDMASK  0x7f
00184 #       define GARDMSB   0x40
00185 #       define EXPBITS 8
00186 #       define EXPBIAS 127
00187 #       define FRACBITS 23
00188 #       define EXPMAX (0xff)
00189 #       define QUIET_NAN 0x100000L
00190 #       define FRAC_NBITS 32
00191 #       define FRACHIGH  0x80000000L
00192 #       define FRACHIGH2 0xc0000000L
00193 #       define pack_d __pack_f
00194 #       define unpack_d __unpack_f
00195 #       define __fpcmp_parts __fpcmp_parts_f
00196         typedef USItype fractype;
00197         typedef UHItype halffractype;
00198         typedef SFtype FLO_type;
00199         typedef SItype intfrac;
00200 
00201 #else
00202 #       define PREFIXFPDP dp
00203 #       define PREFIXSFDF df
00204 #       define NGARDS 8L
00205 #       define GARDROUND 0x7f
00206 #       define GARDMASK  0xff
00207 #       define GARDMSB   0x80
00208 #       define EXPBITS 11
00209 #       define EXPBIAS 1023
00210 #       define FRACBITS 52
00211 #       define EXPMAX (0x7ff)
00212 #       define QUIET_NAN 0x8000000000000LL
00213 #       define FRAC_NBITS 64
00214 #       define FRACHIGH  0x8000000000000000LL
00215 #       define FRACHIGH2 0xc000000000000000LL
00216 #       define pack_d __pack_d
00217 #       define unpack_d __unpack_d
00218 #       define __fpcmp_parts __fpcmp_parts_d
00219         typedef UDItype fractype;
00220         typedef USItype halffractype;
00221         typedef DFtype FLO_type;
00222         typedef DItype intfrac;
00223 #endif /* FLOAT */
00224 
00225 #ifdef US_SOFTWARE_GOFAST
00226 #       ifdef TFLOAT
00227 #               error "GOFAST TFmode not supported"
00228 #       elif defined FLOAT
00229 #               define add              fpadd
00230 #               define sub              fpsub
00231 #               define multiply         fpmul
00232 #               define divide           fpdiv
00233 #               define compare          fpcmp
00234 #               define _unord_f2        __unordsf2
00235 #               define usi_to_float     __floatunsisf
00236 #               define si_to_float      sitofp
00237 #               define float_to_si      fptosi
00238 #               define float_to_usi     fptoui
00239 #               define negate           __negsf2
00240 #               define sf_to_df         fptodp
00241 #               define sf_to_tf         __extendsftf2
00242 #       else
00243 #               define add              dpadd
00244 #               define sub              dpsub
00245 #               define multiply         dpmul
00246 #               define divide           dpdiv
00247 #               define compare          dpcmp
00248 #               define _unord_f2        __unorddf2
00249 #               define usi_to_float     __floatunsidf
00250 #               define si_to_float      litodp
00251 #               define float_to_si      dptoli
00252 #               define float_to_usi     dptoul
00253 #               define negate           __negdf2
00254 #               define df_to_sf         dptofp
00255 #               define df_to_tf         __extenddftf2
00256 #       endif /* FLOAT */
00257 #else
00258 #       ifdef TFLOAT
00259 #               define add              __addtf3
00260 #               define sub              __subtf3
00261 #               define multiply         __multf3
00262 #               define divide           __divtf3
00263 #               define compare          __cmptf2
00264 #               define _eq_f2           __eqtf2
00265 #               define _ne_f2           __netf2
00266 #               define _gt_f2           __gttf2
00267 #               define _ge_f2           __getf2
00268 #               define _lt_f2           __lttf2
00269 #               define _le_f2           __letf2
00270 #               define _unord_f2        __unordtf2
00271 #               define usi_to_float     __floatunsitf
00272 #               define si_to_float      __floatsitf
00273 #               define float_to_si      __fixtfsi
00274 #               define float_to_usi     __fixunstfsi
00275 #               define negate           __negtf2
00276 #               define tf_to_sf         __trunctfsf2
00277 #               define tf_to_df         __trunctfdf2
00278 #       elif defined FLOAT
00279 #               define add              g__addsf3
00280 #               define sub              g__subsf3
00281 #               define multiply         g__mulsf3
00282 #               define divide           g__divsf3
00283 #               define compare          g__cmpsf2
00284 #               define _eq_f2           g__eqsf2
00285 #               define _ne_f2           g__nesf2
00286 #               define _gt_f2           g__gtsf2
00287 #               define _ge_f2           g__gesf2
00288 #               define _lt_f2           g__ltsf2
00289 #               define _le_f2           g__lesf2
00290 #               define _unord_f2        __unordsf2
00291 #               define usi_to_float     __floatunsisf
00292 #               define si_to_float      g__floatsisf
00293 #               define float_to_si      g__fixsfsi
00294 #               define float_to_usi     __fixunssfsi
00295 #               define negate           g__negsf2
00296 #               define sf_to_df         __extendsfdf2
00297 #               define sf_to_tf         __extendsftf2
00298 #       else
00299 #               define add              __adddf3
00300 #               define sub              __subdf3
00301 #               define multiply         __muldf3
00302 #               define divide           __divdf3
00303 #               define compare          __cmpdf2
00304 #               define _eq_f2           __eqdf2
00305 #               define _ne_f2           __nedf2
00306 #               define _gt_f2           __gtdf2
00307 #               define _ge_f2           __gedf2
00308 #               define _lt_f2           __ltdf2
00309 #               define _le_f2           __ledf2
00310 #               define _unord_f2        __unorddf2
00311 #               define usi_to_float     __floatunsidf
00312 #               define si_to_float      __floatsidf
00313 #               define float_to_si      __fixdfsi
00314 #               define float_to_usi     __fixunsdfsi
00315 #               define negate           __negdf2
00316 #               define df_to_sf         __truncdfsf2
00317 #               define df_to_tf         __extenddftf2
00318 #       endif /* FLOAT */
00319 #endif /* US_SOFTWARE_GOFAST */
00320 
00321 #ifndef INLINE
00322 #define INLINE __inline__
00323 #endif
00324 
00325 /* Preserve the sticky-bit when shifting fractions to the right.  */
00326 #define LSHIFT(a, s) { a = (a >> s) | !!(a & (((fractype) 1 << s) - 1)); }
00327 
00328 /* numeric parameters */
00329 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
00330    of a float and of a double. Assumes there are only two float types.
00331    (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
00332  */
00333 #define F_D_BITOFF (52+8-(23+7))
00334 
00335 #ifdef TMODES
00336 # define F_T_BITOFF (__LDBL_MANT_DIG__-1+10-(23+7))
00337 # define D_T_BITOFF (__LDBL_MANT_DIG__-1+10-(52+8))
00338 #endif
00339 
00340 
00341 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
00342 #define IMPLICIT_1 ((fractype)1<<(FRACBITS+NGARDS))
00343 #define IMPLICIT_2 ((fractype)1<<(FRACBITS+1+NGARDS))
00344 
00345 /* common types */
00346 
00347 typedef enum
00348 {
00349   CLASS_SNAN,
00350   CLASS_QNAN,
00351   CLASS_ZERO,
00352   CLASS_NUMBER,
00353   CLASS_INFINITY
00354 } fp_class_type;
00355 
00356 typedef struct
00357 {
00358 #ifdef SMALL_MACHINE
00359   char class;
00360   unsigned char sign;
00361   short normal_exp;
00362 #else
00363   fp_class_type class;
00364   unsigned int sign;
00365   int normal_exp;
00366 #endif
00367 
00368   union
00369     {
00370       fractype ll;
00371       halffractype l[2];
00372     } fraction;
00373 } fp_number_type;
00374 
00375 typedef union
00376 {
00377   FLO_type value;
00378   fractype value_raw;
00379 
00380 #ifndef FLOAT
00381 # ifdef qrtrfractype
00382   qrtrfractype qwords[4];
00383 # else
00384   halffractype words[2];
00385 # endif
00386 #endif
00387 
00388 #ifdef FLOAT_BIT_ORDER_MISMATCH
00389   struct
00390     {
00391       fractype fraction:FRACBITS __attribute__ ((packed));
00392       unsigned int exp:EXPBITS __attribute__ ((packed));
00393       unsigned int sign:1 __attribute__ ((packed));
00394     }
00395   bits;
00396 #endif
00397 
00398 #ifdef _DEBUG_BITFLOAT
00399   struct
00400     {
00401       unsigned int sign:1 __attribute__ ((packed));
00402       unsigned int exp:EXPBITS __attribute__ ((packed));
00403       fractype fraction:FRACBITS __attribute__ ((packed));
00404     }
00405   bits_big_endian;
00406 
00407   struct
00408     {
00409       fractype fraction:FRACBITS __attribute__ ((packed));
00410       unsigned int exp:EXPBITS __attribute__ ((packed));
00411       unsigned int sign:1 __attribute__ ((packed));
00412     }
00413   bits_little_endian;
00414 #endif
00415 }
00416 FLO_union_type;
00417 
00418 /* Prototypes */
00419 
00420 #if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
00421 extern FLO_type pack_d (fp_number_type *);
00422 #endif
00423 
00424 extern void unpack_d (FLO_union_type *, fp_number_type *);
00425 
00426 #if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
00427 extern FLO_type add (FLO_type, FLO_type);
00428 extern FLO_type sub (FLO_type, FLO_type);
00429 #endif
00430 
00431 #if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
00432 extern FLO_type multiply (FLO_type, FLO_type);
00433 #endif
00434 
00435 #if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
00436 extern FLO_type divide (FLO_type, FLO_type);
00437 #endif
00438 
00439 extern int __fpcmp_parts (fp_number_type *, fp_number_type *);
00440 
00441 #if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compare_tf)
00442 extern CMPtype compare (FLO_type, FLO_type);
00443 #endif
00444 
00445 #ifndef US_SOFTWARE_GOFAST
00446 
00447 #if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
00448 extern CMPtype _eq_f2 (FLO_type, FLO_type);
00449 #endif
00450 
00451 #if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
00452 extern CMPtype _ne_f2 (FLO_type, FLO_type);
00453 #endif
00454 
00455 #if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
00456 extern CMPtype _gt_f2 (FLO_type, FLO_type);
00457 #endif
00458 
00459 #if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
00460 extern CMPtype _ge_f2 (FLO_type, FLO_type);
00461 #endif
00462 
00463 #if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
00464 extern CMPtype _lt_f2 (FLO_type, FLO_type);
00465 #endif
00466 
00467 #if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
00468 extern CMPtype _le_f2 (FLO_type, FLO_type);
00469 #endif
00470 
00471 #if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
00472 extern CMPtype _unord_f2 (FLO_type, FLO_type);
00473 #endif
00474 
00475 #endif /* ! US_SOFTWARE_GOFAST */
00476 
00477 #if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
00478 extern FLO_type si_to_float (SItype);
00479 #endif
00480 
00481 #if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
00482 extern SItype float_to_si (FLO_type);
00483 #endif
00484 
00485 #if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
00486 #if defined(US_SOFTWARE_GOFAST) || defined(L_tf_to_usi)
00487 extern USItype float_to_usi (FLO_type);
00488 #endif
00489 #endif
00490 
00491 #if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
00492 extern FLO_type usi_to_float (USItype);
00493 #endif
00494 
00495 #if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
00496 extern FLO_type negate (FLO_type);
00497 #endif
00498 
00499 #ifdef FLOAT
00500 #if defined(L_make_sf)
00501 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
00502 #endif
00503 #ifndef FLOAT_ONLY
00504 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
00505 #if defined(L_sf_to_df)
00506 extern DFtype sf_to_df (SFtype);
00507 #endif
00508 #if defined(L_sf_to_tf) && defined(TMODES)
00509 extern TFtype sf_to_tf (SFtype);
00510 #endif
00511 #endif /* ! FLOAT_ONLY */
00512 #endif /* FLOAT */
00513 
00514 #ifndef FLOAT
00515 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
00516 #if defined(L_make_df)
00517 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
00518 #endif
00519 #if defined(L_df_to_sf)
00520 extern SFtype df_to_sf (DFtype);
00521 #endif
00522 #if defined(L_df_to_tf) && defined(TMODES)
00523 extern TFtype df_to_tf (DFtype);
00524 #endif
00525 #endif /* ! FLOAT */
00526 
00527 #ifdef TMODES
00528 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
00529 extern TFtype __make_tp (fp_class_type, unsigned int, int, UTItype);
00530 #ifdef TFLOAT
00531 #if defined(L_tf_to_sf)
00532 extern SFtype tf_to_sf (TFtype);
00533 #endif
00534 #if defined(L_tf_to_df)
00535 extern DFtype tf_to_df (TFtype);
00536 #endif
00537 #if defined(L_di_to_tf)
00538 extern TFtype di_to_df (DItype);
00539 #endif
00540 #endif /* TFLOAT */
00541 #endif /* TMODES */
00542 
00543 #endif /* ! GCC_FP_BIT_H */

Generated on Tue Oct 7 20:25:46 2008 for spandsp by  doxygen 1.5.6