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