| 1 | /* |
| 2 | --------------------------------------------------------------------------- |
| 3 | Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved. |
| 4 | |
| 5 | The redistribution and use of this software (with or without changes) |
| 6 | is allowed without the payment of fees or royalties provided that: |
| 7 | |
| 8 | source code distributions include the above copyright notice, this |
| 9 | list of conditions and the following disclaimer; |
| 10 | |
| 11 | binary distributions include the above copyright notice, this list |
| 12 | of conditions and the following disclaimer in their documentation. |
| 13 | |
| 14 | This software is provided 'as is' with no explicit or implied warranties |
| 15 | in respect of its operation, including, but not limited to, correctness |
| 16 | and fitness for purpose. |
| 17 | --------------------------------------------------------------------------- |
| 18 | Issue Date: 20/12/2007 |
| 19 | Changes for ARM 9/9/2010 [Downstream relative to Gladman's GitHub, upstream to Qt] |
| 20 | */ |
| 21 | |
| 22 | #ifndef _BRG_ENDIAN_H |
| 23 | #define _BRG_ENDIAN_H |
| 24 | |
| 25 | #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ |
| 26 | #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ |
| 27 | |
| 28 | /* This is needed when using clang with MSVC to avoid including */ |
| 29 | /* endian.h and byteswap.h which are not present on Windows */ |
| 30 | #if defined( _MSC_VER ) && defined( __clang__ ) |
| 31 | # undef __GNUC__ |
| 32 | #endif |
| 33 | |
| 34 | /* Include files where endian defines and byteswap functions may reside */ |
| 35 | #if defined( __sun ) |
| 36 | # include <sys/isa_defs.h> |
| 37 | #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ ) |
| 38 | # include <sys/endian.h> |
| 39 | #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \ |
| 40 | defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ ) |
| 41 | # include <machine/endian.h> |
| 42 | #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ ) |
| 43 | # if !defined( __MINGW32__ ) && !defined( _AIX ) && !defined(Q_OS_QNX) |
| 44 | # include <endian.h> |
| 45 | # if !defined( __BEOS__ ) && !defined(Q_OS_RTEMS) && !defined(Q_OS_VXWORKS) |
| 46 | # include <byteswap.h> |
| 47 | # endif |
| 48 | # endif |
| 49 | #endif |
| 50 | |
| 51 | /* Now attempt to set the define for platform byte order using any */ |
| 52 | /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */ |
| 53 | /* seem to encompass most endian symbol definitions */ |
| 54 | |
| 55 | #if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN ) |
| 56 | # if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN |
| 57 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 58 | # elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN |
| 59 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 60 | # endif |
| 61 | #elif defined( BIG_ENDIAN ) |
| 62 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 63 | #elif defined( LITTLE_ENDIAN ) |
| 64 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 65 | #endif |
| 66 | |
| 67 | #if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN ) |
| 68 | # if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN |
| 69 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 70 | # elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN |
| 71 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 72 | # endif |
| 73 | #elif defined( _BIG_ENDIAN ) |
| 74 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 75 | #elif defined( _LITTLE_ENDIAN ) |
| 76 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 77 | #endif |
| 78 | |
| 79 | #if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN ) |
| 80 | # if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN |
| 81 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 82 | # elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN |
| 83 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 84 | # endif |
| 85 | #elif defined( __BIG_ENDIAN ) |
| 86 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 87 | #elif defined( __LITTLE_ENDIAN ) |
| 88 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 89 | #endif |
| 90 | |
| 91 | #if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ ) |
| 92 | # if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__ |
| 93 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 94 | # elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__ |
| 95 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 96 | # endif |
| 97 | #elif defined( __BIG_ENDIAN__ ) |
| 98 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 99 | #elif defined( __LITTLE_ENDIAN__ ) |
| 100 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 101 | #endif |
| 102 | |
| 103 | /* if the platform byte order could not be determined, then try to */ |
| 104 | /* set this define using common machine defines */ |
| 105 | #if !defined(PLATFORM_BYTE_ORDER) |
| 106 | |
| 107 | #if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \ |
| 108 | defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \ |
| 109 | defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \ |
| 110 | defined( vax ) || defined( vms ) || defined( VMS ) || \ |
| 111 | defined( __VMS ) || defined( _M_X64 ) |
| 112 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 113 | |
| 114 | #elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \ |
| 115 | defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \ |
| 116 | defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \ |
| 117 | defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \ |
| 118 | defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \ |
| 119 | defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \ |
| 120 | defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX ) |
| 121 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 122 | |
| 123 | #elif defined(__arm__) |
| 124 | # ifdef __BIG_ENDIAN |
| 125 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 126 | # else |
| 127 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 128 | # endif |
| 129 | #elif 1 /* **** EDIT HERE IF NECESSARY **** */ |
| 130 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN |
| 131 | #elif 0 /* **** EDIT HERE IF NECESSARY **** */ |
| 132 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN |
| 133 | #else |
| 134 | # error Please edit lines 129 or 131 in brg_endian.h to set the platform byte order |
| 135 | #endif |
| 136 | |
| 137 | #endif |
| 138 | |
| 139 | #endif |
| 140 | |