tuklib_integer.m4: Optimize the check order.

The __builtin byteswapping is the preferred one so check for it first.
This commit is contained in:
Lasse Collin 2020-02-21 01:24:18 +02:00
parent 641042e63f
commit f772a1572f
1 changed files with 29 additions and 27 deletions

View File

@ -7,7 +7,7 @@
# #
# Checks for tuklib_integer.h: # Checks for tuklib_integer.h:
# - Endianness # - Endianness
# - Does operating system provide byte swapping macros # - Does the compiler or the operating system provide byte swapping macros
# - Does the hardware support fast unaligned access to 16-bit # - Does the hardware support fast unaligned access to 16-bit
# and 32-bit integers # and 32-bit integers
# #
@ -22,9 +22,24 @@
AC_DEFUN_ONCE([TUKLIB_INTEGER], [ AC_DEFUN_ONCE([TUKLIB_INTEGER], [
AC_REQUIRE([TUKLIB_COMMON]) AC_REQUIRE([TUKLIB_COMMON])
AC_REQUIRE([AC_C_BIGENDIAN]) AC_REQUIRE([AC_C_BIGENDIAN])
AC_MSG_CHECKING([if __builtin_bswap16/32/64 are supported])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
[[__builtin_bswap16(1);
__builtin_bswap32(1);
__builtin_bswap64(1);]])],
[
AC_DEFINE([HAVE___BUILTIN_BSWAPXX], [1],
[Define to 1 if the GNU C extensions
__builtin_bswap16/32/64 are supported.])
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
# Look for other byteswapping methods.
AC_CHECK_HEADERS([byteswap.h sys/endian.h sys/byteorder.h], [break]) AC_CHECK_HEADERS([byteswap.h sys/endian.h sys/byteorder.h], [break])
# Even if we have byteswap.h, we may lack the specific macros/functions. # Even if we have byteswap.h we may lack the specific macros/functions.
if test x$ac_cv_header_byteswap_h = xyes ; then if test x$ac_cv_header_byteswap_h = xyes ; then
m4_foreach([FUNC], [bswap_16,bswap_32,bswap_64], [ m4_foreach([FUNC], [bswap_16,bswap_32,bswap_64], [
AC_MSG_CHECKING([if FUNC is available]) AC_MSG_CHECKING([if FUNC is available])
@ -44,19 +59,6 @@ main(void)
])dnl ])dnl
fi fi
AC_MSG_CHECKING([if __builtin_bswap16/32/64 are supported])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
[[__builtin_bswap16(1);
__builtin_bswap32(1);
__builtin_bswap64(1);]])],
[
AC_DEFINE([HAVE___BUILTIN_BSWAPXX], [1],
[Define to 1 if the GNU C extensions
__builtin_bswap16/32/64 are supported.])
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
]) ])
AC_MSG_CHECKING([if unaligned memory access should be used]) AC_MSG_CHECKING([if unaligned memory access should be used])