OverSim
oversim_byteswap.h
Go to the documentation of this file.
1 #ifndef OVERSIM_BYTESWAP_H
2 #define OVERSIM_BYTESWAP_H
3 
4 #if not defined _WIN32 && not defined __APPLE__
5 
6 #include <byteswap.h>
7 
8 #else
9 
10 #if defined __APPLE__
11 #include <libkern/OSByteOrder.h>
12 #define bswap_16(x) OSSwapInt16(x)
13 #define bswap_32(x) OSSwapInt32(x)
14 #define bswap_64(x) OSSwapInt64(x)
15 
16 #else
17 
18 #define bswap_16(x) (((x) << 8) & 0xff00) | (((x) >> 8 ) & 0xff)
19 #define bswap_32(x) (((x) << 24) & 0xff000000) \
20  | (((x) << 8) & 0xff0000) \
21  | (((x) >> 8) & 0xff00) \
22  | (((x) >> 24) & 0xff )
23 #define bswap_64(x) ((((x) & 0xff00000000000000ull) >> 56) \
24  | (((x) & 0x00ff000000000000ull) >> 40) \
25  | (((x) & 0x0000ff0000000000ull) >> 24) \
26  | (((x) & 0x000000ff00000000ull) >> 8) \
27  | (((x) & 0x00000000ff000000ull) << 8) \
28  | (((x) & 0x0000000000ff0000ull) << 24) \
29  | (((x) & 0x000000000000ff00ull) << 40) \
30  | (((x) & 0x00000000000000ffull) << 56))
31 #endif
32 #endif
33 #endif