1 /* 2 Copyright (C) 1991 DJ Delorie 3 All rights reserved. 4 5 Redistribution, modification, and use in source and binary forms is permitted 6 provided that the above copyright notice and following paragraph are 7 duplicated in all such forms. 8 9 This file is distributed WITHOUT ANY WARRANTY; without even the implied 10 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 */ 12 #include <sys/features.h> 13 #ifndef __IEEE_BIG_ENDIAN 14 #ifndef __IEEE_LITTLE_ENDIAN 15 16 /* This file can define macros to choose variations of the IEEE float 17 format: 18 19 _FLT_LARGEST_EXPONENT_IS_NORMAL 20 21 Defined if the float format uses the largest exponent for finite 22 numbers rather than NaN and infinity representations. Such a 23 format cannot represent NaNs or infinities at all, but it's FLT_MAX 24 is twice the IEEE value. 25 26 _FLT_NO_DENORMALS 27 28 Defined if the float format does not support IEEE denormals. Every 29 float with a zero exponent is taken to be a zero representation. 30 31 ??? At the moment, there are no equivalent macros above for doubles and 32 the macros are not fully supported by --enable-newlib-hw-fp. 33 34 __IEEE_BIG_ENDIAN 35 36 Defined if the float format is big endian. This is mutually exclusive 37 with __IEEE_LITTLE_ENDIAN. 38 39 __IEEE_LITTLE_ENDIAN 40 41 Defined if the float format is little endian. This is mutually exclusive 42 with __IEEE_BIG_ENDIAN. 43 44 Note that one of __IEEE_BIG_ENDIAN or __IEEE_LITTLE_ENDIAN must be specified for a 45 platform or error will occur. 46 47 __IEEE_BYTES_LITTLE_ENDIAN 48 49 This flag is used in conjunction with __IEEE_BIG_ENDIAN to describe a situation 50 whereby multiple words of an IEEE floating point are in big endian order, but the 51 words themselves are little endian with respect to the bytes. 52 53 _DOUBLE_IS_32BITS 54 55 This is used on platforms that support double by using the 32-bit IEEE 56 float type. 57 58 _FLOAT_ARG 59 60 This represents what type a float arg is passed as. It is used when the type is 61 not promoted to double. 62 63 64 __OBSOLETE_MATH_DEFAULT 65 66 Default value for __OBSOLETE_MATH if that's not set by the user. 67 It should be set here based on predefined feature macros. 68 69 __OBSOLETE_MATH 70 71 If set to 1 then some new math code will be disabled and older libm 72 code will be used instead. This is necessary because the new math 73 code does not support all targets, it assumes that the toolchain has 74 ISO C99 support (hexfloat literals, standard fenv semantics), the 75 target has IEEE-754 conforming binary32 float and binary64 double 76 (not mixed endian) representation, standard SNaN representation, 77 double and single precision arithmetics has similar latency and it 78 has no legacy SVID matherr support, only POSIX errno and fenv 79 exception based error handling. 80 */ 81 82 #if !defined(__IEEE_BIG_ENDIAN) && !defined(__IEEE_LITTLE_ENDIAN) 83 # if defined(__ORDER_BIG_ENDIAN__) && defined(__ORDER_LITTLE_ENDIAN__) && defined(__FLOAT_WORD_ORDER__) 84 # if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ 85 # define __IEEE_BIG_ENDIAN 86 # else 87 # define __IEEE_LITTLE_ENDIAN 88 # endif 89 # endif 90 #endif 91 92 #if __SIZEOF_DOUBLE__ == __SIZEOF_FLOAT__ 93 # define _DBL_EQ_FLT 94 #endif 95 96 #if __SIZEOF_LONG_DOUBLE == __SIZEOF_DOUBLE__ 97 # define LDBL_EQ_DBL 98 #endif 99 100 #if __SIZEOF_DOUBLE__ == 4 101 # define _DOUBLE_IS_32BITS 102 #endif 103 104 #if _SIZEOF_LONG_DOUBLE__ == 4 105 # define _LONG_DOUBLE_IS_32BITS 106 #endif 107 108 #if (defined(__arm__) || defined(__thumb__)) && !defined(__MAVERICK__) 109 /* arm with hard fp and soft dp cannot use new float code */ 110 # if (__ARM_FP & 4) && !(__ARM_FP & 8) 111 # define __OBSOLETE_MATH_DEFAULT_FLOAT 1 112 # endif 113 /* ARM traditionally used big-endian words; and within those words the 114 byte ordering was big or little endian depending upon the target. 115 Modern floating-point formats are naturally ordered; in this case 116 __VFP_FP__ will be defined, even if soft-float. */ 117 #if defined(__VFP_FP__) || __ARM_FP == 0 118 # ifdef __ARMEL__ 119 # define __IEEE_LITTLE_ENDIAN 120 # else 121 # define __IEEE_BIG_ENDIAN 122 # endif 123 #else 124 # define __IEEE_BIG_ENDIAN 125 # ifdef __ARMEL__ 126 # define __IEEE_BYTES_LITTLE_ENDIAN 127 # endif 128 #endif 129 #if __ARM_FP != 0 130 # define _SUPPORTS_ERREXCEPT 131 #endif 132 /* As per ISO/IEC TS 18661 '__FLT_EVAL_METHOD__' will be defined to 16 133 (if compiling with +fp16 support) so it can't be used by math.h to 134 define float_t and double_t. For values of '__FLT_EVAL_METHOD__' 135 other than 0, 1, 2 the definition of float_t and double_t is 136 implementation-defined. */ 137 #define __DOUBLE_TYPE double 138 #define __FLOAT_TYPE float 139 #endif 140 141 #if defined (__aarch64__) 142 #if defined (__AARCH64EL__) 143 #define __IEEE_LITTLE_ENDIAN 144 #else 145 #define __IEEE_BIG_ENDIAN 146 #endif 147 #if __ARM_FP != 0 148 # define _SUPPORTS_ERREXCEPT 149 #else 150 #ifdef __clang__ 151 #include <float.h> 152 /* Clang accesses FPSR for FLT_ROUNDS with soft float target */ 153 #undef FLT_ROUNDS 154 #define FLT_ROUNDS 1 155 #endif 156 #endif 157 /* As per ISO/IEC TS 18661 '__FLT_EVAL_METHOD__' will be defined to 16 158 (if compiling with +fp16 support) so it can't be used by math.h to 159 define float_t and double_t. For values of '__FLT_EVAL_METHOD__' 160 other than 0, 1, 2 the definition of float_t and double_t is 161 implementation-defined. */ 162 #define __DOUBLE_TYPE double 163 #define __FLOAT_TYPE float 164 #endif 165 166 #ifdef __epiphany__ 167 #define __IEEE_LITTLE_ENDIAN 168 #define Sudden_Underflow 1 169 #endif 170 171 #ifdef __hppa__ 172 #define __IEEE_BIG_ENDIAN 173 #endif 174 175 #ifdef __nds32__ 176 #ifdef __big_endian__ 177 #define __IEEE_BIG_ENDIAN 178 #else 179 #define __IEEE_LITTLE_ENDIAN 180 #endif 181 #endif 182 183 #ifdef __SPU__ 184 #define __IEEE_BIG_ENDIAN 185 186 #define isfinite(__y) \ 187 (__extension__ ({int __cy; \ 188 (sizeof (__y) == sizeof (float)) ? (1) : \ 189 (__cy = fpclassify(__y)) != FP_INFINITE && __cy != FP_NAN;})) 190 191 #define isinf(__x) ((sizeof (__x) == sizeof (float)) ? (0) : __isinfd(__x)) 192 #define isnan(__x) ((sizeof (__x) == sizeof (float)) ? (0) : __isnand(__x)) 193 194 /* 195 * Macros for use in ieeefp.h. We can't just define the real ones here 196 * (like those above) as we have name space issues when this is *not* 197 * included via generic the ieeefp.h. 198 */ 199 #define __ieeefp_isnanf(x) 0 200 #define __ieeefp_isinff(x) 0 201 #define __ieeefp_finitef(x) 1 202 #endif 203 204 #ifdef __sparc__ 205 #ifdef __LITTLE_ENDIAN_DATA__ 206 #define __IEEE_LITTLE_ENDIAN 207 #else 208 #define __IEEE_BIG_ENDIAN 209 #endif 210 #endif 211 212 #if defined(__m68k__) || defined(__mc68000__) 213 #define __IEEE_BIG_ENDIAN 214 #ifdef __HAVE_68881__ 215 # define _SUPPORTS_ERREXCEPT 216 #endif 217 #endif 218 219 #if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__) 220 #define __IEEE_BIG_ENDIAN 221 #ifdef __HAVE_SHORT_DOUBLE__ 222 # define _DOUBLE_IS_32BITS 223 #endif 224 #endif 225 226 #if defined (__H8300__) || defined (__H8300H__) || defined (__H8300S__) || defined (__H8500__) || defined (__H8300SX__) 227 #define __IEEE_BIG_ENDIAN 228 #define _FLOAT_ARG float 229 #define _DOUBLE_IS_32BITS 230 #endif 231 232 #if defined (__xc16x__) || defined (__xc16xL__) || defined (__xc16xS__) 233 #define __IEEE_LITTLE_ENDIAN 234 #define _FLOAT_ARG float 235 #define _DOUBLE_IS_32BITS 236 #endif 237 238 239 #ifdef __sh__ 240 #define _IEEE_754_2008_SNAN 0 241 #if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__ 242 #define __IEEE_LITTLE_ENDIAN 243 #elif __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ 244 #define __IEEE_BIG_ENDIAN 245 #endif 246 #ifdef __SH_FPU_ANY__ 247 #define _SUPPORTS_ERREXCEPT 248 #endif 249 #endif 250 251 #ifdef _AM29K 252 #define __IEEE_BIG_ENDIAN 253 #endif 254 255 #ifdef _WIN32 256 #define __IEEE_LITTLE_ENDIAN 257 #endif 258 259 #ifdef __i386__ 260 #define __IEEE_LITTLE_ENDIAN 261 #ifndef _SOFT_FLOAT 262 # define _SUPPORTS_ERREXCEPT 263 #endif 264 #endif 265 266 #ifdef __riscv 267 #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) 268 #define __IEEE_BIG_ENDIAN 269 #else 270 #define __IEEE_LITTLE_ENDIAN 271 #endif 272 #if defined(__riscv_flen) || defined (__riscv_zfinx) 273 # define _SUPPORTS_ERREXCEPT 274 #endif 275 #endif 276 277 #ifdef __powerpc__ 278 279 #ifdef __LITTLE_ENDIAN__ 280 #define __IEEE_LITTLE_ENDIAN 281 #else 282 #define __IEEE_BIG_ENDIAN 283 #endif 284 285 #ifndef _SOFT_FLOAT 286 # define _SUPPORTS_ERREXCEPT 287 #endif 288 289 #endif 290 291 #ifdef __i960__ 292 #define __IEEE_LITTLE_ENDIAN 293 #endif 294 295 #ifdef __lm32__ 296 #define __IEEE_BIG_ENDIAN 297 #endif 298 299 #ifdef __M32R__ 300 #define __IEEE_BIG_ENDIAN 301 #endif 302 303 #ifdef __nvptx__ 304 #define __IEEE_LITTLE_ENDIAN 305 #endif 306 307 #if defined(_C4x) || defined(_C3x) 308 #define __IEEE_BIG_ENDIAN 309 #define _DOUBLE_IS_32BITS 310 #endif 311 312 #ifdef __TMS320C6X__ 313 #ifdef _BIG_ENDIAN 314 #define __IEEE_BIG_ENDIAN 315 #else 316 #define __IEEE_LITTLE_ENDIAN 317 #endif 318 #endif 319 320 #ifdef __TIC80__ 321 #define __IEEE_LITTLE_ENDIAN 322 #endif 323 324 #ifdef __mips__ 325 #define _IEEE_754_2008_SNAN 0 326 #ifndef __mips_soft_float 327 #define _SUPPORTS_ERREXCEPT 328 #endif 329 #endif 330 331 #ifdef __MIPSEL__ 332 #define __IEEE_LITTLE_ENDIAN 333 #endif 334 #ifdef __MIPSEB__ 335 #define __IEEE_BIG_ENDIAN 336 #endif 337 338 #ifdef __MMIX__ 339 #define __IEEE_BIG_ENDIAN 340 #endif 341 342 #ifdef __D30V__ 343 #define __IEEE_BIG_ENDIAN 344 #endif 345 346 /* necv70 was __IEEE_LITTLE_ENDIAN. */ 347 348 #ifdef __W65__ 349 #define __IEEE_LITTLE_ENDIAN 350 #define _DOUBLE_IS_32BITS 351 #endif 352 353 #if defined(__Z8001__) || defined(__Z8002__) 354 #define __IEEE_BIG_ENDIAN 355 #endif 356 357 #ifdef __m88k__ 358 #define __IEEE_BIG_ENDIAN 359 #endif 360 361 #ifdef __mn10300__ 362 #define __IEEE_LITTLE_ENDIAN 363 #endif 364 365 #ifdef __mn10200__ 366 #define __IEEE_LITTLE_ENDIAN 367 #define _DOUBLE_IS_32BITS 368 #endif 369 370 #ifdef __v800 371 #define __IEEE_LITTLE_ENDIAN 372 #endif 373 374 #ifdef __v850 375 #define __IEEE_LITTLE_ENDIAN 376 #endif 377 378 #ifdef __D10V__ 379 #define __IEEE_BIG_ENDIAN 380 #if __DOUBLE__ == 32 381 #define _DOUBLE_IS_32BITS 382 #endif 383 #endif 384 385 #ifdef __PPC__ 386 #if (defined(_BIG_ENDIAN) && _BIG_ENDIAN) || (defined(_AIX) && _AIX) 387 #define __IEEE_BIG_ENDIAN 388 #else 389 #if (defined(_LITTLE_ENDIAN) && _LITTLE_ENDIAN) || (defined(__sun__) && __sun__) || (defined(_WIN32) && _WIN32) 390 #define __IEEE_LITTLE_ENDIAN 391 #endif 392 #endif 393 #endif 394 395 #ifdef __xstormy16__ 396 #define __IEEE_LITTLE_ENDIAN 397 #endif 398 399 #ifdef __arc__ 400 #ifdef __big_endian__ 401 #define __IEEE_BIG_ENDIAN 402 #else 403 #define __IEEE_LITTLE_ENDIAN 404 #endif 405 #endif 406 407 #ifdef __ARC64__ 408 #define __IEEE_LITTLE_ENDIAN 409 #endif 410 411 #ifdef __CRX__ 412 #define __IEEE_LITTLE_ENDIAN 413 #endif 414 415 #ifdef __CSKY__ 416 #ifdef __CSKYBE__ 417 #define __IEEE_BIG_ENDIAN 418 #else 419 #define __IEEE_LITTLE_ENDIAN 420 #endif 421 #endif 422 423 #ifdef __fr30__ 424 #define __IEEE_BIG_ENDIAN 425 #endif 426 427 #ifdef __FT32__ 428 #define __IEEE_LITTLE_ENDIAN 429 #endif 430 431 #ifdef __mcore__ 432 #define __IEEE_BIG_ENDIAN 433 #endif 434 435 #ifdef __mt__ 436 #define __IEEE_BIG_ENDIAN 437 #endif 438 439 #ifdef __frv__ 440 #define __IEEE_BIG_ENDIAN 441 #endif 442 443 #ifdef __moxie__ 444 #ifdef __MOXIE_BIG_ENDIAN__ 445 #define __IEEE_BIG_ENDIAN 446 #else 447 #define __IEEE_LITTLE_ENDIAN 448 #endif 449 #endif 450 451 #ifdef __ia64__ 452 #ifdef __BIG_ENDIAN__ 453 #define __IEEE_BIG_ENDIAN 454 #else 455 #define __IEEE_LITTLE_ENDIAN 456 #endif 457 #endif 458 459 #ifdef __AVR__ 460 #define __IEEE_LITTLE_ENDIAN 461 #if !defined(__SIZEOF_DOUBLE__) || __SIZEOF_DOUBLE__ == 4 462 #define _DOUBLE_IS_32BITS 463 #endif 464 #endif 465 466 #if defined(__or1k__) || defined(__OR1K__) || defined(__OR1KND__) 467 #define __IEEE_BIG_ENDIAN 468 #endif 469 470 #ifdef __IP2K__ 471 #define __IEEE_BIG_ENDIAN 472 #define __SMALL_BITFIELDS 473 #define _DOUBLE_IS_32BITS 474 #endif 475 476 #ifdef __iq2000__ 477 #define __IEEE_BIG_ENDIAN 478 #endif 479 480 #ifdef __MAVERICK__ 481 #ifdef __ARMEL__ 482 # define __IEEE_LITTLE_ENDIAN 483 #else /* must be __ARMEB__ */ 484 # define __IEEE_BIG_ENDIAN 485 #endif /* __ARMEL__ */ 486 #endif /* __MAVERICK__ */ 487 488 #ifdef __m32c__ 489 #define __IEEE_LITTLE_ENDIAN 490 #define __SMALL_BITFIELDS 491 #endif 492 493 #ifdef __CRIS__ 494 #define __IEEE_LITTLE_ENDIAN 495 #endif 496 497 #ifdef __BFIN__ 498 #define __IEEE_LITTLE_ENDIAN 499 #endif 500 501 #ifdef __x86_64__ 502 #define __IEEE_LITTLE_ENDIAN 503 #ifndef _SOFT_FLOAT 504 # define _SUPPORTS_ERREXCEPT 505 #endif 506 #endif 507 508 #ifdef __mep__ 509 #ifdef __LITTLE_ENDIAN__ 510 #define __IEEE_LITTLE_ENDIAN 511 #else 512 #define __IEEE_BIG_ENDIAN 513 #endif 514 #endif 515 516 #ifdef __MICROBLAZE__ 517 #ifndef __MICROBLAZEEL__ 518 #define __IEEE_BIG_ENDIAN 519 #else 520 #define __IEEE_LITTLE_ENDIAN 521 #endif 522 #endif 523 524 #ifdef __MSP430__ 525 #define __IEEE_LITTLE_ENDIAN 526 #define __SMALL_BITFIELDS /* 16 Bit INT */ 527 #endif 528 529 #ifdef __PRU__ 530 #define __IEEE_LITTLE_ENDIAN 531 #endif 532 533 #ifdef __RL78__ 534 #define __IEEE_LITTLE_ENDIAN 535 #define __SMALL_BITFIELDS /* 16 Bit INT */ 536 #ifndef __RL78_64BIT_DOUBLES__ 537 #define _DOUBLE_IS_32BITS 538 #endif 539 #endif 540 541 #ifdef __RX__ 542 543 #ifdef __RX_BIG_ENDIAN__ 544 #define __IEEE_BIG_ENDIAN 545 #else 546 #define __IEEE_LITTLE_ENDIAN 547 #endif 548 549 #ifndef __RX_64BIT_DOUBLES__ 550 #define _DOUBLE_IS_32BITS 551 #endif 552 553 #ifdef __RX_16BIT_INTS__ 554 #define __SMALL_BITFIELDS 555 #endif 556 557 #endif 558 559 #if (defined(__CR16__) || defined(__CR16C__) ||defined(__CR16CP__)) 560 #define __IEEE_LITTLE_ENDIAN 561 #define __SMALL_BITFIELDS /* 16 Bit INT */ 562 #endif 563 564 #ifdef __NIOS2__ 565 # ifdef __nios2_big_endian__ 566 # define __IEEE_BIG_ENDIAN 567 # else 568 # define __IEEE_LITTLE_ENDIAN 569 # endif 570 #endif 571 572 #ifdef __VISIUM__ 573 #define __IEEE_BIG_ENDIAN 574 #endif 575 576 #if (defined(__XTENSA__)) 577 #ifdef __XTENSA_EB__ 578 #define __IEEE_BIG_ENDIAN 579 #endif 580 #ifdef __XTENSA_EL__ 581 #define __IEEE_LITTLE_ENDIAN 582 #endif 583 #endif 584 585 #ifdef __AMDGCN__ 586 #define __IEEE_LITTLE_ENDIAN 587 #endif 588 589 /* New math code requires 64-bit doubles */ 590 #ifdef _DOUBLE_IS_32BITS 591 #undef __OBSOLETE_MATH 592 #undef __OBSOLETE_MATH_DOUBLE 593 #undef __OBSOLETE_MATH_FLOAT 594 #undef __OBSOLETE_MATH_DEFAULT_FLOAT 595 #undef __OBSOLETE_MATH_DEFAULT_DOUBLE 596 #define __OBSOLETE_MATH 1 597 #endif 598 599 #ifdef __XTENSA_EB__ 600 #define __IEEE_BIG_ENDIAN 601 #endif 602 603 604 #ifndef __OBSOLETE_MATH_DEFAULT 605 #define __OBSOLETE_MATH_DEFAULT 1 606 #endif 607 608 #ifndef __OBSOLETE_MATH 609 #define __OBSOLETE_MATH __OBSOLETE_MATH_DEFAULT 610 #endif 611 612 #ifndef __OBSOLETE_MATH_FLOAT 613 #ifdef __OBSOLETE_MATH_DEFAULT_FLOAT 614 #define __OBSOLETE_MATH_FLOAT __OBSOLETE_MATH_DEFAULT_FLOAT 615 #else 616 #define __OBSOLETE_MATH_FLOAT __OBSOLETE_MATH 617 #endif 618 #endif 619 620 #ifndef __OBSOLETE_MATH_DOUBLE 621 #ifdef __OBSOLETE_MATH_DEFAULT_DOUBLE 622 #define __OBSOLETE_MATH_DOUBLE __OBSOLETE_MATH_DEFAULT_DOUBLE 623 #else 624 #define __OBSOLETE_MATH_DOUBLE __OBSOLETE_MATH 625 #endif 626 #endif 627 628 /* Use __FLOAT_WORD_ORDER__ if we don't have 629 * more specific platform knowledge 630 */ 631 #ifndef __IEEE_BIG_ENDIAN 632 # ifndef __IEEE_LITTLE_ENDIAN 633 # ifdef __FLOAT_WORD_ORDER__ 634 # if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__ 635 # define __IEEE_LITTLE_ENDIAN 636 # endif 637 # if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ 638 # define __IEEE_BIG_ENDIAN 639 # endif 640 # endif 641 # endif 642 #endif 643 644 #ifndef __IEEE_BIG_ENDIAN 645 #ifndef __IEEE_LITTLE_ENDIAN 646 #error Endianess not declared!! 647 #endif /* not __IEEE_LITTLE_ENDIAN */ 648 #endif /* not __IEEE_BIG_ENDIAN */ 649 650 #endif /* not __IEEE_LITTLE_ENDIAN */ 651 #endif /* not __IEEE_BIG_ENDIAN */ 652 653