[flac-dev] [PATCH] Add configure check for bswap16

Ralph Giles giles at thaumas.net
Tue Nov 4 12:06:20 PST 2014


The gcc version #ifdef fix for bswap16 doesn't work for Apple's clang.
Here's a better fix, which has configure check for it directly.

Fixes build failures on MacOS X.

 -r
-------------- next part --------------
From 05445ca46da8c1c118c8ec3ba34df8ca0f76925d Mon Sep 17 00:00:00 2001
From: Ralph Giles <giles at thaumas.net>
Date: Tue, 4 Nov 2014 11:57:28 -0800
Subject: [PATCH 1/4] Add autoconf macro to check for the bswap16 intrinsic.

---
 m4/bswap.m4 | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/m4/bswap.m4 b/m4/bswap.m4
index 926f820..72af333 100644
--- a/m4/bswap.m4
+++ b/m4/bswap.m4
@@ -1,4 +1,4 @@
-dnl Copyright (C) 2012  Xiph.org Foundation
+dnl Copyright (C) 2012-2014 Xiph.org Foundation
 dnl
 dnl Redistribution and use in source and binary forms, with or without
 dnl modification, are permitted provided that the following conditions
@@ -53,3 +53,30 @@ AC_DEFUN([XIPH_C_BSWAP32],
 
 	)]
 )# XIPH_C_BSWAP32
+
+
+dnl @synopsis XIPH_C_BSWAP16
+dnl
+dnl @author Erik de Castro Lopo <erikd at mega-nerd.com>
+dnl
+dnl Dtermine whether the compiler has the __builtin_bswap16() intrinsic which
+dnl is likely to be present for most versions of GCC as well as Clang.
+
+AC_DEFUN([XIPH_C_BSWAP16],
+[AC_CACHE_CHECK(for bswap16 instrinsic,
+  ac_cv_c_bswap16,
+
+  # Initialize to no
+  ac_cv_c_bswap16=no
+  HAVE_BSWAP16=0
+
+  [AC_TRY_LINK([],
+    return __builtin_bswap16 (0) ;,
+    ac_cv_c_bswap16=yes
+    HAVE_BSWAP16=1
+  )]
+  AC_DEFINE_UNQUOTED(HAVE_BSWAP16, ${HAVE_BSWAP16},
+    [Compiler has the __builtin_bswap16 intrinsic])
+
+  )]
+)# XIPH_C_BSWAP16
-- 
1.8.5.2 (Apple Git-48)
-------------- next part --------------
From 0d4ae3ea6a49df3eb5a1df1ba6550fd1b613579e Mon Sep 17 00:00:00 2001
From: Ralph Giles <giles at thaumas.net>
Date: Tue, 4 Nov 2014 11:58:45 -0800
Subject: [PATCH 2/4] Use a configure check for bswap16 instead of gcc version
 #ifdefs.

