diff --git a/simgear/misc/stdint.hxx b/simgear/misc/stdint.hxx index 94fbd60a..49e5817d 100644 --- a/simgear/misc/stdint.hxx +++ b/simgear/misc/stdint.hxx @@ -56,21 +56,42 @@ typedef int ssize_t; inline uint16_t sg_bswap_16(uint16_t x) { +#if defined(__llvm__) || \ + (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && !defined(__ICC) + return __builtin_bswap16(x); +#elif defined(_MSC_VER) && !defined(_DEBUG) + return _byteswap_ushort(x); +#else x = (x >> 8) | (x << 8); return x; +#endif } inline uint32_t sg_bswap_32(uint32_t x) { +#if defined(__llvm__) || \ + (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && !defined(__ICC) + return __builtin_bswap32(x); +#elif defined(_MSC_VER) && !defined(_DEBUG) + return _byteswap_ulong(x); +#else x = ((x >> 8) & 0x00FF00FFL) | ((x << 8) & 0xFF00FF00L); x = (x >> 16) | (x << 16); return x; +#endif } inline uint64_t sg_bswap_64(uint64_t x) { +#if defined(__llvm__) || \ + (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && !defined(__ICC) + return __builtin_bswap64(x); +#elif defined(_MSC_VER) && !defined(_DEBUG) + return _byteswap_uint64(x); +#else x = ((x >> 8) & 0x00FF00FF00FF00FFLL) | ((x << 8) & 0xFF00FF00FF00FF00LL); x = ((x >> 16) & 0x0000FFFF0000FFFFLL) | ((x << 16) & 0xFFFF0000FFFF0000LL); x = (x >> 32) | (x << 32); return x; +#endif }