X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Fendian.h;h=e29a4be0599dbc197f5aef72d17b34f9c91cc60e;hb=0eecce98e60a75750cc94d660a22500563d245ad;hp=6d17d691802e709ab041f04e216b832a3da1847b;hpb=de68c8ca57fee0c1128bd7f0cb178803d1ddaa9f;p=casparcg diff --git a/common/endian.h b/common/endian.h index 6d17d6918..e29a4be05 100644 --- a/common/endian.h +++ b/common/endian.h @@ -23,40 +23,58 @@ #pragma once #include +#include +#ifdef _MSC_VER #include +#endif namespace caspar { template -typename std::enable_if::type swap_byte_order( +typename std::enable_if::type swap_byte_order( const T& value) { return value; } template -typename std::enable_if::type swap_byte_order( +typename std::enable_if::type swap_byte_order( const T& value) { +#ifdef _MSC_VER auto swapped = _byteswap_ushort(reinterpret_cast(value)); +#elif __GNUC__ + auto swapped = __builtin_bswap16(value); +#endif + return reinterpret_cast(swapped); } template -typename std::enable_if::type swap_byte_order( +typename std::enable_if::type swap_byte_order( const T& value) { +#ifdef _MSC_VER auto swapped = _byteswap_ulong(reinterpret_cast(value)); - return reinterpret_cast(swapped); +#elif __GNUC__ + auto swapped = __builtin_bswap32(value); +#endif + + return reinterpret_cast(swapped); } template -typename std::enable_if::type swap_byte_order( +typename std::enable_if::type swap_byte_order( const T& value) { +#ifdef _MSC_VER auto swapped = _byteswap_uint64(reinterpret_cast(value)); - return reinterpret_cast(swapped); +#elif __GNUC__ + auto swapped = __builtin_bswap64(value); +#endif + + return reinterpret_cast(swapped); } }