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 #ifndef __IEEE_BIG_ENDIAN 13 #include <picolibc.h> 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__) || defined(__SOFTFP__) 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 #ifndef __SOFTFP__ 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 #ifdef __ARM_FP 148 # define _SUPPORTS_ERREXCEPT 149 #endif 150 /* As per ISO/IEC TS 18661 '__FLT_EVAL_METHOD__' will be defined to 16 151 (if compiling with +fp16 support) so it can't be used by math.h to 152 define float_t and double_t. For values of '__FLT_EVAL_METHOD__' 153 other than 0, 1, 2 the definition of float_t and double_t is 154 implementation-defined. */ 155 #define __DOUBLE_TYPE double 156 #define __FLOAT_TYPE float 157 #endif 158 159 #ifdef __epiphany__ 160 #define __IEEE_LITTLE_ENDIAN 161 #define Sudden_Underflow 1 162 #endif 163 164 #ifdef __hppa__ 165 #define __IEEE_BIG_ENDIAN 166 #endif 167 168 #ifdef __nds32__ 169 #ifdef __big_endian__ 170 #define __IEEE_BIG_ENDIAN 171 #else 172 #define __IEEE_LITTLE_ENDIAN 173 #endif 174 #endif 175 176 #ifdef __SPU__ 177 #define __IEEE_BIG_ENDIAN 178 179 #define isfinite(__y) \ 180 (__extension__ ({int __cy; \ 181 (sizeof (__y) == sizeof (float)) ? (1) : \ 182 (__cy = fpclassify(__y)) != FP_INFINITE && __cy != FP_NAN;})) 183 184 #define isinf(__x) ((sizeof (__x) == sizeof (float)) ? (0) : __isinfd(__x)) 185 #define isnan(__x) ((sizeof (__x) == sizeof (float)) ? (0) : __isnand(__x)) 186 187 /* 188 * Macros for use in ieeefp.h. We can't just define the real ones here 189 * (like those above) as we have name space issues when this is *not* 190 * included via generic the ieeefp.h. 191 */ 192 #define __ieeefp_isnanf(x) 0 193 #define __ieeefp_isinff(x) 0 194 #define __ieeefp_finitef(x) 1 195 #endif 196 197 #ifdef __sparc__ 198 #ifdef __LITTLE_ENDIAN_DATA__ 199 #define __IEEE_LITTLE_ENDIAN 200 #else 201 #define __IEEE_BIG_ENDIAN 202 #endif 203 #endif 204 205 #if defined(__m68k__) || defined(__mc68000__) 206 #define __IEEE_BIG_ENDIAN 207 #ifdef __HAVE_68881__ 208 # define _SUPPORTS_ERREXCEPT 209 #endif 210 #endif 211 212 #if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__) 213 #define __IEEE_BIG_ENDIAN 214 #ifdef __HAVE_SHORT_DOUBLE__ 215 # define _DOUBLE_IS_32BITS 216 #endif 217 #endif 218 219 #if defined (__H8300__) || defined (__H8300H__) || defined (__H8300S__) || defined (__H8500__) || defined (__H8300SX__) 220 #define __IEEE_BIG_ENDIAN 221 #define _FLOAT_ARG float 222 #define _DOUBLE_IS_32BITS 223 #endif 224 225 #if defined (__xc16x__) || defined (__xc16xL__) || defined (__xc16xS__) 226 #define __IEEE_LITTLE_ENDIAN 227 #define _FLOAT_ARG float 228 #define _DOUBLE_IS_32BITS 229 #endif 230 231 232 #ifdef __sh__ 233 #define _IEEE_754_2008_SNAN 0 234 #if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__ 235 #define __IEEE_LITTLE_ENDIAN 236 #elif __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ 237 #define __IEEE_BIG_ENDIAN 238 #endif 239 #ifdef __SH_FPU_ANY__ 240 #define _SUPPORTS_ERREXCEPT 241 #endif 242 #endif 243 244 #ifdef _AM29K 245 #define __IEEE_BIG_ENDIAN 246 #endif 247 248 #ifdef _WIN32 249 #define __IEEE_LITTLE_ENDIAN 250 #endif 251 252 #ifdef __i386__ 253 #define __IEEE_LITTLE_ENDIAN 254 #ifndef _SOFT_FLOAT 255 # define _SUPPORTS_ERREXCEPT 256 #endif 257 #endif 258 259 #ifdef __riscv 260 #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) 261 #define __IEEE_BIG_ENDIAN 262 #else 263 #define __IEEE_LITTLE_ENDIAN 264 #endif 265 #if defined(__riscv_flen) || defined (__riscv_zfinx) 266 # define _SUPPORTS_ERREXCEPT 267 #endif 268 #endif 269 270 #ifdef __powerpc__ 271 272 #ifdef __LITTLE_ENDIAN__ 273 #define __IEEE_LITTLE_ENDIAN 274 #else 275 #define __IEEE_BIG_ENDIAN 276 #endif 277 278 #ifndef _SOFT_FLOAT 279 # define _SUPPORTS_ERREXCEPT 280 #endif 281 282 #endif 283 284 #ifdef __i960__ 285 #define __IEEE_LITTLE_ENDIAN 286 #endif 287 288 #ifdef __lm32__ 289 #define __IEEE_BIG_ENDIAN 290 #endif 291 292 #ifdef __M32R__ 293 #define __IEEE_BIG_ENDIAN 294 #endif 295 296 #ifdef __nvptx__ 297 #define __IEEE_LITTLE_ENDIAN 298 #endif 299 300 #if defined(_C4x) || defined(_C3x) 301 #define __IEEE_BIG_ENDIAN 302 #define _DOUBLE_IS_32BITS 303 #endif 304 305 #ifdef __TMS320C6X__ 306 #ifdef _BIG_ENDIAN 307 #define __IEEE_BIG_ENDIAN 308 #else 309 #define __IEEE_LITTLE_ENDIAN 310 #endif 311 #endif 312 313 #ifdef __TIC80__ 314 #define __IEEE_LITTLE_ENDIAN 315 #endif 316 317 #ifdef __mips__ 318 #define _IEEE_754_2008_SNAN 0 319 #ifndef __mips_soft_float 320 #define _SUPPORTS_ERREXCEPT 321 #endif 322 #endif 323 324 #ifdef __MIPSEL__ 325 #define __IEEE_LITTLE_ENDIAN 326 #endif 327 #ifdef __MIPSEB__ 328 #define __IEEE_BIG_ENDIAN 329 #endif 330 331 #ifdef __MMIX__ 332 #define __IEEE_BIG_ENDIAN 333 #endif 334 335 #ifdef __D30V__ 336 #define __IEEE_BIG_ENDIAN 337 #endif 338 339 /* necv70 was __IEEE_LITTLE_ENDIAN. */ 340 341 #ifdef __W65__ 342 #define __IEEE_LITTLE_ENDIAN 343 #define _DOUBLE_IS_32BITS 344 #endif 345 346 #if defined(__Z8001__) || defined(__Z8002__) 347 #define __IEEE_BIG_ENDIAN 348 #endif 349 350 #ifdef __m88k__ 351 #define __IEEE_BIG_ENDIAN 352 #endif 353 354 #ifdef __mn10300__ 355 #define __IEEE_LITTLE_ENDIAN 356 #endif 357 358 #ifdef __mn10200__ 359 #define __IEEE_LITTLE_ENDIAN 360 #define _DOUBLE_IS_32BITS 361 #endif 362 363 #ifdef __v800 364 #define __IEEE_LITTLE_ENDIAN 365 #endif 366 367 #ifdef __v850 368 #define __IEEE_LITTLE_ENDIAN 369 #endif 370 371 #ifdef __D10V__ 372 #define __IEEE_BIG_ENDIAN 373 #if __DOUBLE__ == 32 374 #define _DOUBLE_IS_32BITS 375 #endif 376 #endif 377 378 #ifdef __PPC__ 379 #if (defined(_BIG_ENDIAN) && _BIG_ENDIAN) || (defined(_AIX) && _AIX) 380 #define __IEEE_BIG_ENDIAN 381 #else 382 #if (defined(_LITTLE_ENDIAN) && _LITTLE_ENDIAN) || (defined(__sun__) && __sun__) || (defined(_WIN32) && _WIN32) 383 #define __IEEE_LITTLE_ENDIAN 384 #endif 385 #endif 386 #endif 387 388 #ifdef __xstormy16__ 389 #define __IEEE_LITTLE_ENDIAN 390 #endif 391 392 #ifdef __arc__ 393 #ifdef __big_endian__ 394 #define __IEEE_BIG_ENDIAN 395 #else 396 #define __IEEE_LITTLE_ENDIAN 397 #endif 398 #endif 399 400 #ifdef __CRX__ 401 #define __IEEE_LITTLE_ENDIAN 402 #endif 403 404 #ifdef __CSKY__ 405 #ifdef __CSKYBE__ 406 #define __IEEE_BIG_ENDIAN 407 #else 408 #define __IEEE_LITTLE_ENDIAN 409 #endif 410 #endif 411 412 #ifdef __fr30__ 413 #define __IEEE_BIG_ENDIAN 414 #endif 415 416 #ifdef __FT32__ 417 #define __IEEE_LITTLE_ENDIAN 418 #endif 419 420 #ifdef __mcore__ 421 #define __IEEE_BIG_ENDIAN 422 #endif 423 424 #ifdef __mt__ 425 #define __IEEE_BIG_ENDIAN 426 #endif 427 428 #ifdef __frv__ 429 #define __IEEE_BIG_ENDIAN 430 #endif 431 432 #ifdef __moxie__ 433 #ifdef __MOXIE_BIG_ENDIAN__ 434 #define __IEEE_BIG_ENDIAN 435 #else 436 #define __IEEE_LITTLE_ENDIAN 437 #endif 438 #endif 439 440 #ifdef __ia64__ 441 #ifdef __BIG_ENDIAN__ 442 #define __IEEE_BIG_ENDIAN 443 #else 444 #define __IEEE_LITTLE_ENDIAN 445 #endif 446 #endif 447 448 #ifdef __AVR__ 449 #define __IEEE_LITTLE_ENDIAN 450 #if !defined(__SIZEOF_DOUBLE__) || __SIZEOF_DOUBLE__ == 4 451 #define _DOUBLE_IS_32BITS 452 #endif 453 #endif 454 455 #if defined(__or1k__) || defined(__OR1K__) || defined(__OR1KND__) 456 #define __IEEE_BIG_ENDIAN 457 #endif 458 459 #ifdef __IP2K__ 460 #define __IEEE_BIG_ENDIAN 461 #define __SMALL_BITFIELDS 462 #define _DOUBLE_IS_32BITS 463 #endif 464 465 #ifdef __iq2000__ 466 #define __IEEE_BIG_ENDIAN 467 #endif 468 469 #ifdef __MAVERICK__ 470 #ifdef __ARMEL__ 471 # define __IEEE_LITTLE_ENDIAN 472 #else /* must be __ARMEB__ */ 473 # define __IEEE_BIG_ENDIAN 474 #endif /* __ARMEL__ */ 475 #endif /* __MAVERICK__ */ 476 477 #ifdef __m32c__ 478 #define __IEEE_LITTLE_ENDIAN 479 #define __SMALL_BITFIELDS 480 #endif 481 482 #ifdef __CRIS__ 483 #define __IEEE_LITTLE_ENDIAN 484 #endif 485 486 #ifdef __BFIN__ 487 #define __IEEE_LITTLE_ENDIAN 488 #endif 489 490 #ifdef __x86_64__ 491 #define __IEEE_LITTLE_ENDIAN 492 #ifndef _SOFT_FLOAT 493 # define _SUPPORTS_ERREXCEPT 494 #endif 495 #endif 496 497 #ifdef __mep__ 498 #ifdef __LITTLE_ENDIAN__ 499 #define __IEEE_LITTLE_ENDIAN 500 #else 501 #define __IEEE_BIG_ENDIAN 502 #endif 503 #endif 504 505 #ifdef __MICROBLAZE__ 506 #ifndef __MICROBLAZEEL__ 507 #define __IEEE_BIG_ENDIAN 508 #else 509 #define __IEEE_LITTLE_ENDIAN 510 #endif 511 #endif 512 513 #ifdef __MSP430__ 514 #define __IEEE_LITTLE_ENDIAN 515 #define __SMALL_BITFIELDS /* 16 Bit INT */ 516 #endif 517 518 #ifdef __PRU__ 519 #define __IEEE_LITTLE_ENDIAN 520 #endif 521 522 #ifdef __RL78__ 523 #define __IEEE_LITTLE_ENDIAN 524 #define __SMALL_BITFIELDS /* 16 Bit INT */ 525 #ifndef __RL78_64BIT_DOUBLES__ 526 #define _DOUBLE_IS_32BITS 527 #endif 528 #endif 529 530 #ifdef __RX__ 531 532 #ifdef __RX_BIG_ENDIAN__ 533 #define __IEEE_BIG_ENDIAN 534 #else 535 #define __IEEE_LITTLE_ENDIAN 536 #endif 537 538 #ifndef __RX_64BIT_DOUBLES__ 539 #define _DOUBLE_IS_32BITS 540 #endif 541 542 #ifdef __RX_16BIT_INTS__ 543 #define __SMALL_BITFIELDS 544 #endif 545 546 #endif 547 548 #if (defined(__CR16__) || defined(__CR16C__) ||defined(__CR16CP__)) 549 #define __IEEE_LITTLE_ENDIAN 550 #define __SMALL_BITFIELDS /* 16 Bit INT */ 551 #endif 552 553 #ifdef __NIOS2__ 554 # ifdef __nios2_big_endian__ 555 # define __IEEE_BIG_ENDIAN 556 # else 557 # define __IEEE_LITTLE_ENDIAN 558 # endif 559 #endif 560 561 #ifdef __VISIUM__ 562 #define __IEEE_BIG_ENDIAN 563 #endif 564 565 #if (defined(__XTENSA__)) 566 #ifdef __XTENSA_EB__ 567 #define __IEEE_BIG_ENDIAN 568 #endif 569 #ifdef __XTENSA_EL__ 570 #define __IEEE_LITTLE_ENDIAN 571 #endif 572 #endif 573 574 #ifdef __AMDGCN__ 575 #define __IEEE_LITTLE_ENDIAN 576 #endif 577 578 /* New math code requires 64-bit doubles */ 579 #ifdef _DOUBLE_IS_32BITS 580 #undef __OBSOLETE_MATH 581 #undef __OBSOLETE_MATH_DOUBLE 582 #undef __OBSOLETE_MATH_FLOAT 583 #undef __OBSOLETE_MATH_DEFAULT_FLOAT 584 #undef __OBSOLETE_MATH_DEFAULT_DOUBLE 585 #define __OBSOLETE_MATH 1 586 #endif 587 588 #ifdef __XTENSA_EB__ 589 #define __IEEE_BIG_ENDIAN 590 #endif 591 592 #ifdef __CYGWIN__ 593 #define __OBSOLETE_MATH_DEFAULT 0 594 #endif 595 596 #ifndef __OBSOLETE_MATH_DEFAULT 597 #define __OBSOLETE_MATH_DEFAULT 1 598 #endif 599 600 #ifndef __OBSOLETE_MATH 601 #define __OBSOLETE_MATH __OBSOLETE_MATH_DEFAULT 602 #endif 603 604 #ifndef __OBSOLETE_MATH_FLOAT 605 #ifdef __OBSOLETE_MATH_DEFAULT_FLOAT 606 #define __OBSOLETE_MATH_FLOAT __OBSOLETE_MATH_DEFAULT_FLOAT 607 #else 608 #define __OBSOLETE_MATH_FLOAT __OBSOLETE_MATH 609 #endif 610 #endif 611 612 #ifndef __OBSOLETE_MATH_DOUBLE 613 #ifdef __OBSOLETE_MATH_DEFAULT_DOUBLE 614 #define __OBSOLETE_MATH_DOUBLE __OBSOLETE_MATH_DEFAULT_DOUBLE 615 #else 616 #define __OBSOLETE_MATH_DOUBLE __OBSOLETE_MATH 617 #endif 618 #endif 619 620 /* Use __FLOAT_WORD_ORDER__ if we don't have 621 * more specific platform knowledge 622 */ 623 #ifndef __IEEE_BIG_ENDIAN 624 # ifndef __IEEE_LITTLE_ENDIAN 625 # ifdef __FLOAT_WORD_ORDER__ 626 # if __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__ 627 # define __IEEE_LITTLE_ENDIAN 628 # endif 629 # if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ 630 # define __IEEE_BIG_ENDIAN 631 # endif 632 # endif 633 # endif 634 #endif 635 636 #ifndef __IEEE_BIG_ENDIAN 637 #ifndef __IEEE_LITTLE_ENDIAN 638 #error Endianess not declared!! 639 #endif /* not __IEEE_LITTLE_ENDIAN */ 640 #endif /* not __IEEE_BIG_ENDIAN */ 641 642 #endif /* not __IEEE_LITTLE_ENDIAN */ 643 #endif /* not __IEEE_BIG_ENDIAN */ 644 645