xref: /minix3/sys/external/bsd/compiler_rt/dist/lib/builtins/int_endianness.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* ===-- int_endianness.h - configuration header for compiler-rt ------------===
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 compiler-rt.
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 INT_ENDIANNESS_H
17*0a6a1f1dSLionel Sambuc #define INT_ENDIANNESS_H
18*0a6a1f1dSLionel Sambuc 
19*0a6a1f1dSLionel Sambuc #if defined(__SVR4) && defined(__sun)
20*0a6a1f1dSLionel Sambuc #include <sys/byteorder.h>
21*0a6a1f1dSLionel Sambuc 
22*0a6a1f1dSLionel Sambuc #if defined(_BIG_ENDIAN)
23*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 0
24*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    1
25*0a6a1f1dSLionel Sambuc #elif defined(_LITTLE_ENDIAN)
26*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 1
27*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    0
28*0a6a1f1dSLionel Sambuc #else /* !_LITTLE_ENDIAN */
29*0a6a1f1dSLionel Sambuc #error "unknown endianness"
30*0a6a1f1dSLionel Sambuc #endif /* !_LITTLE_ENDIAN */
31*0a6a1f1dSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc #endif /* Solaris and AuroraUX. */
33*0a6a1f1dSLionel Sambuc 
34*0a6a1f1dSLionel Sambuc /* .. */
35*0a6a1f1dSLionel Sambuc 
36*0a6a1f1dSLionel Sambuc #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__minix)
37*0a6a1f1dSLionel Sambuc #include <sys/endian.h>
38*0a6a1f1dSLionel Sambuc 
39*0a6a1f1dSLionel Sambuc #if _BYTE_ORDER == _BIG_ENDIAN
40*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 0
41*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    1
42*0a6a1f1dSLionel Sambuc #elif _BYTE_ORDER == _LITTLE_ENDIAN
43*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 1
44*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    0
45*0a6a1f1dSLionel Sambuc #endif /* _BYTE_ORDER */
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc #endif /* *BSD */
48*0a6a1f1dSLionel Sambuc 
49*0a6a1f1dSLionel Sambuc #if defined(__OpenBSD__) || defined(__Bitrig__)
50*0a6a1f1dSLionel Sambuc #include <machine/endian.h>
51*0a6a1f1dSLionel Sambuc 
52*0a6a1f1dSLionel Sambuc #if _BYTE_ORDER == _BIG_ENDIAN
53*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 0
54*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    1
55*0a6a1f1dSLionel Sambuc #elif _BYTE_ORDER == _LITTLE_ENDIAN
56*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 1
57*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    0
58*0a6a1f1dSLionel Sambuc #endif /* _BYTE_ORDER */
59*0a6a1f1dSLionel Sambuc 
60*0a6a1f1dSLionel Sambuc #endif /* OpenBSD and Bitrig. */
61*0a6a1f1dSLionel Sambuc 
62*0a6a1f1dSLionel Sambuc /* .. */
63*0a6a1f1dSLionel Sambuc 
64*0a6a1f1dSLionel Sambuc /* Mac OSX has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the compiler (at least with GCC) */
65*0a6a1f1dSLionel Sambuc #if defined(__APPLE__) || defined(__ellcc__ )
66*0a6a1f1dSLionel Sambuc 
67*0a6a1f1dSLionel Sambuc #ifdef __BIG_ENDIAN__
68*0a6a1f1dSLionel Sambuc #if __BIG_ENDIAN__
69*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 0
70*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    1
71*0a6a1f1dSLionel Sambuc #endif
72*0a6a1f1dSLionel Sambuc #endif /* __BIG_ENDIAN__ */
73*0a6a1f1dSLionel Sambuc 
74*0a6a1f1dSLionel Sambuc #ifdef __LITTLE_ENDIAN__
75*0a6a1f1dSLionel Sambuc #if __LITTLE_ENDIAN__
76*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 1
77*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    0
78*0a6a1f1dSLionel Sambuc #endif
79*0a6a1f1dSLionel Sambuc #endif /* __LITTLE_ENDIAN__ */
80*0a6a1f1dSLionel Sambuc 
81*0a6a1f1dSLionel Sambuc #endif /* Mac OSX */
82*0a6a1f1dSLionel Sambuc 
83*0a6a1f1dSLionel Sambuc /* .. */
84*0a6a1f1dSLionel Sambuc 
85*0a6a1f1dSLionel Sambuc #if defined(__linux__)
86*0a6a1f1dSLionel Sambuc #include <endian.h>
87*0a6a1f1dSLionel Sambuc 
88*0a6a1f1dSLionel Sambuc #if __BYTE_ORDER == __BIG_ENDIAN
89*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 0
90*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    1
91*0a6a1f1dSLionel Sambuc #elif __BYTE_ORDER == __LITTLE_ENDIAN
92*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 1
93*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    0
94*0a6a1f1dSLionel Sambuc #endif /* __BYTE_ORDER */
95*0a6a1f1dSLionel Sambuc 
96*0a6a1f1dSLionel Sambuc #endif /* GNU/Linux */
97*0a6a1f1dSLionel Sambuc 
98*0a6a1f1dSLionel Sambuc #if defined(_WIN32)
99*0a6a1f1dSLionel Sambuc 
100*0a6a1f1dSLionel Sambuc #define _YUGA_LITTLE_ENDIAN 1
101*0a6a1f1dSLionel Sambuc #define _YUGA_BIG_ENDIAN    0
102*0a6a1f1dSLionel Sambuc 
103*0a6a1f1dSLionel Sambuc #endif /* Windows */
104*0a6a1f1dSLionel Sambuc 
105*0a6a1f1dSLionel Sambuc /* . */
106*0a6a1f1dSLionel Sambuc 
107*0a6a1f1dSLionel Sambuc #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
108*0a6a1f1dSLionel Sambuc #error Unable to determine endian
109*0a6a1f1dSLionel Sambuc #endif /* Check we found an endianness correctly. */
110*0a6a1f1dSLionel Sambuc 
111*0a6a1f1dSLionel Sambuc #endif /* INT_ENDIANNESS_H */
112