diff options
-rw-r--r-- | host/include/uhd/utils/byteswap.hpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/host/include/uhd/utils/byteswap.hpp b/host/include/uhd/utils/byteswap.hpp index 779b48ec9..dd5dcbc09 100644 --- a/host/include/uhd/utils/byteswap.hpp +++ b/host/include/uhd/utils/byteswap.hpp @@ -57,11 +57,10 @@ namespace uhd{ return _byteswap_uint64(x); } -#elif defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 - #include <byteswap.h> +#elif defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 2 UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ - return bswap_16(x); //no __builtin_bswap16 + return (x>>8) | (x<<8); //DNE return __builtin_bswap16(x); } UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ @@ -72,7 +71,22 @@ namespace uhd{ return __builtin_bswap64(x); } -#else +#elif defined(__FreeBSD__) || defined(__MACOSX__) || defined(__APPLE__) + #include <libkern/OSByteOrder.h> + + UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ + return OSSwapInt16(x); + } + + UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ + return OSSwapInt32(x); + } + + UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ + return OSSwapInt64(x); + } + +#elif defined(linux) || defined(__linux) #include <byteswap.h> UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ @@ -87,6 +101,20 @@ namespace uhd{ return bswap_64(x); } +#else //http://www.koders.com/c/fidB93B34CD44F0ECF724F1A4EAE3854BA2FE692F59.aspx + + UHD_INLINE boost::uint16_t uhd::byteswap(boost::uint16_t x){ + return (x>>8) | (x<<8); + } + + UHD_INLINE boost::uint32_t uhd::byteswap(boost::uint32_t x){ + return (boost::uint32_t(uhd::byteswap(boost::uint16_t(x&0xfffful)))<<16) | (uhd::byteswap(boost::uint16_t(x>>16))); + } + + UHD_INLINE boost::uint64_t uhd::byteswap(boost::uint64_t x){ + return (boost::uint64_t(uhd::byteswap(boost::uint32_t(x&0xffffffffull)))<<32) | (uhd::byteswap(boost::uint32_t(x>>32))); + } + #endif #endif /* INCLUDED_UHD_UTILS_BYTESWAP_HPP */ |