endian: remove templates from bswap

It's too hard to trace problems with callers if we use templates here
(most of the callgraph gets truncated so we can't even tell who's
calling us).
This commit is contained in:
Danny Robson 2018-12-15 15:35:27 +11:00
parent 07e66f20d3
commit b0311f9cd4

View File

@ -17,15 +17,10 @@
namespace cruft {
//-------------------------------------------------------------------------
template <typename T>
constexpr T
bswap (T) noexcept;
// CXX: Update using "if constexpr" when available. It doesn't seem to be
// worth the dicking about to use enable_if_t to differentiate the
// signed/unsigned cases.
#define SIGNED_BSWAP(S) \
template <> \
constexpr \
int##S##_t \
bswap (int##S##_t v) noexcept { \
@ -41,12 +36,12 @@ namespace cruft {
SIGNED_BSWAP(32)
SIGNED_BSWAP(64)
template <> constexpr int8_t bswap ( int8_t v) noexcept { return v; }
template <> constexpr uint8_t bswap (uint8_t v) noexcept { return v; }
constexpr int8_t bswap ( int8_t v) noexcept { return v; }
constexpr uint8_t bswap (uint8_t v) noexcept { return v; }
template <> constexpr uint16_t bswap (uint16_t v) noexcept { return __builtin_bswap16 (v); }
template <> constexpr uint32_t bswap (uint32_t v) noexcept { return __builtin_bswap32 (v); }
template <> constexpr uint64_t bswap (uint64_t v) noexcept { return __builtin_bswap64 (v); }
constexpr uint16_t bswap (uint16_t v) noexcept { return __builtin_bswap16 (v); }
constexpr uint32_t bswap (uint32_t v) noexcept { return __builtin_bswap32 (v); }
constexpr uint64_t bswap (uint64_t v) noexcept { return __builtin_bswap64 (v); }
// use a type-punning union to punt the byte swapping operation to the
@ -54,7 +49,6 @@ namespace cruft {
//
// this is debatably safe under production compilers like gcc + clang
// despite what the standard may say about unions.
template <>
constexpr float
bswap (float v) noexcept
{