From 4ffdf2ed40845d8fb856a1a3ca5b5e74616850e9 Mon Sep 17 00:00:00 2001 From: Jessica Hamilton Date: Sun, 4 May 2014 12:03:11 +1200 Subject: [PATCH] Use GCC builtins for byte-swapping. Fixes #10800. * Introduced in gcc-4.3 for at least Intel platforms * On ARM, full support added in gcc-4.8 * Other platforms untested, left as-is * This introduces a breaking change to the ABI for gcc4 --- headers/os/support/ByteOrder.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/headers/os/support/ByteOrder.h b/headers/os/support/ByteOrder.h index 96e996119d..9952769ff4 100644 --- a/headers/os/support/ByteOrder.h +++ b/headers/os/support/ByteOrder.h @@ -111,19 +111,28 @@ typedef enum { #ifdef __cplusplus extern "C" { -#endif +#endif extern status_t swap_data(type_code type, void *data, size_t length, swap_action action); extern bool is_type_swapped(type_code type); - /* Private implementations */ extern double __swap_double(double arg); extern float __swap_float(float arg); +#if (defined(__INTEL__) || defined(__x86_64__)) && GCC_VERSION >= 40300 +#define __swap_int64(arg) __builtin_bswap64(arg) +#define __swap_int32(arg) __builtin_bswap32(arg) +#define __swap_int16(arg) __builtin_bswap16(arg) +#elif defined(__ARM__) && GCC_VERSION >= 40800 +#define __swap_int64(arg) __builtin_bswap64(arg) +#define __swap_int32(arg) __builtin_bswap32(arg) +#define __swap_int16(arg) __builtin_bswap16(arg) +#else extern uint64 __swap_int64(uint64 arg); extern uint32 __swap_int32(uint32 arg); extern uint16 __swap_int16(uint16 arg); +#endif #ifdef __cplusplus }