aboutsummaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-06-08 14:59:51 -0700
committerJosh Blum <josh@joshknows.com>2010-06-08 14:59:51 -0700
commit185971dd625034366b2d1420b74c3de072a90330 (patch)
treefdaa5f8f8805030ca31e0bbe7741910bc2989e0d /host/include
parent37cf8a77e86de2d9247738ed6ce7b2534e66e2f8 (diff)
downloaduhd-185971dd625034366b2d1420b74c3de072a90330.tar.gz
uhd-185971dd625034366b2d1420b74c3de072a90330.tar.bz2
uhd-185971dd625034366b2d1420b74c3de072a90330.zip
extend byteswap routines for macosx, and added case for unknown
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/utils/byteswap.hpp36
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 */