1/* Header file for fp-bit.c. */ 2/* Copyright (C) 2000-2015 Free Software Foundation, Inc. 3 4This file is part of GCC. 5 6GCC is free software; you can redistribute it and/or modify it under 7the terms of the GNU General Public License as published by the Free 8Software Foundation; either version 3, or (at your option) any later 9version. 10 11GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12WARRANTY; without even the implied warranty of MERCHANTABILITY or 13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14for more details. 15 16Under Section 7 of GPL version 3, you are granted additional 17permissions described in the GCC Runtime Library Exception, version 183.1, as published by the Free Software Foundation. 19 20You should have received a copy of the GNU General Public License and 21a copy of the GCC Runtime Library Exception along with this program; 22see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23<http://www.gnu.org/licenses/>. */ 24 25#ifndef GCC_FP_BIT_H 26#define GCC_FP_BIT_H 27 28/* Defining FINE_GRAINED_LIBRARIES allows one to select which routines 29 from this file are compiled via additional -D options. 30 31 This avoids the need to pull in the entire fp emulation library 32 when only a small number of functions are needed. 33 34 If FINE_GRAINED_LIBRARIES is not defined, then compile every 35 suitable routine. */ 36#ifndef FINE_GRAINED_LIBRARIES 37#define L_pack_df 38#define L_unpack_df 39#define L_pack_sf 40#define L_unpack_sf 41#define L_addsub_sf 42#define L_addsub_df 43#define L_mul_sf 44#define L_mul_df 45#define L_div_sf 46#define L_div_df 47#define L_fpcmp_parts_sf 48#define L_fpcmp_parts_df 49#define L_compare_sf 50#define L_compare_df 51#define L_eq_sf 52#define L_eq_df 53#define L_ne_sf 54#define L_ne_df 55#define L_gt_sf 56#define L_gt_df 57#define L_ge_sf 58#define L_ge_df 59#define L_lt_sf 60#define L_lt_df 61#define L_le_sf 62#define L_le_df 63#define L_unord_sf 64#define L_unord_df 65#define L_usi_to_sf 66#define L_usi_to_df 67#define L_si_to_sf 68#define L_si_to_df 69#define L_sf_to_si 70#define L_df_to_si 71#define L_f_to_usi 72#define L_df_to_usi 73#define L_negate_sf 74#define L_negate_df 75#define L_make_sf 76#define L_make_df 77#define L_sf_to_df 78#define L_df_to_sf 79#ifdef FLOAT 80#define L_thenan_sf 81#else 82#define L_thenan_df 83#endif 84#endif /* ! FINE_GRAINED_LIBRARIES */ 85 86#if __LDBL_MANT_DIG__ == 113 || __LDBL_MANT_DIG__ == 106 87# if defined(TFLOAT) || defined(L_sf_to_tf) || defined(L_df_to_tf) 88# define TMODES 89# endif 90#endif 91 92typedef float SFtype __attribute__ ((mode (SF))); 93typedef float DFtype __attribute__ ((mode (DF))); 94#ifdef TMODES 95typedef float TFtype __attribute__ ((mode (TF))); 96#endif 97 98typedef int HItype __attribute__ ((mode (HI))); 99typedef int SItype __attribute__ ((mode (SI))); 100typedef int DItype __attribute__ ((mode (DI))); 101#ifdef TMODES 102typedef int TItype __attribute__ ((mode (TI))); 103#endif 104 105/* The type of the result of a floating point comparison. This must 106 match `__libgcc_cmp_return__' in GCC for the target. */ 107#ifndef CMPtype 108typedef int CMPtype __attribute__ ((mode (__libgcc_cmp_return__))); 109#endif 110 111typedef unsigned int UHItype __attribute__ ((mode (HI))); 112typedef unsigned int USItype __attribute__ ((mode (SI))); 113typedef unsigned int UDItype __attribute__ ((mode (DI))); 114#ifdef TMODES 115typedef unsigned int UTItype __attribute__ ((mode (TI))); 116#endif 117 118#define MAX_USI_INT (~(USItype)0) 119#define MAX_SI_INT ((SItype) (MAX_USI_INT >> 1)) 120#define BITS_PER_SI (4 * BITS_PER_UNIT) 121#ifdef TMODES 122#define MAX_UDI_INT (~(UDItype)0) 123#define MAX_DI_INT ((DItype) (MAX_UDI_INT >> 1)) 124#define BITS_PER_DI (8 * BITS_PER_UNIT) 125#endif 126 127#ifdef FLOAT_ONLY 128#define NO_DI_MODE 129#endif 130 131#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 132#define FLOAT_BIT_ORDER_MISMATCH 133#endif 134 135#if __BYTE_ORDER__ != __FLOAT_WORD_ORDER__ 136#define FLOAT_WORD_ORDER_MISMATCH 137#endif 138 139#ifdef TFLOAT 140# ifndef TMODES 141# error "TFLOAT requires long double to have 113 bits of mantissa" 142# endif 143 144# define PREFIXFPDP tp 145# define PREFIXSFDF tf 146# define NGARDS 10L /* Is this right? */ 147# define GARDROUND 0x1ff 148# define GARDMASK 0x3ff 149# define GARDMSB 0x200 150# define FRAC_NBITS 128 151 152# if __LDBL_MANT_DIG__ == 113 /* IEEE quad */ 153# define EXPBITS 15 154# define EXPBIAS 16383 155# define EXPMAX (0x7fff) 156# define QUIET_NAN ((TItype)0x8 << 108) 157# define FRACHIGH ((TItype)0x8 << 124) 158# define FRACHIGH2 ((TItype)0xc << 124) 159# define FRACBITS 112 160# endif 161 162# if __LDBL_MANT_DIG__ == 106 /* IBM extended (double+double) */ 163# define EXPBITS 11 164# define EXPBIAS 1023 165# define EXPMAX (0x7ff) 166# define QUIET_NAN ((TItype)0x8 << (48 + 64)) 167# define FRACHIGH ((TItype)0x8 << 124) 168# define FRACHIGH2 ((TItype)0xc << 124) 169# define FRACBITS 105 170# define HALFFRACBITS 52 171# define HALFSHIFT 64 172# endif 173 174# define pack_d __pack_t 175# define unpack_d __unpack_t 176# define __fpcmp_parts __fpcmp_parts_t 177 typedef UTItype fractype; 178 typedef UDItype halffractype; 179 typedef USItype qrtrfractype; 180#define qrtrfractype qrtrfractype 181 typedef TFtype FLO_type; 182 typedef TItype intfrac; 183#elif defined FLOAT 184# define NGARDS 7L 185# define GARDROUND 0x3f 186# define GARDMASK 0x7f 187# define GARDMSB 0x40 188# define EXPBITS 8 189# define EXPBIAS 127 190# define FRACBITS 23 191# define EXPMAX (0xff) 192# define QUIET_NAN 0x400000L 193# define FRAC_NBITS 32 194# define FRACHIGH 0x80000000L 195# define FRACHIGH2 0xc0000000L 196# define pack_d __pack_f 197# define unpack_d __unpack_f 198# define __fpcmp_parts __fpcmp_parts_f 199 typedef USItype fractype; 200 typedef UHItype halffractype; 201 typedef SFtype FLO_type; 202 typedef SItype intfrac; 203 204#else 205# define PREFIXFPDP dp 206# define PREFIXSFDF df 207# define NGARDS 8L 208# define GARDROUND 0x7f 209# define GARDMASK 0xff 210# define GARDMSB 0x80 211# define EXPBITS 11 212# define EXPBIAS 1023 213# define FRACBITS 52 214# define EXPMAX (0x7ff) 215# define QUIET_NAN 0x8000000000000LL 216# define FRAC_NBITS 64 217# define FRACHIGH 0x8000000000000000LL 218# define FRACHIGH2 0xc000000000000000LL 219# define pack_d __pack_d 220# define unpack_d __unpack_d 221# define __fpcmp_parts __fpcmp_parts_d 222 typedef UDItype fractype; 223 typedef USItype halffractype; 224 typedef DFtype FLO_type; 225 typedef DItype intfrac; 226#endif /* FLOAT */ 227 228#ifdef TFLOAT 229# define add __addtf3 230# define sub __subtf3 231# define multiply __multf3 232# define divide __divtf3 233# define compare __cmptf2 234# define _eq_f2 __eqtf2 235# define _ne_f2 __netf2 236# define _gt_f2 __gttf2 237# define _ge_f2 __getf2 238# define _lt_f2 __lttf2 239# define _le_f2 __letf2 240# define _unord_f2 __unordtf2 241# define usi_to_float __floatunsitf 242# define si_to_float __floatsitf 243# define float_to_si __fixtfsi 244# define float_to_usi __fixunstfsi 245# define negate __negtf2 246# define tf_to_sf __trunctfsf2 247# define tf_to_df __trunctfdf2 248#elif defined FLOAT 249# define add __addsf3 250# define sub __subsf3 251# define multiply __mulsf3 252# define divide __divsf3 253# define compare __cmpsf2 254# define _eq_f2 __eqsf2 255# define _ne_f2 __nesf2 256# define _gt_f2 __gtsf2 257# define _ge_f2 __gesf2 258# define _lt_f2 __ltsf2 259# define _le_f2 __lesf2 260# define _unord_f2 __unordsf2 261# define usi_to_float __floatunsisf 262# define si_to_float __floatsisf 263# define float_to_si __fixsfsi 264# define float_to_usi __fixunssfsi 265# define negate __negsf2 266# define sf_to_df __extendsfdf2 267# define sf_to_tf __extendsftf2 268#else 269# define add __adddf3 270# define sub __subdf3 271# define multiply __muldf3 272# define divide __divdf3 273# define compare __cmpdf2 274# define _eq_f2 __eqdf2 275# define _ne_f2 __nedf2 276# define _gt_f2 __gtdf2 277# define _ge_f2 __gedf2 278# define _lt_f2 __ltdf2 279# define _le_f2 __ledf2 280# define _unord_f2 __unorddf2 281# define usi_to_float __floatunsidf 282# define si_to_float __floatsidf 283# define float_to_si __fixdfsi 284# define float_to_usi __fixunsdfsi 285# define negate __negdf2 286# define df_to_sf __truncdfsf2 287# define df_to_tf __extenddftf2 288#endif /* FLOAT */ 289 290#ifndef INLINE 291#define INLINE __inline__ 292#endif 293 294/* Preserve the sticky-bit when shifting fractions to the right. */ 295#define LSHIFT(a, s) { a = (a >> s) | !!(a & (((fractype) 1 << s) - 1)); } 296 297/* numeric parameters */ 298/* F_D_BITOFF is the number of bits offset between the MSB of the mantissa 299 of a float and of a double. Assumes there are only two float types. 300 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS+float::NGARDS)) 301 */ 302#define F_D_BITOFF (52+8-(23+7)) 303 304#ifdef TMODES 305# define F_T_BITOFF (__LDBL_MANT_DIG__-1+10-(23+7)) 306# define D_T_BITOFF (__LDBL_MANT_DIG__-1+10-(52+8)) 307#endif 308 309 310#define NORMAL_EXPMIN (-(EXPBIAS)+1) 311#define IMPLICIT_1 ((fractype)1<<(FRACBITS+NGARDS)) 312#define IMPLICIT_2 ((fractype)1<<(FRACBITS+1+NGARDS)) 313 314/* common types */ 315 316typedef enum 317{ 318 CLASS_SNAN, 319 CLASS_QNAN, 320 CLASS_ZERO, 321 CLASS_NUMBER, 322 CLASS_INFINITY 323} fp_class_type; 324 325typedef struct 326{ 327#ifdef SMALL_MACHINE 328 char class; 329 unsigned char sign; 330 short normal_exp; 331#else 332 fp_class_type class; 333 unsigned int sign; 334 int normal_exp; 335#endif 336 337 union 338 { 339 fractype ll; 340 halffractype l[2]; 341 } fraction; 342} fp_number_type; 343 344typedef union 345{ 346 FLO_type value; 347 fractype value_raw; 348 349#ifndef FLOAT 350# ifdef qrtrfractype 351 qrtrfractype qwords[4]; 352# else 353 halffractype words[2]; 354# endif 355#endif 356 357#ifdef FLOAT_BIT_ORDER_MISMATCH 358 struct 359 { 360 fractype fraction:FRACBITS __attribute__ ((packed)); 361 unsigned int exp:EXPBITS __attribute__ ((packed)); 362 unsigned int sign:1 __attribute__ ((packed)); 363 } 364 bits; 365#endif 366 367#ifdef _DEBUG_BITFLOAT 368 struct 369 { 370 unsigned int sign:1 __attribute__ ((packed)); 371 unsigned int exp:EXPBITS __attribute__ ((packed)); 372 fractype fraction:FRACBITS __attribute__ ((packed)); 373 } 374 bits_big_endian; 375 376 struct 377 { 378 fractype fraction:FRACBITS __attribute__ ((packed)); 379 unsigned int exp:EXPBITS __attribute__ ((packed)); 380 unsigned int sign:1 __attribute__ ((packed)); 381 } 382 bits_little_endian; 383#endif 384} 385FLO_union_type; 386 387/* Prototypes. */ 388 389#if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf) 390extern FLO_type pack_d (const fp_number_type *); 391#endif 392 393extern void unpack_d (FLO_union_type *, fp_number_type *); 394 395#if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf) 396extern FLO_type add (FLO_type, FLO_type); 397extern FLO_type sub (FLO_type, FLO_type); 398#endif 399 400#if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf) 401extern FLO_type multiply (FLO_type, FLO_type); 402#endif 403 404#if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf) 405extern FLO_type divide (FLO_type, FLO_type); 406#endif 407 408extern int __fpcmp_parts (fp_number_type *, fp_number_type *); 409 410#if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compare_tf) 411extern CMPtype compare (FLO_type, FLO_type); 412#endif 413 414#if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf) 415extern CMPtype _eq_f2 (FLO_type, FLO_type); 416#endif 417 418#if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf) 419extern CMPtype _ne_f2 (FLO_type, FLO_type); 420#endif 421 422#if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf) 423extern CMPtype _gt_f2 (FLO_type, FLO_type); 424#endif 425 426#if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf) 427extern CMPtype _ge_f2 (FLO_type, FLO_type); 428#endif 429 430#if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf) 431extern CMPtype _lt_f2 (FLO_type, FLO_type); 432#endif 433 434#if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf) 435extern CMPtype _le_f2 (FLO_type, FLO_type); 436#endif 437 438#if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf) 439extern CMPtype _unord_f2 (FLO_type, FLO_type); 440#endif 441 442#if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf) 443extern FLO_type si_to_float (SItype); 444#endif 445 446#if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si) 447extern SItype float_to_si (FLO_type); 448#endif 449 450#if defined(L_tf_to_usi) 451extern USItype float_to_usi (FLO_type); 452#endif 453 454#if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf) 455extern FLO_type usi_to_float (USItype); 456#endif 457 458#if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf) 459extern FLO_type negate (FLO_type); 460#endif 461 462#ifdef FLOAT 463#if defined(L_make_sf) 464extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype); 465#endif 466#ifndef FLOAT_ONLY 467extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype); 468#if defined(L_sf_to_df) 469extern DFtype sf_to_df (SFtype); 470#endif 471#if defined(L_sf_to_tf) && defined(TMODES) 472extern TFtype sf_to_tf (SFtype); 473#endif 474#endif /* ! FLOAT_ONLY */ 475#endif /* FLOAT */ 476 477#ifndef FLOAT 478extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype); 479#if defined(L_make_df) 480extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype); 481#endif 482#if defined(L_df_to_sf) 483extern SFtype df_to_sf (DFtype); 484#endif 485#if defined(L_df_to_tf) && defined(TMODES) 486extern TFtype df_to_tf (DFtype); 487#endif 488#endif /* ! FLOAT */ 489 490#ifdef TMODES 491extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype); 492extern TFtype __make_tp (fp_class_type, unsigned int, int, UTItype); 493#ifdef TFLOAT 494#if defined(L_tf_to_sf) 495extern SFtype tf_to_sf (TFtype); 496#endif 497#if defined(L_tf_to_df) 498extern DFtype tf_to_df (TFtype); 499#endif 500#if defined(L_di_to_tf) 501extern TFtype di_to_df (DItype); 502#endif 503#endif /* TFLOAT */ 504#endif /* TMODES */ 505 506#endif /* ! GCC_FP_BIT_H */ 507