Fix bswap16 issue on Debian 6.
authorRalph Giles <giles@thaumas.net>
Wed, 2 Jul 2014 21:12:38 +0000 (14:12 -0700)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Thu, 3 Jul 2014 08:59:49 +0000 (18:59 +1000)
Versions of GCC prior to 4.8 didn't provide an implementation
of __builtin_bswap16 on x86_64. Detect those versions and
supply a fallback implementation. A cleaner fix would be
to detect bswap16 independently of bswap32 in configure
and handle them separately.

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
include/share/endswap.h

index 058fe0b..9a5d86f 100644 (file)
 
 #if HAVE_BSWAP32                       /* GCC and Clang */
 
+/* GCC prior to 4.8 didn't provide bswap16 on x86_64 */
+#if __GNUC__ <= 4 && __GNUC_MINOR__ < 8
+static inline unsigned short __builtin_bswap16(unsigned short a)
+{
+       return (a<<8)|(a>>8);
+}
+#endif
+
 #define        ENDSWAP_16(x)           (__builtin_bswap16 (x))
 #define        ENDSWAP_32(x)           (__builtin_bswap32 (x))