1 /* ===-- int_endianness.h - configuration header for compiler-rt ------------=== 2 * 3 * The LLVM Compiler Infrastructure 4 * 5 * This file is dual licensed under the MIT and the University of Illinois Open 6 * Source Licenses. See LICENSE.TXT for details. 7 * 8 * ===----------------------------------------------------------------------=== 9 * 10 * This file is a configuration header for compiler-rt. 11 * This file is not part of the interface of this library. 12 * 13 * ===----------------------------------------------------------------------=== 14 */ 15 16 #ifndef INT_ENDIANNESS_H 17 #define INT_ENDIANNESS_H 18 19 #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \ 20 defined(__ORDER_LITTLE_ENDIAN__) 21 22 /* Clang and GCC provide built-in endianness definitions. */ 23 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 24 #define _YUGA_LITTLE_ENDIAN 0 25 #define _YUGA_BIG_ENDIAN 1 26 #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 27 #define _YUGA_LITTLE_ENDIAN 1 28 #define _YUGA_BIG_ENDIAN 0 29 #endif /* __BYTE_ORDER__ */ 30 31 #else /* Compilers other than Clang or GCC. */ 32 33 #if defined(__SVR4) && defined(__sun) 34 #include <sys/byteorder.h> 35 36 #if defined(_BIG_ENDIAN) 37 #define _YUGA_LITTLE_ENDIAN 0 38 #define _YUGA_BIG_ENDIAN 1 39 #elif defined(_LITTLE_ENDIAN) 40 #define _YUGA_LITTLE_ENDIAN 1 41 #define _YUGA_BIG_ENDIAN 0 42 #else /* !_LITTLE_ENDIAN */ 43 #error "unknown endianness" 44 #endif /* !_LITTLE_ENDIAN */ 45 46 #endif /* Solaris and AuroraUX. */ 47 48 /* .. */ 49 50 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \ 51 defined(__minix) 52 #include <sys/endian.h> 53 54 #if _BYTE_ORDER == _BIG_ENDIAN 55 #define _YUGA_LITTLE_ENDIAN 0 56 #define _YUGA_BIG_ENDIAN 1 57 #elif _BYTE_ORDER == _LITTLE_ENDIAN 58 #define _YUGA_LITTLE_ENDIAN 1 59 #define _YUGA_BIG_ENDIAN 0 60 #endif /* _BYTE_ORDER */ 61 62 #endif /* *BSD */ 63 64 #if defined(__OpenBSD__) || defined(__Bitrig__) 65 #include <machine/endian.h> 66 67 #if _BYTE_ORDER == _BIG_ENDIAN 68 #define _YUGA_LITTLE_ENDIAN 0 69 #define _YUGA_BIG_ENDIAN 1 70 #elif _BYTE_ORDER == _LITTLE_ENDIAN 71 #define _YUGA_LITTLE_ENDIAN 1 72 #define _YUGA_BIG_ENDIAN 0 73 #endif /* _BYTE_ORDER */ 74 75 #endif /* OpenBSD and Bitrig. */ 76 77 /* .. */ 78 79 /* Mac OSX has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the 80 * compiler (at least with GCC) */ 81 #if defined(__APPLE__) || defined(__ellcc__ ) 82 83 #ifdef __BIG_ENDIAN__ 84 #if __BIG_ENDIAN__ 85 #define _YUGA_LITTLE_ENDIAN 0 86 #define _YUGA_BIG_ENDIAN 1 87 #endif 88 #endif /* __BIG_ENDIAN__ */ 89 90 #ifdef __LITTLE_ENDIAN__ 91 #if __LITTLE_ENDIAN__ 92 #define _YUGA_LITTLE_ENDIAN 1 93 #define _YUGA_BIG_ENDIAN 0 94 #endif 95 #endif /* __LITTLE_ENDIAN__ */ 96 97 #endif /* Mac OSX */ 98 99 /* .. */ 100 101 #if defined(_WIN32) 102 103 #define _YUGA_LITTLE_ENDIAN 1 104 #define _YUGA_BIG_ENDIAN 0 105 106 #endif /* Windows */ 107 108 #endif /* Clang or GCC. */ 109 110 /* . */ 111 112 #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN) 113 #error Unable to determine endian 114 #endif /* Check we found an endianness correctly. */ 115 116 #endif /* INT_ENDIANNESS_H */