xref: /minix3/sys/external/bsd/compiler_rt/dist/test/builtins/Unit/endianness.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* ===-- endianness.h - configuration header for libgcc replacement --------===
2*0a6a1f1dSLionel Sambuc  *
3*0a6a1f1dSLionel Sambuc  *		       The LLVM Compiler Infrastructure
4*0a6a1f1dSLionel Sambuc  *
5*0a6a1f1dSLionel Sambuc  * This file is dual licensed under the MIT and the University of Illinois Open
6*0a6a1f1dSLionel Sambuc  * Source Licenses. See LICENSE.TXT for details.
7*0a6a1f1dSLionel Sambuc  *
8*0a6a1f1dSLionel Sambuc  * ===----------------------------------------------------------------------===
9*0a6a1f1dSLionel Sambuc  *
10*0a6a1f1dSLionel Sambuc  * This file is a configuration header for libgcc replacement.
11*0a6a1f1dSLionel Sambuc  * This file is not part of the interface of this library.
12*0a6a1f1dSLionel Sambuc  *
13*0a6a1f1dSLionel Sambuc  * ===----------------------------------------------------------------------===
14*0a6a1f1dSLionel Sambuc  */
15*0a6a1f1dSLionel Sambuc 
16*0a6a1f1dSLionel Sambuc #ifndef ENDIANNESS_H
17*0a6a1f1dSLionel Sambuc #define ENDIANNESS_H
18*0a6a1f1dSLionel Sambuc 
19*0a6a1f1dSLionel Sambuc /*
20*0a6a1f1dSLionel Sambuc  * Known limitations:
21*0a6a1f1dSLionel Sambuc  *   Middle endian systems are not handled currently.
22*0a6a1f1dSLionel Sambuc  */
23*0a6a1f1dSLionel Sambuc 
24*0a6a1f1dSLionel Sambuc #if defined(__SVR4) && defined(__sun)
25*0a6a1f1dSLionel Sambuc #include <sys/byteorder.h>
26*0a6a1f1dSLionel Sambuc 
27*0a6a1f1dSLionel Sambuc #if _BYTE_ORDER == _BIG_ENDIAN
28*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 0
29*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    1
30*0a6a1f1dSLionel Sambuc #elif _BYTE_ORDER == _LITTLE_ENDIAN
31*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 1
32*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    0
33*0a6a1f1dSLionel Sambuc #endif /* _BYTE_ORDER */
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc #endif /* Solaris and AuroraUX. */
36*0a6a1f1dSLionel Sambuc 
37*0a6a1f1dSLionel Sambuc /* .. */
38*0a6a1f1dSLionel Sambuc 
39*0a6a1f1dSLionel Sambuc #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonflyBSD__) || defined(__minix)
40*0a6a1f1dSLionel Sambuc #include <sys/endian.h>
41*0a6a1f1dSLionel Sambuc 
42*0a6a1f1dSLionel Sambuc #if _BYTE_ORDER == _BIG_ENDIAN
43*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 0
44*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    1
45*0a6a1f1dSLionel Sambuc #elif _BYTE_ORDER == _LITTLE_ENDIAN
46*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 1
47*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    0
48*0a6a1f1dSLionel Sambuc #endif /* _BYTE_ORDER */
49*0a6a1f1dSLionel Sambuc 
50*0a6a1f1dSLionel Sambuc #endif /* *BSD */
51*0a6a1f1dSLionel Sambuc 
52*0a6a1f1dSLionel Sambuc /* .. */
53*0a6a1f1dSLionel Sambuc 
54*0a6a1f1dSLionel Sambuc #if defined(__OpenBSD__) || defined(__Bitrig__)
55*0a6a1f1dSLionel Sambuc #include <machine/endian.h>
56*0a6a1f1dSLionel Sambuc 
57*0a6a1f1dSLionel Sambuc #if _BYTE_ORDER == _BIG_ENDIAN
58*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 0
59*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    1
60*0a6a1f1dSLionel Sambuc #elif _BYTE_ORDER == _LITTLE_ENDIAN
61*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 1
62*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    0
63*0a6a1f1dSLionel Sambuc #endif /* _BYTE_ORDER */
64*0a6a1f1dSLionel Sambuc 
65*0a6a1f1dSLionel Sambuc #endif /* OpenBSD and Bitrig. */
66*0a6a1f1dSLionel Sambuc 
67*0a6a1f1dSLionel Sambuc /* .. */
68*0a6a1f1dSLionel Sambuc 
69*0a6a1f1dSLionel Sambuc /* Mac OSX has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the compiler (at least with GCC) */
70*0a6a1f1dSLionel Sambuc #if defined(__APPLE__) && defined(__MACH__) || defined(__ellcc__ )
71*0a6a1f1dSLionel Sambuc 
72*0a6a1f1dSLionel Sambuc #ifdef __BIG_ENDIAN__
73*0a6a1f1dSLionel Sambuc #if __BIG_ENDIAN__
74*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 0
75*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    1
76*0a6a1f1dSLionel Sambuc #endif
77*0a6a1f1dSLionel Sambuc #endif /* __BIG_ENDIAN__ */
78*0a6a1f1dSLionel Sambuc 
79*0a6a1f1dSLionel Sambuc #ifdef __LITTLE_ENDIAN__
80*0a6a1f1dSLionel Sambuc #if __LITTLE_ENDIAN__
81*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 1
82*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    0
83*0a6a1f1dSLionel Sambuc #endif
84*0a6a1f1dSLionel Sambuc #endif /* __LITTLE_ENDIAN__ */
85*0a6a1f1dSLionel Sambuc 
86*0a6a1f1dSLionel Sambuc #endif /* Mac OSX */
87*0a6a1f1dSLionel Sambuc 
88*0a6a1f1dSLionel Sambuc /* .. */
89*0a6a1f1dSLionel Sambuc 
90*0a6a1f1dSLionel Sambuc #if defined(__linux__)
91*0a6a1f1dSLionel Sambuc #include <endian.h>
92*0a6a1f1dSLionel Sambuc 
93*0a6a1f1dSLionel Sambuc #if __BYTE_ORDER == __BIG_ENDIAN
94*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 0
95*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    1
96*0a6a1f1dSLionel Sambuc #elif __BYTE_ORDER == __LITTLE_ENDIAN
97*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 1
98*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    0
99*0a6a1f1dSLionel Sambuc #endif /* __BYTE_ORDER */
100*0a6a1f1dSLionel Sambuc 
101*0a6a1f1dSLionel Sambuc #endif /* GNU/Linux */
102*0a6a1f1dSLionel Sambuc 
103*0a6a1f1dSLionel Sambuc /* . */
104*0a6a1f1dSLionel Sambuc 
105*0a6a1f1dSLionel Sambuc #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
106*0a6a1f1dSLionel Sambuc #error Unable to determine endian
107*0a6a1f1dSLionel Sambuc #endif /* Check we found an endianness correctly. */
108*0a6a1f1dSLionel Sambuc 
109*0a6a1f1dSLionel Sambuc #endif /* ENDIANNESS_H */
110