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