aboutsummaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2019-12-31 00:18:24 +0200
committerLasse Collin <lasse.collin@tukaani.org>2019-12-31 00:18:24 +0200
commit77bc5bc6dd67056cfd5888520ac930cfc57b4516 (patch)
tree8c9e30726f38ae255629dcf2dd52c0de6be85b24 /m4
parentTests: Hopefully fix test_check.c to work on EBCDIC systems. (diff)
downloadxz-77bc5bc6dd67056cfd5888520ac930cfc57b4516.tar.xz
Revise tuklib_integer.h and .m4.
Add a configure option --enable-unsafe-type-punning to get the old non-conforming memory access methods. It can be useful with old compilers or in some other less typical situations but shouldn't normally be used. Omit the packed struct trick for unaligned access. While it's best in some cases, this is simpler. If the memcpy trick doesn't work, one can request unsafe type punning from configure. Because CRC32/CRC64 code needs fast aligned reads, if no very safe way to do it is found, type punning is used as a fallback. This sucks but since it currently works in practice, it seems to be the least bad option. It's never needed with GCC >= 4.7 or Clang >= 3.6 since these support __builtin_assume_aligned and thus fast aligned access can be done with the memcpy trick. Other things: - Support GCC/Clang __builtin_bswapXX - Cleaner bswap fallback macros - Minor cleanups
Diffstat (limited to 'm4')
-rw-r--r--m4/tuklib_integer.m446
1 files changed, 45 insertions, 1 deletions
diff --git a/m4/tuklib_integer.m4 b/m4/tuklib_integer.m4
index c3c59fe3..dcc83d92 100644
--- a/m4/tuklib_integer.m4
+++ b/m4/tuklib_integer.m4
@@ -45,11 +45,26 @@ main(void)
])dnl
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_ARG_ENABLE([unaligned-access], AS_HELP_STRING([--enable-unaligned-access],
[Enable if the system supports *fast* unaligned memory access
with 16-bit and 32-bit integers. By default, this is enabled
- only on x86, x86_64, and big endian PowerPC.]),
+ only on x86, x86_64, big endian PowerPC,
+ and some ARM systems.]),
[], [enable_unaligned_access=auto])
if test "x$enable_unaligned_access" = xauto ; then
# TODO: There may be other architectures, on which unaligned access
@@ -82,4 +97,33 @@ if test "x$enable_unaligned_access" = xyes ; then
else
AC_MSG_RESULT([no])
fi
+
+AC_MSG_CHECKING([if unsafe type punning should be used])
+AC_ARG_ENABLE([unsafe-type-punning],
+ AS_HELP_STRING([--enable-unsafe-type-punning],
+ [This introduces strict aliasing violations and may result
+ in broken code. However, this might improve performance in
+ some cases, especially with old compilers (e.g.
+ GCC 3 and early 4.x on x86, GCC < 6 on ARMv6 and ARMv7).]),
+ [], [enable_unsafe_type_punning=no])
+if test "x$enable_unsafe_type_punning" = xyes ; then
+ AC_DEFINE([TUKLIB_USE_UNSAFE_TYPE_PUNNING], [1], [Define to 1 to use
+ unsafe type punning, e.g. char *x = ...; *(int *)x = 123;
+ which violates strict aliasing rules and thus is
+ undefined behavior and might result in broken code.])
+ AC_MSG_RESULT([yes])
+else
+ AC_MSG_RESULT([no])
+fi
+
+AC_MSG_CHECKING([if __builtin_assume_aligned is supported])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[__builtin_assume_aligned("", 1);]])],
+ [
+ AC_DEFINE([HAVE___BUILTIN_ASSUME_ALIGNED], [1],
+ [Define to 1 if the GNU C extension
+ __builtin_assume_aligned is supported.])
+ AC_MSG_RESULT([yes])
+ ], [
+ AC_MSG_RESULT([no])
+ ])
])dnl