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