aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJessica Hamilton <jessica.l.hamilton@gmail.com>2014-05-04 12:03:11 +1200
committerJessica Hamilton <jessica.l.hamilton@gmail.com>2014-05-27 05:35:38 +1200
commit4ffdf2ed40845d8fb856a1a3ca5b5e74616850e9 (patch)
treea8da7c964b53fe8902db3942bfd59dccd0c32a8f
parent36764b40013b19746e6caa041ab3f5100c84a4c2 (diff)
Use GCC builtins for byte-swapping. Fixes #10800.hrev47269
* 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
-rw-r--r--headers/os/support/ByteOrder.h13
1 files 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
}