diff options
author | Josh Blum <josh@joshknows.com> | 2010-06-09 00:54:35 +0000 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-06-09 00:54:35 +0000 |
commit | 8985d5c400a5f64dd95c0f0dcf9f793b32bd2d9c (patch) | |
tree | c038d960822b5ca153f4bbf6a4bad075467a2a1f /host/include | |
parent | cd84a19214ea03a3615b5ac7997f33fcfc9870ae (diff) | |
parent | 8c7b73ee536357d2f7efc4558b531575fa28ca31 (diff) | |
download | uhd-8985d5c400a5f64dd95c0f0dcf9f793b32bd2d9c.tar.gz uhd-8985d5c400a5f64dd95c0f0dcf9f793b32bd2d9c.tar.bz2 uhd-8985d5c400a5f64dd95c0f0dcf9f793b32bd2d9c.zip |
Merge branch 'master' of ettus.sourcerepo.com:ettus/uhdpriv into usrp_e
Diffstat (limited to 'host/include')
-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 */ |