diff options
author | Lennart Poettering <lennart@poettering.net> | 2009-05-19 22:34:43 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2009-05-20 02:09:32 +0200 |
commit | ec901d786f6de6e6f870279e2d955f491619c559 (patch) | |
tree | 9855d127242c9f910dc3d90ddb2e6267929f711d /dbus/dbus-marshal-basic.h | |
parent | 9293e823767daee79386cc797510808f4eed01a3 (diff) | |
download | dbus-ec901d786f6de6e6f870279e2d955f491619c559.tar.gz |
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.
Diffstat (limited to 'dbus/dbus-marshal-basic.h')
-rw-r--r-- | dbus/dbus-marshal-basic.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/dbus/dbus-marshal-basic.h b/dbus/dbus-marshal-basic.h index bcc15ee9..f09c5208 100644 --- a/dbus/dbus-marshal-basic.h +++ b/dbus/dbus-marshal-basic.h @@ -26,6 +26,11 @@ #define DBUS_MARSHAL_BASIC_H #include <config.h> + +#ifdef HAVE_BYTESWAP_H +#include <byteswap.h> +#endif + #include <dbus/dbus-protocol.h> #include <dbus/dbus-types.h> #include <dbus/dbus-arch-deps.h> @@ -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)) |