Daniel Dunbar | 0a3e350 | 2011-11-15 18:56:21 +0000 | [diff] [blame] | 1 | /* ===-- int_endianness.h - configuration header for compiler-rt ------------=== |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 2 | * |
| 3 | * The LLVM Compiler Infrastructure |
| 4 | * |
Howard Hinnant | 9ad441f | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 5 | * This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | * Source Licenses. See LICENSE.TXT for details. |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 7 | * |
| 8 | * ===----------------------------------------------------------------------=== |
| 9 | * |
Daniel Dunbar | 4467b65 | 2009-10-27 17:48:46 +0000 | [diff] [blame] | 10 | * This file is a configuration header for compiler-rt. |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 11 | * This file is not part of the interface of this library. |
| 12 | * |
| 13 | * ===----------------------------------------------------------------------=== |
| 14 | */ |
| 15 | |
Daniel Dunbar | 0a3e350 | 2011-11-15 18:56:21 +0000 | [diff] [blame] | 16 | #ifndef INT_ENDIANNESS_H |
| 17 | #define INT_ENDIANNESS_H |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 18 | |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 19 | #if defined(__SVR4) && defined(__sun) |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 20 | #include <sys/byteorder.h> |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 21 | |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 22 | #if _BYTE_ORDER == _BIG_ENDIAN |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 23 | #define _YUGA_LITTLE_ENDIAN 0 |
| 24 | #define _YUGA_BIG_ENDIAN 1 |
| 25 | #elif _BYTE_ORDER == _LITTLE_ENDIAN |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 26 | #define _YUGA_LITTLE_ENDIAN 1 |
| 27 | #define _YUGA_BIG_ENDIAN 0 |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 28 | #endif /* _BYTE_ORDER */ |
| 29 | |
| 30 | #endif /* Solaris and AuroraUX. */ |
| 31 | |
| 32 | /* .. */ |
| 33 | |
Eric Christopher | 47a953e | 2012-09-20 06:19:20 +0000 | [diff] [blame^] | 34 | #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__minix) |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 35 | #include <sys/endian.h> |
| 36 | |
| 37 | #if _BYTE_ORDER == _BIG_ENDIAN |
| 38 | #define _YUGA_LITTLE_ENDIAN 0 |
| 39 | #define _YUGA_BIG_ENDIAN 1 |
| 40 | #elif _BYTE_ORDER == _LITTLE_ENDIAN |
| 41 | #define _YUGA_LITTLE_ENDIAN 1 |
| 42 | #define _YUGA_BIG_ENDIAN 0 |
| 43 | #endif /* _BYTE_ORDER */ |
| 44 | |
| 45 | #endif /* *BSD */ |
| 46 | |
Eric Christopher | 47a953e | 2012-09-20 06:19:20 +0000 | [diff] [blame^] | 47 | #if defined(__OpenBSD__) || defined(__Bitrig__) |
| 48 | #include <machine/endian.h> |
| 49 | |
| 50 | #if _BYTE_ORDER == _BIG_ENDIAN |
| 51 | #define _YUGA_LITTLE_ENDIAN 0 |
| 52 | #define _YUGA_BIG_ENDIAN 1 |
| 53 | #elif _BYTE_ORDER == _LITTLE_ENDIAN |
| 54 | #define _YUGA_LITTLE_ENDIAN 1 |
| 55 | #define _YUGA_BIG_ENDIAN 0 |
| 56 | #endif /* _BYTE_ORDER */ |
| 57 | |
| 58 | #endif /* OpenBSD and Bitrig. */ |
| 59 | |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 60 | /* .. */ |
| 61 | |
| 62 | /* Mac OSX has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the compiler (at least with GCC) */ |
Edward O'Callaghan | e8178e2 | 2009-08-18 11:54:44 +0000 | [diff] [blame] | 63 | #if defined(__APPLE__) && defined(__MACH__) || defined(__ellcc__ ) |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 64 | |
| 65 | #ifdef __BIG_ENDIAN__ |
| 66 | #if __BIG_ENDIAN__ |
| 67 | #define _YUGA_LITTLE_ENDIAN 0 |
| 68 | #define _YUGA_BIG_ENDIAN 1 |
| 69 | #endif |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 70 | #endif /* __BIG_ENDIAN__ */ |
| 71 | |
| 72 | #ifdef __LITTLE_ENDIAN__ |
| 73 | #if __LITTLE_ENDIAN__ |
| 74 | #define _YUGA_LITTLE_ENDIAN 1 |
| 75 | #define _YUGA_BIG_ENDIAN 0 |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 76 | #endif |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 77 | #endif /* __LITTLE_ENDIAN__ */ |
| 78 | |
| 79 | #endif /* Mac OSX */ |
| 80 | |
| 81 | /* .. */ |
| 82 | |
Nuno Lopes | 166b783 | 2009-08-09 18:59:21 +0000 | [diff] [blame] | 83 | #if defined(__linux__) |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 84 | #include <endian.h> |
| 85 | |
| 86 | #if __BYTE_ORDER == __BIG_ENDIAN |
| 87 | #define _YUGA_LITTLE_ENDIAN 0 |
| 88 | #define _YUGA_BIG_ENDIAN 1 |
| 89 | #elif __BYTE_ORDER == __LITTLE_ENDIAN |
| 90 | #define _YUGA_LITTLE_ENDIAN 1 |
| 91 | #define _YUGA_BIG_ENDIAN 0 |
| 92 | #endif /* __BYTE_ORDER */ |
| 93 | |
| 94 | #endif /* GNU/Linux */ |
| 95 | |
Anton Korobeynikov | 7e8904f | 2012-01-12 21:13:48 +0000 | [diff] [blame] | 96 | #if defined(_WIN32) |
| 97 | |
| 98 | #define _YUGA_LITTLE_ENDIAN 1 |
| 99 | #define _YUGA_BIG_ENDIAN 0 |
| 100 | |
| 101 | #endif /* Windows */ |
| 102 | |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 103 | /* . */ |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 104 | |
| 105 | #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN) |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 106 | #error Unable to determine endian |
| 107 | #endif /* Check we found an endianness correctly. */ |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 108 | |
Daniel Dunbar | 0a3e350 | 2011-11-15 18:56:21 +0000 | [diff] [blame] | 109 | #endif /* INT_ENDIANNESS_H */ |