endian.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * Copyright (c) 1997
  8. * Silicon Graphics Computer Systems, Inc.
  9. *
  10. * Permission to use, copy, modify, distribute and sell this software
  11. * and its documentation for any purpose is hereby granted without fee,
  12. * provided that the above copyright notice appear in all copies and
  13. * that both that copyright notice and this permission notice appear
  14. * in supporting documentation. Silicon Graphics makes no
  15. * representations about the suitability of this software for any
  16. * purpose. It is provided "as is" without express or implied warranty.
  17. */
  18. /*
  19. * Copyright notice reproduced from <boost/detail/limits.hpp>, from
  20. * which this code was originally taken.
  21. *
  22. * Modified by Caleb Epstein to use <endian.h> with GNU libc and to
  23. * defined the BOOST_ENDIAN macro.
  24. */
  25. #ifndef BOOST_DETAIL_ENDIAN_HPP
  26. #define BOOST_DETAIL_ENDIAN_HPP
  27. // GNU libc offers the helpful header <endian.h> which defines
  28. // __BYTE_ORDER
  29. #if defined (__GLIBC__)
  30. # include <endian.h>
  31. # if (__BYTE_ORDER == __LITTLE_ENDIAN)
  32. # define BOOST_LITTLE_ENDIAN
  33. # elif (__BYTE_ORDER == __BIG_ENDIAN)
  34. # define BOOST_BIG_ENDIAN
  35. # elif (__BYTE_ORDER == __PDP_ENDIAN)
  36. # define BOOST_PDP_ENDIAN
  37. # else
  38. # error Unknown machine endianness detected.
  39. # endif
  40. # define BOOST_BYTE_ORDER __BYTE_ORDER
  41. #elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) || \
  42. defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
  43. # define BOOST_BIG_ENDIAN
  44. # define BOOST_BYTE_ORDER 4321
  45. #elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) || \
  46. defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
  47. # define BOOST_LITTLE_ENDIAN
  48. # define BOOST_BYTE_ORDER 1234
  49. #elif defined(__sparc) || defined(__sparc__) \
  50. || defined(_POWER) || defined(__powerpc__) \
  51. || defined(__ppc__) || defined(__hpux) || defined(__hppa) \
  52. || defined(_MIPSEB) || defined(_POWER) \
  53. || defined(__s390__)
  54. # define BOOST_BIG_ENDIAN
  55. # define BOOST_BYTE_ORDER 4321
  56. #elif defined(__i386__) || defined(__alpha__) \
  57. || defined(__ia64) || defined(__ia64__) \
  58. || defined(_M_IX86) || defined(_M_IA64) \
  59. || defined(_M_ALPHA) || defined(__amd64) \
  60. || defined(__amd64__) || defined(_M_AMD64) \
  61. || defined(__x86_64) || defined(__x86_64__) \
  62. || defined(_M_X64) || defined(__bfin__)
  63. # define BOOST_LITTLE_ENDIAN
  64. # define BOOST_BYTE_ORDER 1234
  65. #else
  66. # error The file boost/detail/endian.hpp needs to be set up for your CPU type.
  67. #endif
  68. #endif