Better vertical alignment
[skeinsum.git] / brg_endian.h
1 /*\r
2  ---------------------------------------------------------------------------\r
3  Copyright (c) 2003, Dr Brian Gladman, Worcester, UK.   All rights reserved.\r
4 \r
5  LICENSE TERMS\r
6 \r
7  The free distribution and use of this software in both source and binary\r
8  form is allowed (with or without changes) provided that:\r
9 \r
10    1. distributions of this source code include the above copyright\r
11       notice, this list of conditions and the following disclaimer;\r
12 \r
13    2. distributions in binary form include the above copyright\r
14       notice, this list of conditions and the following disclaimer\r
15       in the documentation and/or other associated materials;\r
16 \r
17    3. the copyright holder's name is not used to endorse products\r
18       built using this software without specific written permission.\r
19 \r
20  ALTERNATIVELY, provided that this notice is retained in full, this product\r
21  may be distributed under the terms of the GNU General Public License (GPL),\r
22  in which case the provisions of the GPL apply INSTEAD OF those given above.\r
23 \r
24  DISCLAIMER\r
25 \r
26  This software is provided 'as is' with no explicit or implied warranties\r
27  in respect of its properties, including, but not limited to, correctness\r
28  and/or fitness for purpose.\r
29  ---------------------------------------------------------------------------\r
30  Issue 20/10/2006\r
31 */\r
32 \r
33 #ifndef BRG_ENDIAN_H\r
34 #define BRG_ENDIAN_H\r
35 \r
36 #define IS_BIG_ENDIAN      4321 /* byte 0 is most significant (mc68k) */\r
37 #define IS_LITTLE_ENDIAN   1234 /* byte 0 is least significant (i386) */\r
38 \r
39 /* Include files where endian defines and byteswap functions may reside */\r
40 #if defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ )\r
41 #  include <sys/endian.h>\r
42 #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \\r
43       defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ )\r
44 #  include <machine/endian.h>\r
45 #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )\r
46 #  if !defined( __MINGW32__ ) && !defined(AVR)\r
47 #    include <endian.h>\r
48 #    if !defined( __BEOS__ )\r
49 #      include <byteswap.h>\r
50 #    endif\r
51 #  endif\r
52 #endif\r
53 \r
54 /* Now attempt to set the define for platform byte order using any  */\r
55 /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which  */\r
56 /* seem to encompass most endian symbol definitions                 */\r
57 \r
58 #if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN )\r
59 #  if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN\r
60 #    define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN\r
61 #  elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN\r
62 #    define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN\r
63 #  endif\r
64 #elif defined( BIG_ENDIAN )\r
65 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN\r
66 #elif defined( LITTLE_ENDIAN )\r
67 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN\r
68 #endif\r
69 \r
70 #if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN )\r
71 #  if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN\r
72 #    define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN\r
73 #  elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN\r
74 #    define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN\r
75 #  endif\r
76 #elif defined( _BIG_ENDIAN )\r
77 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN\r
78 #elif defined( _LITTLE_ENDIAN )\r
79 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN\r
80 #endif\r
81 \r
82 #if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN )\r
83 #  if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN\r
84 #    define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN\r
85 #  elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN\r
86 #    define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN\r
87 #  endif\r
88 #elif defined( __BIG_ENDIAN )\r
89 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN\r
90 #elif defined( __LITTLE_ENDIAN )\r
91 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN\r
92 #endif\r
93 \r
94 #if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ )\r
95 #  if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__\r
96 #    define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN\r
97 #  elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__\r
98 #    define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN\r
99 #  endif\r
100 #elif defined( __BIG_ENDIAN__ )\r
101 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN\r
102 #elif defined( __LITTLE_ENDIAN__ )\r
103 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN\r
104 #endif\r
105 \r
106 /*  if the platform byte order could not be determined, then try to */\r
107 /*  set this define using common machine defines                    */\r
108 #if !defined(PLATFORM_BYTE_ORDER)\r
109 \r
110 #if   defined( __alpha__ ) || defined( __alpha ) || defined( i386 )       || \\r
111       defined( __i386__ )  || defined( _M_I86 )  || defined( _M_IX86 )    || \\r
112       defined( __OS2__ )   || defined( sun386 )  || defined( __TURBOC__ ) || \\r
113       defined( vax )       || defined( vms )     || defined( VMS )        || \\r
114       defined( __VMS )     || defined( _M_X64 )  || defined( AVR )\r
115 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN\r
116 \r
117 #elif defined( AMIGA )   || defined( applec )    || defined( __AS400__ )  || \\r
118       defined( _CRAY )   || defined( __hppa )    || defined( __hp9000 )   || \\r
119       defined( ibm370 )  || defined( mc68000 )   || defined( m68k )       || \\r
120       defined( __MRC__ ) || defined( __MVS__ )   || defined( __MWERKS__ ) || \\r
121       defined( sparc )   || defined( __sparc)    || defined( SYMANTEC_C ) || \\r
122       defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM )   || \\r
123       defined( THINK_C ) || defined( __VMCMS__ )\r
124 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN\r
125 \r
126 #elif 0     /* **** EDIT HERE IF NECESSARY **** */\r
127 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN\r
128 #elif 0     /* **** EDIT HERE IF NECESSARY **** */\r
129 #  define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN\r
130 #else\r
131 #  error Please edit lines 126 or 128 in brg_endian.h to set the platform byte order\r
132 #endif\r
133 #endif\r
134 \r
135 /* special handler for IA64, which may be either endianness (?)  */\r
136 /* here we assume little-endian, but this may need to be changed */\r
137 #if defined(__ia64) || defined(__ia64__) || defined(_M_IA64)\r
138 #  define PLATFORM_MUST_ALIGN (1)\r
139 #ifndef PLATFORM_BYTE_ORDER\r
140 #  define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN\r
141 #endif\r
142 #endif\r
143 \r
144 #ifndef   PLATFORM_MUST_ALIGN\r
145 #  define PLATFORM_MUST_ALIGN (0)\r
146 #endif\r
147 \r
148 #endif  /* ifndef BRG_ENDIAN_H */\r