1 //===-- int_endianness.h - configuration header for compiler-rt -----------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a configuration header for compiler-rt.
10 // This file is not part of the interface of this library.
12 //===----------------------------------------------------------------------===//
14 #ifndef INT_ENDIANNESS_H
15 #define INT_ENDIANNESS_H
17 #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
18 defined(__ORDER_LITTLE_ENDIAN__)
20 // Clang and GCC provide built-in endianness definitions.
21 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
22 #define _YUGA_LITTLE_ENDIAN 0
23 #define _YUGA_BIG_ENDIAN 1
24 #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
25 #define _YUGA_LITTLE_ENDIAN 1
26 #define _YUGA_BIG_ENDIAN 0
27 #endif // __BYTE_ORDER__
29 #else // Compilers other than Clang or GCC.
31 #if defined(__SVR4) && defined(__sun)
32 #include <sys/byteorder.h>
34 #if defined(_BIG_ENDIAN)
35 #define _YUGA_LITTLE_ENDIAN 0
36 #define _YUGA_BIG_ENDIAN 1
37 #elif defined(_LITTLE_ENDIAN)
38 #define _YUGA_LITTLE_ENDIAN 1
39 #define _YUGA_BIG_ENDIAN 0
40 #else // !_LITTLE_ENDIAN
41 #error "unknown endianness"
42 #endif // !_LITTLE_ENDIAN
48 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
50 #include <sys/endian.h>
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
62 #if defined(__OpenBSD__)
63 #include <machine/endian.h>
65 #if _BYTE_ORDER == _BIG_ENDIAN
66 #define _YUGA_LITTLE_ENDIAN 0
67 #define _YUGA_BIG_ENDIAN 1
68 #elif _BYTE_ORDER == _LITTLE_ENDIAN
69 #define _YUGA_LITTLE_ENDIAN 1
70 #define _YUGA_BIG_ENDIAN 0
77 // Mac OSX has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the
78 // compiler (at least with GCC)
79 #if defined(__APPLE__) || defined(__ellcc__)
83 #define _YUGA_LITTLE_ENDIAN 0
84 #define _YUGA_BIG_ENDIAN 1
86 #endif // __BIG_ENDIAN__
88 #ifdef __LITTLE_ENDIAN__
90 #define _YUGA_LITTLE_ENDIAN 1
91 #define _YUGA_BIG_ENDIAN 0
93 #endif // __LITTLE_ENDIAN__
101 #define _YUGA_LITTLE_ENDIAN 1
102 #define _YUGA_BIG_ENDIAN 0
106 #endif // Clang or GCC.
110 #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
111 #error Unable to determine endian
112 #endif // Check we found an endianness correctly.
114 #endif // INT_ENDIANNESS_H