From d7bfc779c8dff37dfde310f7ef732616656cafbb Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Mon, 6 Feb 2012 07:15:48 +1100 Subject: [PATCH] Add XIPH_BSWAP32 configure macro to detect __builtin_bswap32() intrinsic. --- configure.ac | 2 ++ include/share/endswap.h | 12 ++++++--- m4/bswap.m4 | 55 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 m4/bswap.m4 diff --git a/configure.ac b/configure.ac index af1593b4..549024aa 100644 --- a/configure.ac +++ b/configure.ac @@ -66,6 +66,8 @@ AC_SUBST(HAVE_INTTYPES_H) AC_CHECK_HEADERS(byteswap.h) AC_SUBST(HAVE_BYTESWAP_H) +XIPH_C_BSWAP32 + XIPH_C_FIND_ENDIAN AC_DEFINE_UNQUOTED(CPU_IS_BIG_ENDIAN, ${ac_cv_c_big_endian}, [Target processor is big endian.]) diff --git a/include/share/endswap.h b/include/share/endswap.h index 5262075e..e481d456 100644 --- a/include/share/endswap.h +++ b/include/share/endswap.h @@ -31,16 +31,20 @@ /* It is assumed that this header will be included after "config.h". */ -#if HAVE_BYTESWAP_H +#if HAVE_BSWAP32 /* GCC and Clang */ -#include /* Linux */ - -#define ENDSWAP_INT(x) ((int) bswap_32 (x)) +#define ENDSWAP_INT(x) (__builtin_bswap32 (x)) #elif defined _MSC_VER /* Windows. Apparently in . */ #define ENDSWAP_INT(x) ((int) _byteswap_ulong (x)) +#elif HAVE_BYTESWAP_H /* Linux */ + +#include + +#define ENDSWAP_INT(x) ((int) bswap_32 (x)) + #else #define ENDSWAP_INT(x) ((((x) >> 24) & 0xFF) + (((x) >> 8) & 0xFF00) + (((x) & 0xFF00) << 8) + (((x) & 0xFF) << 24)) diff --git a/m4/bswap.m4 b/m4/bswap.m4 new file mode 100644 index 00000000..926f820e --- /dev/null +++ b/m4/bswap.m4 @@ -0,0 +1,55 @@ +dnl Copyright (C) 2012 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 +dnl are met: +dnl +dnl - Redistributions of source code must retain the above copyright +dnl notice, this list of conditions and the following disclaimer. +dnl +dnl - Redistributions in binary form must reproduce the above copyright +dnl notice, this list of conditions and the following disclaimer in the +dnl documentation and/or other materials provided with the distribution. +dnl +dnl - Neither the name of the Xiph.org Foundation nor the names of its +dnl contributors may be used to endorse or promote products derived from +dnl this software without specific prior written permission. +dnl +dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR +dnl CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +dnl @synopsis XIPH_C_BSWAP32 +dnl +dnl @author Erik de Castro Lopo +dnl +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, + + # Initialize to no + ac_cv_c_bswap=no + HAVE_BSWAP32=0 + + [AC_TRY_LINK([], + return __builtin_bswap32 (0) ;, + ac_cv_c_bswap=yes + HAVE_BSWAP32=1 + )] + AC_DEFINE_UNQUOTED(HAVE_BSWAP32, ${HAVE_BSWAP32}, + [Compiler has the __builtin_bswap32 intrinsic]) + + )] +)# XIPH_C_BSWAP32