From ec901d786f6de6e6f870279e2d955f491619c559 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 19 May 2009 22:34:43 +0200 Subject: [PATCH] byteswap: make use of glibc specific bytswap primitives glibc knows three bswap_{16|32|64}() calls that internally make use of a gcc extension to implement faster byteswapping. We should make use of it if we can. --- configure.in | 2 ++ dbus/dbus-marshal-basic.h | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/configure.in b/configure.in index c2c6a8c..036679c 100644 --- a/configure.in +++ b/configure.in @@ -679,6 +679,8 @@ AC_CHECK_HEADERS(execinfo.h, [AC_CHECK_FUNCS(backtrace)]) AC_CHECK_HEADERS(errno.h) +AC_CHECK_HEADERS(byteswap.h) + AC_CHECK_HEADERS(unistd.h) # checking for a posix version of getpwnam_r diff --git a/dbus/dbus-marshal-basic.h b/dbus/dbus-marshal-basic.h index bcc15ee..f09c520 100644 --- a/dbus/dbus-marshal-basic.h +++ b/dbus/dbus-marshal-basic.h @@ -26,6 +26,11 @@ #define DBUS_MARSHAL_BASIC_H #include + +#ifdef HAVE_BYTESWAP_H +#include +#endif + #include #include #include @@ -37,6 +42,11 @@ #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN #endif +#ifdef HAVE_BYTESWAP_H +#define DBUS_UINT16_SWAP_LE_BE_CONSTANT(val) bswap_16(val) +#define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) bswap_32(val) +#else /* HAVE_BYTESWAP_H */ + #define DBUS_UINT16_SWAP_LE_BE_CONSTANT(val) ((dbus_uint16_t) ( \ (dbus_uint16_t) ((dbus_uint16_t) (val) >> 8) | \ (dbus_uint16_t) ((dbus_uint16_t) (val) << 8))) @@ -47,8 +57,14 @@ (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >> 8) | \ (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24))) +#endif /* HAVE_BYTESWAP_H */ + #ifdef DBUS_HAVE_INT64 +#ifdef HAVE_BYTESWAP_H +#define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) bswap_64(val) +#else /* HAVE_BYTESWAP_H */ + #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) ((dbus_uint64_t) ( \ (((dbus_uint64_t) (val) & \ (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) | \ @@ -68,6 +84,8 @@ (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56))) #endif /* DBUS_HAVE_INT64 */ +#endif /* HAVE_BYTESWAP_H */ + #define DBUS_UINT16_SWAP_LE_BE(val) (DBUS_UINT16_SWAP_LE_BE_CONSTANT (val)) #define DBUS_INT16_SWAP_LE_BE(val) ((dbus_int16_t)DBUS_UINT16_SWAP_LE_BE_CONSTANT (val)) -- 2.7.4