Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // Copyright 2005 Caleb Epstein |
| 2 | // Copyright 2006 John Maddock |
| 3 | // Copyright 2010 Rene Rivera |
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompany- |
| 5 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | |
| 7 | /* |
| 8 | * Copyright (c) 1997 |
| 9 | * Silicon Graphics Computer Systems, Inc. |
| 10 | * |
| 11 | * Permission to use, copy, modify, distribute and sell this software |
| 12 | * and its documentation for any purpose is hereby granted without fee, |
| 13 | * provided that the above copyright notice appear in all copies and |
| 14 | * that both that copyright notice and this permission notice appear |
| 15 | * in supporting documentation. Silicon Graphics makes no |
| 16 | * representations about the suitability of this software for any |
| 17 | * purpose. It is provided "as is" without express or implied warranty. |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * Copyright notice reproduced from <ndnboost/detail/limits.hpp>, from |
| 22 | * which this code was originally taken. |
| 23 | * |
| 24 | * Modified by Caleb Epstein to use <endian.h> with GNU libc and to |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 25 | * defined the NDNBOOST_ENDIAN macro. |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 26 | */ |
| 27 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 28 | #ifndef NDNBOOST_DETAIL_ENDIAN_HPP |
| 29 | #define NDNBOOST_DETAIL_ENDIAN_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 30 | |
| 31 | // |
| 32 | // Special cases come first: |
| 33 | // |
| 34 | #if defined (__GLIBC__) |
| 35 | // GNU libc offers the helpful header <endian.h> which defines |
| 36 | // __BYTE_ORDER |
| 37 | # include <endian.h> |
| 38 | # if (__BYTE_ORDER == __LITTLE_ENDIAN) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 39 | # define NDNBOOST_LITTLE_ENDIAN |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 40 | # elif (__BYTE_ORDER == __BIG_ENDIAN) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 41 | # define NDNBOOST_BIG_ENDIAN |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 42 | # elif (__BYTE_ORDER == __PDP_ENDIAN) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 43 | # define NDNBOOST_PDP_ENDIAN |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 44 | # else |
| 45 | # error Unknown machine endianness detected. |
| 46 | # endif |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 47 | # define NDNBOOST_BYTE_ORDER __BYTE_ORDER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 48 | |
| 49 | #elif defined(__NetBSD__) || defined(__FreeBSD__) || \ |
| 50 | defined(__OpenBSD__) || (__DragonFly__) |
| 51 | // |
| 52 | // BSD has endian.h, see https://svn.boost.org/trac/boost/ticket/6013 |
| 53 | # if defined(__OpenBSD__) |
| 54 | # include <machine/endian.h> |
| 55 | # else |
| 56 | # include <sys/endian.h> |
| 57 | # endif |
| 58 | # if (_BYTE_ORDER == _LITTLE_ENDIAN) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 59 | # define NDNBOOST_LITTLE_ENDIAN |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 60 | # elif (_BYTE_ORDER == _BIG_ENDIAN) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 61 | # define NDNBOOST_BIG_ENDIAN |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 62 | # elif (_BYTE_ORDER == _PDP_ENDIAN) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 63 | # define NDNBOOST_PDP_ENDIAN |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 64 | # else |
| 65 | # error Unknown machine endianness detected. |
| 66 | # endif |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 67 | # define NDNBOOST_BYTE_ORDER _BYTE_ORDER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 68 | |
| 69 | #elif defined( __ANDROID__ ) |
| 70 | // Adroid specific code, see: https://svn.boost.org/trac/boost/ticket/7528 |
| 71 | // Here we can use machine/_types.h, see: |
| 72 | // http://stackoverflow.com/questions/6212951/endianness-of-android-ndk |
| 73 | # include "machine/_types.h" |
| 74 | # ifdef __ARMEB__ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 75 | # define NDNBOOST_BIG_ENDIAN |
| 76 | # define NDNBOOST_BYTE_ORDER 4321 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 77 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 78 | # define NDNBOOST_LITTLE_ENDIAN |
| 79 | # define NDNBOOST_BYTE_ORDER 1234 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 80 | # endif // __ARMEB__ |
| 81 | |
| 82 | #elif defined( _XBOX ) |
| 83 | // |
| 84 | // XBox is always big endian?? |
| 85 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 86 | # define NDNBOOST_BIG_ENDIAN |
| 87 | # define NDNBOOST_BYTE_ORDER 4321 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 88 | |
| 89 | #elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) || \ |
| 90 | defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) || \ |
| 91 | defined(__BIGENDIAN__) && !defined(__LITTLEENDIAN__) || \ |
| 92 | defined(_STLP_BIG_ENDIAN) && !defined(_STLP_LITTLE_ENDIAN) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 93 | # define NDNBOOST_BIG_ENDIAN |
| 94 | # define NDNBOOST_BYTE_ORDER 4321 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 95 | #elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) || \ |
| 96 | defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) || \ |
| 97 | defined(__LITTLEENDIAN__) && !defined(__BIGENDIAN__) || \ |
| 98 | defined(_STLP_LITTLE_ENDIAN) && !defined(_STLP_BIG_ENDIAN) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 99 | # define NDNBOOST_LITTLE_ENDIAN |
| 100 | # define NDNBOOST_BYTE_ORDER 1234 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 101 | #elif defined(__sparc) || defined(__sparc__) \ |
| 102 | || defined(_POWER) || defined(__powerpc__) \ |
| 103 | || defined(__ppc__) || defined(__hpux) || defined(__hppa) \ |
| 104 | || defined(_MIPSEB) || defined(_POWER) \ |
| 105 | || defined(__s390__) || defined(__ARMEB__) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 106 | # define NDNBOOST_BIG_ENDIAN |
| 107 | # define NDNBOOST_BYTE_ORDER 4321 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 108 | #elif defined(__i386__) || defined(__alpha__) \ |
| 109 | || defined(__ia64) || defined(__ia64__) \ |
| 110 | || defined(_M_IX86) || defined(_M_IA64) \ |
| 111 | || defined(_M_ALPHA) || defined(__amd64) \ |
| 112 | || defined(__amd64__) || defined(_M_AMD64) \ |
| 113 | || defined(__x86_64) || defined(__x86_64__) \ |
| 114 | || defined(_M_X64) || defined(__bfin__) \ |
| 115 | || defined(__ARMEL__) \ |
| 116 | || (defined(_WIN32) && defined(__ARM__) && defined(_MSC_VER)) // ARM Windows CE don't define anything reasonably unique, but there are no big-endian Windows versions |
| 117 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 118 | # define NDNBOOST_LITTLE_ENDIAN |
| 119 | # define NDNBOOST_BYTE_ORDER 1234 |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 120 | #else |
Jeff Thompson | 9939dcd | 2013-10-15 15:12:24 -0700 | [diff] [blame] | 121 | # error The file ndnboost/detail/endian.hpp needs to be set up for your CPU type. |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 122 | #endif |
| 123 | |
| 124 | |
| 125 | #endif |
| 126 | |