Skip to content

Commit bdf4fac

Browse files
author
Dale Wilson
committed
Hand code byteswap16(). The intrinsic is not available on gcc 4.7 which is still in common use.
1 parent 8aef3fa commit bdf4fac

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

main/cpp/otf_api/Listener.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@
2424
* builtins for GCC. MSVC has similar ones.
2525
*/
2626

27+
// Some GCC versions do not include __builtin_bswap16
28+
// The compiler optimizes the code below into a single ROL instruction so the intrinsic is not really needed
29+
#define BYTESWAP16(v) (((v) >> 8) | ((v) << 8))
30+
2731
#if defined(WIN32) || defined(_WIN32)
2832
#define BSWAP16(b,v) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : _byteswap_ushort((::uint16_t)v))
2933
#define BSWAP32(b,v) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : _byteswap_ulong((::uint32_t)v))
3034
#define BSWAP64(b,v) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : _byteswap_uint64((::uint64_t)v))
3135
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
32-
#define BSWAP16(b,v) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : __builtin_bswap16((::uint16_t)v))
36+
#define BSWAP16(b,v) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : BYTESWAP16((::uint16_t)v))
3337
#define BSWAP32(b,v) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : __builtin_bswap32((::uint32_t)v))
3438
#define BSWAP64(b,v) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : __builtin_bswap64((::uint64_t)v))
3539
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
36-
#define BSWAP16(b,v) ((b == Ir::SBE_BIG_ENDIAN) ? (v) : __builtin_bswap16((::uint16_t)v))
40+
#define BSWAP16(b,v) ((b == Ir::SBE_BIG_ENDIAN) ? (v) : BYTESWAP16((::uint16_t)v))
3741
#define BSWAP32(b,v) ((b == Ir::SBE_BIG_ENDIAN) ? (v) : __builtin_bswap32((::uint32_t)v))
3842
#define BSWAP64(b,v) ((b == Ir::SBE_BIG_ENDIAN) ? (v) : __builtin_bswap64((::uint64_t)v))
3943
#else

0 commit comments

Comments
 (0)