Fixes a build problem on apple clang.
---
 configure.ac            | 1 +
 include/share/endswap.h | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index dae619e..3ed4e7f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -67,6 +67,7 @@ AC_CHECK_HEADERS([stdint.h inttypes.h byteswap.h sys/param.h termios.h x86intrin
 AC_HEADER_TIOCGWINSZ
 
 XIPH_C_BSWAP32
+XIPH_C_BSWAP16
 
 ac_cv_c_big_endian=0
 ac_cv_c_little_endian=0
diff --git a/include/share/endswap.h b/include/share/endswap.h
index 86bf857..dece49c 100644
--- a/include/share/endswap.h
+++ b/include/share/endswap.h
@@ -34,7 +34,7 @@
 #if HAVE_BSWAP32			/* GCC and Clang */
 
 /* GCC prior to 4.8 didn't provide bswap16 on x86_64 */
-#if __GNUC__ <= 4 && __GNUC_MINOR__ < 8
+#ifndef HAVE_BSWAP16
 static inline unsigned short __builtin_bswap16(unsigned short a)
 {
 	return (a<<8)|(a>>8);
-- 
1.8.5.2 (Apple Git-48)
-------------- next part --------------
From 55c8e0b2a1c73ffde8c907b39abee08161ccc429 Mon Sep 17 00:00:00 2001
From: Ralph Giles <giles at thaumas.net>
Date: Tue, 4 Nov 2014 11:59:53 -0800
Subject: [PATCH 3/4] Clean up bswap32 autoconf macro.

Improve 'checking' message and don't hog the cache namespace.
---
 m4/bswap.m4 | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/m4/bswap.m4 b/m4/bswap.m4
index 72af333..eec3ee1 100644
--- a/m4/bswap.m4
+++ b/m4/bswap.m4
@@ -36,16 +36,16 @@ dnl Dtermine whether the compiler has the __builtin_bswap32() intrinsic which
 dnl is likely to be present for most versions of GCC as well as Clang.
 
 AC_DEFUN([XIPH_C_BSWAP32],
-[AC_CACHE_CHECK(has bswap32 instrinsic,
-	ac_cv_c_bswap,
+[AC_CACHE_CHECK(for bswap32 instrinsic,
+	ac_cv_c_bswap32,
 
 	# Initialize to no
-	ac_cv_c_bswap=no
+	ac_cv_c_bswap32=no
 	HAVE_BSWAP32=0
 
 	[AC_TRY_LINK([],
 		return __builtin_bswap32 (0) ;,
-			ac_cv_c_bswap=yes
+			ac_cv_c_bswap32=yes
 			HAVE_BSWAP32=1
 			)]
 	AC_DEFINE_UNQUOTED(HAVE_BSWAP32, ${HAVE_BSWAP32},
-- 
1.8.5.2 (Apple Git-48)
-------------- next part --------------
From 0b2f5b4bef8116b27660e24597e915c9fbf2b828 Mon Sep 17 00:00:00 2001
From: Ralph Giles <giles at thaumas.net>
Date: Tue, 4 Nov 2014 12:01:48 -0800
Subject: [PATCH 4/4] Fix indenting on the bswap32 autoconf macro.

We generally prefer spaces to tabs.
---
 m4/bswap.m4 | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/m4/bswap.m4 b/m4/bswap.m4
index eec3ee1..e6793d6 100644
--- a/m4/bswap.m4
+++ b/m4/bswap.m4
@@ -37,21 +37,21 @@ dnl is likely to be present for most versions of GCC as well as Clang.
 
 AC_DEFUN([XIPH_C_BSWAP32],
 [AC_CACHE_CHECK(for bswap32 instrinsic,
-	ac_cv_c_bswap32,
+  ac_cv_c_bswap32,
 
-	# Initialize to no
-	ac_cv_c_bswap32=no
-	HAVE_BSWAP32=0
+  # Initialize to no
+  ac_cv_c_bswap32=no
+  HAVE_BSWAP32=0
 
-	[AC_TRY_LINK([],
-		return __builtin_bswap32 (0) ;,
-			ac_cv_c_bswap32=yes
-			HAVE_BSWAP32=1
-			)]
-	AC_DEFINE_UNQUOTED(HAVE_BSWAP32, ${HAVE_BSWAP32},
-					[Compiler has the __builtin_bswap32 intrinsic])
+  [AC_TRY_LINK([],
+    return __builtin_bswap32 (0) ;,
+    ac_cv_c_bswap32=yes
+    HAVE_BSWAP32=1
+  )]
+  AC_DEFINE_UNQUOTED(HAVE_BSWAP32, ${HAVE_BSWAP32},
+    [Compiler has the __builtin_bswap32 intrinsic])
 
-	)]
+  )]
 )# XIPH_C_BSWAP32
 
 
-- 
1.8.5.2 (Apple Git-48)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
Url : http://lists.xiph.org/pipermail/flac-dev/attachments/20141104/4be918da/attachment.pgp 


More information about the flac-dev mailing list