|
Boost : |
Subject: Re: [boost] License of endian and limits in Boost detail
From: John Maddock (boost.regex_at_[hidden])
Date: 2013-03-19 06:25:21
>>> Actually I suspect that there is really only one way to do this task -
>>> whatever the actual macro
>>> variable names used in the code.
>>>
>>
>> Probably.. FYI.. I worked up an initial implementation in the Predef
>> library over the weekend from the information I could find on-line. Which
>> I
>> suspect is less than what the current endian header has. I'll check it in
>> tonight and ask for feedback as to what's missing and style.
>>
>
> First pass at the Predef header for this at <
> https://raw.github.com/grafikrobot/boost-predef/master/include/boost/predef/endian.h>.
> Currently only tested on my OSX laptop. Would appreciate others trying it
> out. The info is a combination of the indispensable description from
> predef.sf.net (Bjorn Reese et al), known endian specifications I could
> find
> on the architectures I currently detect, and a small amount of general web
> searching.
I haven't looked at your version yet, but here's the start of the
reverse-engineering info:
Output:
~~~~~
* Define BOOST_LITTLE_ENDIAN when little endian.
* Define BOOST_BIG_ENDIAN when big endian.
* Define BOOST_PDP_ENDIAN when PDB endian.
* Emit a #error when endianness can't be possitively determined.
*Define BOOST_BYTE_ORDER to either 1234 (LE) or 4321 (BE).
Post SGI version modifications.
~~~~~~~~~~~~~~~~~~~~~
These are all BSL licensed mods, mostly based on bug reports:
*Issue 7703: check for __BIGENDIAN__ and __LITTLEENDIAN__
* Issue 7528: patch for android:
#if defined( __ANDROID__ )
// Adroid specific code, see: https://svn.boost.org/trac/boost/ticket/7528
// Here we can use machine/_types.h, see:
// http://stackoverflow.com/questions/6212951/endianness-of-android-ndk
# include "machine/_types.h"
# ifdef __ARMEB__
# define BOOST_BIG_ENDIAN
# define BOOST_BYTE_ORDER 4321
# else
# define BOOST_LITTLE_ENDIAN
# define BOOST_BYTE_ORDER 1234
# endif // __ARMEB__
#elif defined( _XBOX )
//
// XBox is always big endian??
//
# define BOOST_BIG_ENDIAN
# define BOOST_BYTE_ORDER 4321
#endif
* Issue 6013. Patch for BSD based systems:
#if defined(__NetBSD__) || defined(__FreeBSD__) || \
defined(__OpenBSD__) || (__DragonFly__)
# if defined(__OpenBSD__)
# include <machine/endian.h>
# else
# include <sys/endian.h>
# endif
# if (_BYTE_ORDER == _LITTLE_ENDIAN)
# define BOOST_LITTLE_ENDIAN
# elif (_BYTE_ORDER == _BIG_ENDIAN)
# define BOOST_BIG_ENDIAN
# elif (_BYTE_ORDER == _PDP_ENDIAN)
# define BOOST_PDP_ENDIAN
# else
# error Unknown machine endianness detected.
# endif
# define BOOST_BYTE_ORDER _BYTE_ORDER
#endif
* Issue 7516: Arm defines __ARMEB__ for big endian and __ARMEL__ for little
endian.
And on Win32 use:
(defined(_WIN32) && defined(__ARM__) && defined(_MSC_VER)) // ARM Windows CE
don't define anything reasonably unique, but there are no big-endian Windows
versions
* Select from STLPort options when available (patch for embedded VC++ plus
STLPort):
defined(_STLP_BIG_ENDIAN) && !defined(_STLP_LITTLE_ENDIAN) -> BE
defined(_STLP_LITTLE_ENDIAN) && !defined(_STLP_BIG_ENDIAN) -> LE
* Issue 2762, check for:
defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) -> BE
defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) -> LE
* REv 57048: defined(__hppa) -> BE
* Issue 2663: defined(__bfin__) -> LE
* Issue 1922: Checking for defined(_BIG_ENDIAN) should be
defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN), similarly for
defined(_LITTLE_ENDIAN)
* REv 35591: defined(__ppc__) || defined(__hpux) -> BE
* Rev 35587: defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) ||
defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) -> LE
* Rev 30185: defined(__ia64) || defined(__ia64__) || defined(_M_IX86) ||
defined(_M_IA64) || defined(_M_ALPHA) -> LE
* Finally, Caleb Epstein's original modification:
#if defined (__GLIBC__)
// GNU libc offers the helpful header <endian.h> which defines
// __BYTE_ORDER
# include <endian.h>
# if (__BYTE_ORDER == __LITTLE_ENDIAN)
# define BOOST_LITTLE_ENDIAN
# elif (__BYTE_ORDER == __BIG_ENDIAN)
# define BOOST_BIG_ENDIAN
# elif (__BYTE_ORDER == __PDP_ENDIAN)
# define BOOST_PDP_ENDIAN
# else
# error Unknown machine endianness detected.
# endif
# define BOOST_BYTE_ORDER __BYTE_ORDER
#endif
John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk