Created
April 6, 2013 06:14
-
-
Save hideo55/5325084 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* NO-OP for little-endian platforms */ | |
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) | |
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ | |
# define BYTESWAP(x) (x) | |
# endif | |
/* if __BYTE_ORDER__ is not predefined (like FreeBSD), use arch */ | |
#elif defined(__i386) || defined(__x86_64) \ | |
|| defined(__alpha) || defined(__vax) | |
# define BYTESWAP(x) (x) | |
/* use __builtin_bswap32 if available */ | |
#elif defined(__GNUC__) || defined(__clang__) | |
#ifdef __has_builtin | |
#if __has_builtin(__builtin_bswap32) | |
#define BYTESWAP(x) __builtin_bswap32(x) | |
#endif // __has_builtin(__builtin_bswap32) | |
#endif // __has_builtin | |
#endif // defined(__GNUC__) || defined(__clang__) | |
/* last resort (big-endian w/o __builtin_bswap) */ | |
#ifndef BYTESWAP | |
# define BYTESWAP(x) ((((x)&0xFF)<<24) \ | |
|(((x)>>24)&0xFF) \ | |
|(((x)&0x0000FF00)<<8) \ | |
|(((x)&0x00FF0000)>>8) ) | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment