112852Sgabeblack@google.com// Copyright 2005 Caleb Epstein
212852Sgabeblack@google.com// Copyright 2006 John Maddock
312852Sgabeblack@google.com// Copyright 2010 Rene Rivera
412852Sgabeblack@google.com// Distributed under the Boost Software License, Version 1.0. (See accompany-
512852Sgabeblack@google.com// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
612852Sgabeblack@google.com
712852Sgabeblack@google.com/*
812852Sgabeblack@google.com * Copyright (c) 1997
912852Sgabeblack@google.com * Silicon Graphics Computer Systems, Inc.
1012852Sgabeblack@google.com *
1112852Sgabeblack@google.com * Permission to use, copy, modify, distribute and sell this software
1212852Sgabeblack@google.com * and its documentation for any purpose is hereby granted without fee,
1312852Sgabeblack@google.com * provided that the above copyright notice appear in all copies and
1412852Sgabeblack@google.com * that both that copyright notice and this permission notice appear
1512852Sgabeblack@google.com * in supporting documentation.  Silicon Graphics makes no
1612852Sgabeblack@google.com * representations about the suitability of this software for any
1712852Sgabeblack@google.com * purpose.  It is provided "as is" without express or implied warranty.
1812852Sgabeblack@google.com */
1912852Sgabeblack@google.com
2012852Sgabeblack@google.com/*
2112852Sgabeblack@google.com * Copyright notice reproduced from <sysc/packages/boost/detail/limits.hpp>,
2212852Sgabeblack@google.com * from which this code was originally taken.
2312852Sgabeblack@google.com *
2412852Sgabeblack@google.com * Modified by Caleb Epstein to use <endian.h> with GNU libc and to
2512852Sgabeblack@google.com * defined the SC_BOOST_ENDIAN macro.
2612852Sgabeblack@google.com */
2712852Sgabeblack@google.com
2812852Sgabeblack@google.com#ifndef __SYSTEMC_EXT_UTILS_ENDIAN_HH__
2912852Sgabeblack@google.com#define __SYSTEMC_EXT_UTILS_ENDIAN_HH__
3012852Sgabeblack@google.com
3112852Sgabeblack@google.com// GNU libc offers the helpful header <endian.h> which defines
3212852Sgabeblack@google.com// __BYTE_ORDER
3312852Sgabeblack@google.com
3412852Sgabeblack@google.com#if defined (__GLIBC__)
3512852Sgabeblack@google.com# include <endian.h>
3612852Sgabeblack@google.com# if (__BYTE_ORDER == __LITTLE_ENDIAN)
3712852Sgabeblack@google.com#  define SC_BOOST_LITTLE_ENDIAN
3812852Sgabeblack@google.com# elif (__BYTE_ORDER == __BIG_ENDIAN)
3912852Sgabeblack@google.com#  define SC_BOOST_BIG_ENDIAN
4012852Sgabeblack@google.com# elif (__BYTE_ORDER == __PDP_ENDIAN)
4112852Sgabeblack@google.com#  define SC_BOOST_PDP_ENDIAN
4212852Sgabeblack@google.com# else
4312852Sgabeblack@google.com#  error Unknown machine endianness detected.
4412852Sgabeblack@google.com# endif
4512852Sgabeblack@google.com# define SC_BOOST_BYTE_ORDER __BYTE_ORDER
4612852Sgabeblack@google.com#elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) || \
4712852Sgabeblack@google.com    defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) || \
4812852Sgabeblack@google.com    defined(_STLP_BIG_ENDIAN) && !defined(_STLP_LITTLE_ENDIAN)
4912852Sgabeblack@google.com# define SC_BOOST_BIG_ENDIAN
5012852Sgabeblack@google.com# define SC_BOOST_BYTE_ORDER 4321
5112852Sgabeblack@google.com#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) || \
5212852Sgabeblack@google.com    defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) || \
5312852Sgabeblack@google.com    defined(_STLP_LITTLE_ENDIAN) && !defined(_STLP_BIG_ENDIAN)
5412852Sgabeblack@google.com# define SC_BOOST_LITTLE_ENDIAN
5512852Sgabeblack@google.com# define SC_BOOST_BYTE_ORDER 1234
5612852Sgabeblack@google.com#elif defined(__sparc) || defined(__sparc__) \
5712852Sgabeblack@google.com   || defined(_POWER) || defined(__powerpc__) \
5812852Sgabeblack@google.com   || defined(__ppc__) || defined(__ppc64__) \
5912852Sgabeblack@google.com   || defined(__hpux) || defined(__hppa) \
6012852Sgabeblack@google.com   || defined(_MIPSEB) || defined(_POWER) \
6112852Sgabeblack@google.com   || defined(__s390__)
6212852Sgabeblack@google.com# define SC_BOOST_BIG_ENDIAN
6312852Sgabeblack@google.com# define SC_BOOST_BYTE_ORDER 4321
6412852Sgabeblack@google.com#elif defined(__i386__) || defined(__alpha__) \
6512852Sgabeblack@google.com   || defined(__ia64) || defined(__ia64__) \
6612852Sgabeblack@google.com   || defined(_M_IX86) || defined(_M_IA64) \
6712852Sgabeblack@google.com   || defined(_M_ALPHA) || defined(__amd64) \
6812852Sgabeblack@google.com   || defined(__amd64__) || defined(_M_AMD64) \
6912852Sgabeblack@google.com   || defined(__x86_64) || defined(__x86_64__) \
7013447Sciro.santilli@arm.com   || defined(_M_X64) || defined(__bfin__) \
7113447Sciro.santilli@arm.com   || defined(__arm__) || defined(__aarch64__)
7212852Sgabeblack@google.com
7312852Sgabeblack@google.com# define SC_BOOST_LITTLE_ENDIAN
7412852Sgabeblack@google.com# define SC_BOOST_BYTE_ORDER 1234
7512852Sgabeblack@google.com#else
7612852Sgabeblack@google.com# error The file boost/detail/endian.hpp needs to be set up for your CPU type.
7712852Sgabeblack@google.com#endif
7812852Sgabeblack@google.com
7912852Sgabeblack@google.com
8012852Sgabeblack@google.com#endif // __SYSTEMC_EXT_UTILS_ENDIAN_HH__
81