From: Tsuda Kageyu Date: Fri, 13 Nov 2015 01:58:23 +0000 (+0900) Subject: Make use of the Boost Endian library for byte swapping. X-Git-Tag: v1.11beta~153 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6775cef651f01753efff221264112af7f11aa183;p=taglib Make use of the Boost Endian library for byte swapping. It's likely to be better at choosing the most efficient method than our CMake tests. --- diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 5c740756..3fa01bb1 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -108,57 +108,69 @@ endif() # Determine which kind of byte swap functions your compiler supports. check_cxx_source_compiles(" + #include int main() { - __builtin_bswap16(0); - __builtin_bswap32(0); - __builtin_bswap64(0); + boost::endian::endian_reverse(static_cast(1)); + boost::endian::endian_reverse(static_cast(1)); + boost::endian::endian_reverse(static_cast(1)); return 0; } -" HAVE_GCC_BYTESWAP) +" HAVE_BOOST_BYTESWAP) -if(NOT HAVE_GCC_BYTESWAP) +if(NOT HAVE_BOOST_BYTESWAP) check_cxx_source_compiles(" - #include int main() { - __bswap_16(0); - __bswap_32(0); - __bswap_64(0); + __builtin_bswap16(0); + __builtin_bswap32(0); + __builtin_bswap64(0); return 0; } - " HAVE_GLIBC_BYTESWAP) + " HAVE_GCC_BYTESWAP) - if(NOT HAVE_GLIBC_BYTESWAP) + if(NOT HAVE_GCC_BYTESWAP) check_cxx_source_compiles(" - #include + #include int main() { - _byteswap_ushort(0); - _byteswap_ulong(0); - _byteswap_uint64(0); + __bswap_16(0); + __bswap_32(0); + __bswap_64(0); return 0; } - " HAVE_MSC_BYTESWAP) + " HAVE_GLIBC_BYTESWAP) - if(NOT HAVE_MSC_BYTESWAP) + if(NOT HAVE_GLIBC_BYTESWAP) check_cxx_source_compiles(" - #include + #include int main() { - OSSwapInt16(0); - OSSwapInt32(0); - OSSwapInt64(0); + _byteswap_ushort(0); + _byteswap_ulong(0); + _byteswap_uint64(0); return 0; } - " HAVE_MAC_BYTESWAP) + " HAVE_MSC_BYTESWAP) - if(NOT HAVE_MAC_BYTESWAP) + if(NOT HAVE_MSC_BYTESWAP) check_cxx_source_compiles(" - #include + #include int main() { - swap16(0); - swap32(0); - swap64(0); + OSSwapInt16(0); + OSSwapInt32(0); + OSSwapInt64(0); return 0; } - " HAVE_OPENBSD_BYTESWAP) + " HAVE_MAC_BYTESWAP) + + if(NOT HAVE_MAC_BYTESWAP) + check_cxx_source_compiles(" + #include + int main() { + swap16(0); + swap32(0); + swap64(0); + return 0; + } + " HAVE_OPENBSD_BYTESWAP) + endif() endif() endif() endif() diff --git a/config.h.cmake b/config.h.cmake index 12e713fc..55affab6 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -1,6 +1,7 @@ /* config.h. Generated by cmake from config.h.cmake */ /* Defined if your compiler supports some byte swap functions */ +#cmakedefine HAVE_BOOST_BYTESWAP 1 #cmakedefine HAVE_GCC_BYTESWAP 1 #cmakedefine HAVE_GLIBC_BYTESWAP 1 #cmakedefine HAVE_MSC_BYTESWAP 1 diff --git a/taglib/toolkit/tutils.h b/taglib/toolkit/tutils.h index 82f1dd9a..5c204d85 100644 --- a/taglib/toolkit/tutils.h +++ b/taglib/toolkit/tutils.h @@ -31,10 +31,12 @@ #ifndef DO_NOT_DOCUMENT // tell Doxygen not to document this header #ifdef HAVE_CONFIG_H -#include +# include #endif -#if defined(HAVE_MSC_BYTESWAP) +#if defined(HAVE_BOOST_BYTESWAP) +# include +#elif defined(HAVE_MSC_BYTESWAP) # include #elif defined(HAVE_GLIBC_BYTESWAP) # include @@ -59,7 +61,11 @@ namespace TagLib */ inline ushort byteSwap(ushort x) { -#if defined(HAVE_GCC_BYTESWAP) +#if defined(HAVE_BOOST_BYTESWAP) + + return boost::endian::endian_reverse(x); + +#elif defined(HAVE_GCC_BYTESWAP) return __builtin_bswap16(x); @@ -91,7 +97,11 @@ namespace TagLib */ inline uint byteSwap(uint x) { -#if defined(HAVE_GCC_BYTESWAP) +#if defined(HAVE_BOOST_BYTESWAP) + + return boost::endian::endian_reverse(x); + +#elif defined(HAVE_GCC_BYTESWAP) return __builtin_bswap32(x); @@ -126,7 +136,11 @@ namespace TagLib */ inline ulonglong byteSwap(ulonglong x) { -#if defined(HAVE_GCC_BYTESWAP) +#if defined(HAVE_BOOST_BYTESWAP) + + return boost::endian::endian_reverse(x); + +#elif defined(HAVE_GCC_BYTESWAP) return __builtin_bswap64(x);