make use of byte swap builtins of gcc if they are available

git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1880 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2007-09-22 00:21:08 +00:00
parent f26de8077d
commit 9db42672d4
2 changed files with 43 additions and 31 deletions

View file

@ -221,6 +221,7 @@ AC_CHECK_HEADERS([windows.h winsock2.h ws2tcpip.h])
# Other
AC_CHECK_HEADERS([sys/ioctl.h])
AC_CHECK_HEADERS([byteswap.h])
#### Typdefs, structures, etc. ####

View file

@ -31,10 +31,21 @@
#error "Please include config.h before including this file!"
#endif
#ifdef HAVE_BYTESWAP_H
#include <byteswap.h>
#endif
#ifdef HAVE_BYTESWAP_H
#define INT16_SWAP(x) ((int16_t) bswap_16((uint16_t) x))
#define UINT16_SWAP(x) ((uint16_t) bswap_16((uint16_t) x))
#define INT32_SWAP(x) ((int32_t) bswap_32((uint32_t) x))
#define UINT32_SWAP(x) ((uint32_t) bswap_32((uint32_t) x))
#else
#define INT16_SWAP(x) ( (int16_t) ( ((uint16_t) x >> 8) | ((uint16_t) x << 8) ) )
#define UINT16_SWAP(x) ( (uint16_t) ( ((uint16_t) x >> 8) | ((uint16_t) x << 8) ) )
#define INT32_SWAP(x) ( (int32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
#define UINT32_SWAP(x) ( (uint32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
#endif
#define MAYBE_INT32_SWAP(c,x) ((c) ? INT32_SWAP(x) : x)
#define MAYBE_UINT32_SWAP(c,x) ((c) ? UINT32_SWAP(x) : x)