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