aboutsummaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2020-02-21 01:24:18 +0200
committerLasse Collin <lasse.collin@tukaani.org>2020-02-21 01:24:18 +0200
commit524c2f12c762032b819757aeda8af7c47c4cabce (patch)
treeb292709bf7df1d2c1056423a9d59d67f17b6cbf5 /m4
parenttuklib_exit: Add missing header. (diff)
downloadxz-524c2f12c762032b819757aeda8af7c47c4cabce.tar.xz
tuklib_integer.m4: Optimize the check order.
The __builtin byteswapping is the preferred one so check for it first.
Diffstat (limited to 'm4')
-rw-r--r--m4/tuklib_integer.m456
1 files changed, 29 insertions, 27 deletions
diff --git a/m4/tuklib_integer.m4 b/m4/tuklib_integer.m4
index dcc83d92..e9741ef6 100644
--- a/m4/tuklib_integer.m4
+++ b/m4/tuklib_integer.m4
@@ -7,7 +7,7 @@
#
# Checks for tuklib_integer.h:
# - 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
# and 32-bit integers
#
@@ -22,13 +22,28 @@
AC_DEFUN_ONCE([TUKLIB_INTEGER], [
AC_REQUIRE([TUKLIB_COMMON])
AC_REQUIRE([AC_C_BIGENDIAN])
-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.
-if test x$ac_cv_header_byteswap_h = xyes ; then
- m4_foreach([FUNC], [bswap_16,bswap_32,bswap_64], [
- AC_MSG_CHECKING([if FUNC is available])
- AC_LINK_IFELSE([AC_LANG_SOURCE([
+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])
+
+ # Even if we have byteswap.h we may lack the specific macros/functions.
+ if test x$ac_cv_header_byteswap_h = xyes ; then
+ m4_foreach([FUNC], [bswap_16,bswap_32,bswap_64], [
+ AC_MSG_CHECKING([if FUNC is available])
+ AC_LINK_IFELSE([AC_LANG_SOURCE([
#include <byteswap.h>
int
main(void)
@@ -36,28 +51,15 @@ main(void)
FUNC[](42);
return 0;
}
- ])], [
- AC_DEFINE(HAVE_[]m4_toupper(FUNC), [1],
+ ])], [
+ AC_DEFINE(HAVE_[]m4_toupper(FUNC), [1],
[Define to 1 if] FUNC [is available.])
- AC_MSG_RESULT([yes])
- ], [AC_MSG_RESULT([no])])
-
- ])dnl
-fi
+ AC_MSG_RESULT([yes])
+ ], [AC_MSG_RESULT([no])])
-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])
- ])
+ ])dnl
+ fi
+])
AC_MSG_CHECKING([if unaligned memory access should be used])
AC_ARG_ENABLE([unaligned-access], AS_HELP_STRING([--enable-unaligned-access],