oversim_byteswap.h
Go to the documentation of this file.00001 #ifndef OVERSIM_BYTESWAP_H
00002 #define OVERSIM_BYTESWAP_H
00003
00004 #if not defined _WIN32 && not defined __APPLE__
00005
00006 #include <byteswap.h>
00007
00008 #else
00009
00010 #if defined __APPLE__
00011 #include <libkern/OSByteOrder.h>
00012 #define bswap_16(x) OSSwapInt16(x)
00013 #define bswap_32(x) OSSwapInt32(x)
00014 #define bswap_64(x) OSSwapInt64(x)
00015
00016 #else
00017
00018 #define bswap_16(x) (((x) << 8) & 0xff00) | (((x) >> 8 ) & 0xff)
00019 #define bswap_32(x) (((x) << 24) & 0xff000000) \
00020 | (((x) << 8) & 0xff0000) \
00021 | (((x) >> 8) & 0xff00) \
00022 | (((x) >> 24) & 0xff )
00023 #define bswap_64(x) ((((x) & 0xff00000000000000ull) >> 56) \
00024 | (((x) & 0x00ff000000000000ull) >> 40) \
00025 | (((x) & 0x0000ff0000000000ull) >> 24) \
00026 | (((x) & 0x000000ff00000000ull) >> 8) \
00027 | (((x) & 0x00000000ff000000ull) << 8) \
00028 | (((x) & 0x0000000000ff0000ull) << 24) \
00029 | (((x) & 0x000000000000ff00ull) << 40) \
00030 | (((x) & 0x00000000000000ffull) << 56))
00031 #endif
00032 #endif
00033 #endif