blob: 06c53de0bfa9a788314e698cdb998a9fc834513c [file] [log] [blame]
Edward O'Callaghan686fd2a2009-08-05 19:58:45 +00001/* ===-- endianness.h - configuration header for libgcc replacement --------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghan686fd2a2009-08-05 19:58:45 +00007 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file is a configuration header for libgcc replacement.
11 * This file is not part of the interface of this library.
12 *
13 * ===----------------------------------------------------------------------===
14 */
15
16#ifndef ENDIANNESS_H
17#define ENDIANNESS_H
18
Edward O'Callaghanbb119a42009-08-08 02:31:50 +000019/*
20 * Known limitations:
21 * Middle endian systems are not handled currently.
22 */
Edward O'Callaghan686fd2a2009-08-05 19:58:45 +000023
Edward O'Callaghanbb119a42009-08-08 02:31:50 +000024#if defined(__SVR4) && defined(__sun)
Edward O'Callaghan686fd2a2009-08-05 19:58:45 +000025#include <sys/byteorder.h>
Edward O'Callaghan686fd2a2009-08-05 19:58:45 +000026
Edward O'Callaghan686fd2a2009-08-05 19:58:45 +000027#if _BYTE_ORDER == _BIG_ENDIAN
Edward O'Callaghanbb119a42009-08-08 02:31:50 +000028#define _YUGA_LITTLE_ENDIAN 0
29#define _YUGA_BIG_ENDIAN 1
30#elif _BYTE_ORDER == _LITTLE_ENDIAN
Edward O'Callaghan686fd2a2009-08-05 19:58:45 +000031#define _YUGA_LITTLE_ENDIAN 1
32#define _YUGA_BIG_ENDIAN 0
Edward O'Callaghanbb119a42009-08-08 02:31:50 +000033#endif /* _BYTE_ORDER */
34
35#endif /* Solaris and AuroraUX. */
36
37/* .. */
38
Rafael Espindolab7a76d12012-01-05 23:59:42 +000039#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonflyBSD__) || defined(__minix)
Edward O'Callaghanbb119a42009-08-08 02:31:50 +000040#include <sys/endian.h>
41
42#if _BYTE_ORDER == _BIG_ENDIAN
43#define _YUGA_LITTLE_ENDIAN 0
44#define _YUGA_BIG_ENDIAN 1
45#elif _BYTE_ORDER == _LITTLE_ENDIAN
46#define _YUGA_LITTLE_ENDIAN 1
47#define _YUGA_BIG_ENDIAN 0
48#endif /* _BYTE_ORDER */
49
50#endif /* *BSD */
51
52/* .. */
53
Eric Christopher47a953e2012-09-20 06:19:20 +000054#if defined(__OpenBSD__) || defined(__Bitrig__)
55#include <machine/endian.h>
56
57#if _BYTE_ORDER == _BIG_ENDIAN
58#define _YUGA_LITTLE_ENDIAN 0
59#define _YUGA_BIG_ENDIAN 1
60#elif _BYTE_ORDER == _LITTLE_ENDIAN
61#define _YUGA_LITTLE_ENDIAN 1
62#define _YUGA_BIG_ENDIAN 0
63#endif /* _BYTE_ORDER */
64
65#endif /* OpenBSD and Bitrig. */
66
67/* .. */
68
Edward O'Callaghanbb119a42009-08-08 02:31:50 +000069/* Mac OSX has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the compiler (at least with GCC) */
Edward O'Callaghane8178e22009-08-18 11:54:44 +000070#if defined(__APPLE__) && defined(__MACH__) || defined(__ellcc__ )
Edward O'Callaghan686fd2a2009-08-05 19:58:45 +000071
72#ifdef __BIG_ENDIAN__
73#if __BIG_ENDIAN__
74#define _YUGA_LITTLE_ENDIAN 0
75#define _YUGA_BIG_ENDIAN 1
76#endif
Edward O'Callaghanbb119a42009-08-08 02:31:50 +000077#endif /* __BIG_ENDIAN__ */
78
79#ifdef __LITTLE_ENDIAN__
80#if __LITTLE_ENDIAN__
81#define _YUGA_LITTLE_ENDIAN 1
82#define _YUGA_BIG_ENDIAN 0
Edward O'Callaghan686fd2a2009-08-05 19:58:45 +000083#endif
Edward O'Callaghanbb119a42009-08-08 02:31:50 +000084#endif /* __LITTLE_ENDIAN__ */
85
86#endif /* Mac OSX */
87
88/* .. */
89
Edward O'Callaghan6ee8d332009-08-18 11:50:23 +000090#if defined(__linux__)
Edward O'Callaghanbb119a42009-08-08 02:31:50 +000091#include <endian.h>
92
93#if __BYTE_ORDER == __BIG_ENDIAN
94#define _YUGA_LITTLE_ENDIAN 0
95#define _YUGA_BIG_ENDIAN 1
96#elif __BYTE_ORDER == __LITTLE_ENDIAN
97#define _YUGA_LITTLE_ENDIAN 1
98#define _YUGA_BIG_ENDIAN 0
99#endif /* __BYTE_ORDER */
100
101#endif /* GNU/Linux */
102
103/* . */
Edward O'Callaghan686fd2a2009-08-05 19:58:45 +0000104
105#if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
Edward O'Callaghanbb119a42009-08-08 02:31:50 +0000106#error Unable to determine endian
107#endif /* Check we found an endianness correctly. */
Edward O'Callaghan686fd2a2009-08-05 19:58:45 +0000108
109#endif /* ENDIANNESS_H */