modified: myjupyterlab.sh
[GalaxyCodeBases.git] / etc / Windows / vlmcsd_old_vancepym / endian.h
blob8439ff85d25e24fcbecff39e0fd8204bb30ee282
1 #ifndef __endian_h
2 #define __endian_h
4 #ifndef CONFIG
5 #define CONFIG "config.h"
6 #endif // CONFIG
7 #include CONFIG
9 //
10 // Unaligned access
12 #define UAA16(p, i) (((PACKED16*)p)->val[i])
13 #define UAA32(p, i) (((PACKED32*)p)->val[i])
14 #define UAA64(p, i) (((PACKED64*)p)->val[i])
16 #define UA64(p) UAA64(p, 0)
17 #define UA32(p) UAA32(p, 0)
18 #define UA16(p) UAA16(p, 0)
21 //Byteswap: Use compiler support if available
23 #ifdef __has_builtin // Clang supports this
25 #if __has_builtin(__builtin_bswap16)
26 #define BS16(x) __builtin_bswap16(x)
27 #endif
29 #if __has_builtin(__builtin_bswap32)
30 #define BS32(x) __builtin_bswap32(x)
31 #endif
33 #if __has_builtin(__builtin_bswap64)
34 #define BS64(x) __builtin_bswap64(x)
35 #endif
37 #endif // has_builtin
39 #ifdef __GNUC__ // GNU C >= 4.3 has bswap32 and bswap64. GNU C >= 4.8 also has bswap16
40 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)
42 #ifndef BS32
43 #define BS32(x) __builtin_bswap32(x)
44 #endif
46 #ifndef BS64
47 #define BS64(x) __builtin_bswap64(x)
48 #endif
50 #if (__GNUC__ > 4) || (__GNUC_MINOR__ > 7)
52 #ifndef BS16
53 #define BS16(x) __builtin_bswap16(x)
54 #endif
56 #endif // GNU C > 4.7
57 #endif // __GNUC__ > 4
58 #endif // __GNUC__
61 // Byteorder
63 #if defined(__linux__) || defined(__GLIBC__) || defined(__CYGWIN__)
65 #include <endian.h>
66 #include <byteswap.h>
68 #ifndef BS16
69 #define BS16(x) bswap_16(x)
70 #endif
72 #ifndef BS32
73 #define BS32(x) bswap_32(x)
74 #endif
76 #ifndef BS64
77 #define BS64(x) bswap_64(x)
78 #endif
80 #elif defined(__sun__)
82 #include <sys/byteorder.h>
84 #ifndef BS16
85 #define BS16(x) BSWAP_16(x)
86 #endif
88 #ifndef BS32
89 #define BS32(x) BSWAP_32(x)
90 #endif
92 #ifndef BS64
93 #define BS64(x) BSWAP_64(x)
94 #endif
96 #define __LITTLE_ENDIAN 1234
97 #define __BIG_ENDIAN 4321
99 #ifdef _LITTLE_ENDIAN
100 #define __BYTE_ORDER __LITTLE_ENDIAN
101 #else
102 #define __BYTE_ORDER __BIG_ENDIAN
103 #endif
105 #elif __minix__ || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
107 #include <sys/types.h>
108 #include <sys/endian.h>
110 #define __BYTE_ORDER _BYTE_ORDER
111 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
112 #define __BIG_ENDIAN _BIG_ENDIAN
114 #ifdef __OpenBSD__
116 #ifndef BS16
117 #define BS16 swap16
118 #endif
120 #ifndef BS32
121 #define BS32 swap32
122 #endif
124 #ifndef BS64
125 #define BS64 swap64
126 #endif
128 #else // !__OpenBSD__
130 #ifndef BS16
131 #define BS16 bswap16
132 #endif
134 #ifndef BS32
135 #define BS32 bswap32
136 #endif
138 #ifndef BS64
139 #define BS64 bswap64
140 #endif
142 #endif // !__OpenBSD__
144 #elif defined(__APPLE__)
146 #include <sys/types.h>
147 #include <machine/endian.h>
148 #include <libkern/OSByteOrder.h>
150 #define __BYTE_ORDER _BYTE_ORDER
151 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
152 #define __BIG_ENDIAN _BIG_ENDIAN
154 #ifndef BS16
155 #define BS16 OSSwapInt16
156 #endif
158 #ifndef BS32
159 #define BS32 OSSwapInt32
160 #endif
162 #ifndef BS64
163 #define BS64 OSSwapInt64
164 #endif
166 #elif defined(_WIN32)
168 #define __LITTLE_ENDIAN 1234
169 #define __BIG_ENDIAN 4321
170 #define __BYTE_ORDER __LITTLE_ENDIAN
172 #include <stdlib.h>
174 #ifndef BS16
175 #define BS16 _byteswap_ushort
176 #endif
178 #ifndef BS32
179 #define BS32 _byteswap_ulong
180 #endif
182 #ifndef BS64
183 #define BS64 _byteswap_uint64
184 #endif
186 #endif // Byteorder in different OS
189 #if defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) \
190 && defined(BS16) && defined(BS32) && defined(BS64)
192 #if __BYTE_ORDER == __LITTLE_ENDIAN
194 #define __BE16(x) BS16(x)
195 #define __LE16(x) (x)
196 #define __BE32(x) BS32(x)
197 #define __LE32(x) (x)
198 #define __BE64(x) BS64(x)
199 #define __LE64(x) (x)
201 #else // __BYTE_ORDER == __BIG_ENDIAN
203 #define __BE16(x) (x)
204 #define __LE16(x) BS16(x)
205 #define __BE32(x) (x)
206 #define __LE32(x) BS32(x)
207 #define __BE64(x) (x)
208 #define __LE64(x) BS64(x)
210 #endif // __BYTE_ORDER
212 #define PUT_UAA64BE(p, v, i) ( UAA64(p, i) = __BE64(v) )
213 #define PUT_UAA32BE(p, v, i) ( UAA32(p, i) = __BE32(v) )
214 #define PUT_UAA16BE(p, v, i) ( UAA16(p, i) = __BE16(v) )
216 #define PUT_UAA64LE(p, v, i) ( UAA64(p, i) = __LE64(v) )
217 #define PUT_UAA32LE(p, v, i) ( UAA32(p, i) = __LE32(v) )
218 #define PUT_UAA16LE(p, v, i) ( UAA16(p, i) = __LE16(v) )
220 #define GET_UAA64BE(p, i) __BE64(UAA64(p, i))
221 #define GET_UAA32BE(p, i) __BE32(UAA32(p, i))
222 #define GET_UAA16BE(p, i) __BE16(UAA16(p, i))
224 #define GET_UAA64LE(p, i) __LE64(UAA64(p, i))
225 #define GET_UAA32LE(p, i) __LE32(UAA32(p, i))
226 #define GET_UAA16LE(p, i) __LE16(UAA16(p, i))
228 #define BE16(x) __BE16(x)
229 #define LE16(x) __LE16(x)
230 #define BE32(x) __BE32(x)
231 #define LE32(x) __LE32(x)
232 #define BE64(x) __BE64(x)
233 #define LE64(x) __LE64(x)
235 #else // ! defined(__BYTE_ORDER)
237 extern void PUT_UAA64BE(void *p, unsigned long long v, unsigned int i);
239 extern void PUT_UAA32BE(void *p, unsigned int v, unsigned int i);
241 extern void PUT_UAA16BE(void *p, unsigned short v, unsigned int i);
244 extern void PUT_UAA64LE(void *p, unsigned long long v, unsigned int i);
246 extern void PUT_UAA32LE(void *p, unsigned int v, unsigned int i);
248 extern void PUT_UAA16LE(void *p, unsigned short v, unsigned int i);
251 extern unsigned long long GET_UAA64BE(void *p, unsigned int i);
253 extern unsigned int GET_UAA32BE(void *p, unsigned int i);
255 extern unsigned short GET_UAA16BE(void *p, unsigned int i);
258 extern unsigned long long GET_UAA64LE(void *p, unsigned int i);
260 extern unsigned int GET_UAA32LE(void *p, unsigned int i);
262 extern unsigned short GET_UAA16LE(void *p, unsigned int i);
265 extern unsigned short BE16(unsigned short x);
267 extern unsigned short LE16(unsigned short x);
269 extern unsigned int BE32(unsigned int x);
271 extern unsigned int LE32(unsigned int x);
273 extern unsigned long long BE64(unsigned long long x);
275 extern unsigned long long LE64(unsigned long long x);
277 #endif // defined(__BYTE_ORDER)
280 #define PUT_UA64BE(p, v) PUT_UAA64BE(p, v, 0)
281 #define PUT_UA32BE(p, v) PUT_UAA32BE(p, v, 0)
282 #define PUT_UA16BE(p, v) PUT_UAA16BE(p, v, 0)
284 #define PUT_UA64LE(p, v) PUT_UAA64LE(p, v, 0)
285 #define PUT_UA32LE(p, v) PUT_UAA32LE(p, v, 0)
286 #define PUT_UA16LE(p, v) PUT_UAA16LE(p, v, 0)
288 #define GET_UA64BE(p) GET_UAA64BE(p, 0)
289 #define GET_UA32BE(p) GET_UAA32BE(p, 0)
290 #define GET_UA16BE(p) GET_UAA16BE(p, 0)
292 #define GET_UA64LE(p) GET_UAA64LE(p, 0)
293 #define GET_UA32LE(p) GET_UAA32LE(p, 0)
294 #define GET_UA16LE(p) GET_UAA16LE(p, 0)
296 #endif // __endian_h