From 185971dd625034366b2d1420b74c3de072a90330 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 8 Jun 2010 14:59:51 -0700 Subject: extend byteswap routines for macosx, and added case for unknown --- host/include/uhd/utils/byteswap.hpp | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'host/include') 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 +#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 + + 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 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 */ -- cgit v1.2.3