Translations: Update the Korean translation.
[xz/debian.git] / m4 / tuklib_integer.m4
blobab9a4056445bb7388fe67b5f076692bddfeb8d7c
2 # SYNOPSIS
4 #   TUKLIB_INTEGER
6 # DESCRIPTION
8 #   Checks for tuklib_integer.h:
9 #     - Endianness
10 #     - Does the compiler or the operating system provide byte swapping macros
11 #     - Does the hardware support fast unaligned access to 16-bit, 32-bit,
12 #       and 64-bit integers
14 # COPYING
16 #   Author: Lasse Collin
18 #   This file has been put into the public domain.
19 #   You can do whatever you want with this file.
22 AC_DEFUN_ONCE([TUKLIB_INTEGER], [
23 AC_REQUIRE([TUKLIB_COMMON])
24 AC_REQUIRE([AC_C_BIGENDIAN])
26 AC_MSG_CHECKING([if __builtin_bswap16/32/64 are supported])
27 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
28                         [[__builtin_bswap16(1);
29                         __builtin_bswap32(1);
30                         __builtin_bswap64(1);]])],
32         AC_DEFINE([HAVE___BUILTIN_BSWAPXX], [1],
33                 [Define to 1 if the GNU C extensions
34                 __builtin_bswap16/32/64 are supported.])
35         AC_MSG_RESULT([yes])
36 ], [
37         AC_MSG_RESULT([no])
39         # Look for other byteswapping methods.
40         AC_CHECK_HEADERS([byteswap.h sys/endian.h sys/byteorder.h], [break])
42         # Even if we have byteswap.h we may lack the specific macros/functions.
43         if test x$ac_cv_header_byteswap_h = xyes ; then
44                 m4_foreach([FUNC], [bswap_16,bswap_32,bswap_64], [
45                         AC_MSG_CHECKING([if FUNC is available])
46                         AC_LINK_IFELSE([AC_LANG_SOURCE([
47 #include <byteswap.h>
48 int
49 main(void)
51         FUNC[](42);
52         return 0;
54                         ])], [
55                                 AC_DEFINE(HAVE_[]m4_toupper(FUNC), [1],
56                                         [Define to 1 if] FUNC [is available.])
57                                 AC_MSG_RESULT([yes])
58                         ], [AC_MSG_RESULT([no])])
60                 ])dnl
61         fi
64 AC_MSG_CHECKING([if unaligned memory access should be used])
65 AC_ARG_ENABLE([unaligned-access], AS_HELP_STRING([--enable-unaligned-access],
66                 [Enable if the system supports *fast* unaligned memory access
67                 with 16-bit, 32-bit, and 64-bit integers. By default,
68                 this is enabled only on x86, x86_64, big endian PowerPC,
69                 and some ARM systems.]),
70         [], [enable_unaligned_access=auto])
71 if test "x$enable_unaligned_access" = xauto ; then
72         # TODO: There may be other architectures, on which unaligned access
73         # is OK.
74         case $host_cpu in
75                 i?86|x86_64|powerpc|powerpc64)
76                         enable_unaligned_access=yes
77                         ;;
78                 arm*|aarch64*)
79                         # On 32-bit and 64-bit ARM, GCC and Clang
80                         # #define __ARM_FEATURE_UNALIGNED if
81                         # unaligned access is supported.
82                         AC_COMPILE_IFELSE([AC_LANG_SOURCE([
83 #ifndef __ARM_FEATURE_UNALIGNED
84 compile error
85 #endif
86 int main(void) { return 0; }
87 ])], [enable_unaligned_access=yes], [enable_unaligned_access=no])
88                         ;;
89                 *)
90                         enable_unaligned_access=no
91                         ;;
92         esac
94 if test "x$enable_unaligned_access" = xyes ; then
95         AC_DEFINE([TUKLIB_FAST_UNALIGNED_ACCESS], [1], [Define to 1 if
96                 the system supports fast unaligned access to 16-bit,
97                 32-bit, and 64-bit integers.])
98         AC_MSG_RESULT([yes])
99 else
100         AC_MSG_RESULT([no])
103 AC_MSG_CHECKING([if unsafe type punning should be used])
104 AC_ARG_ENABLE([unsafe-type-punning],
105         AS_HELP_STRING([--enable-unsafe-type-punning],
106                 [This introduces strict aliasing violations and may result
107                 in broken code. However, this might improve performance in
108                 some cases, especially with old compilers (e.g.
109                 GCC 3 and early 4.x on x86, GCC < 6 on ARMv6 and ARMv7).]),
110         [], [enable_unsafe_type_punning=no])
111 if test "x$enable_unsafe_type_punning" = xyes ; then
112         AC_DEFINE([TUKLIB_USE_UNSAFE_TYPE_PUNNING], [1], [Define to 1 to use
113                 unsafe type punning, e.g. char *x = ...; *(int *)x = 123;
114                 which violates strict aliasing rules and thus is
115                 undefined behavior and might result in broken code.])
116         AC_MSG_RESULT([yes])
117 else
118         AC_MSG_RESULT([no])
121 AC_MSG_CHECKING([if __builtin_assume_aligned is supported])
122 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[__builtin_assume_aligned("", 1);]])],
123         [
124                 AC_DEFINE([HAVE___BUILTIN_ASSUME_ALIGNED], [1],
125                         [Define to 1 if the GNU C extension
126                         __builtin_assume_aligned is supported.])
127                 AC_MSG_RESULT([yes])
128         ], [
129                 AC_MSG_RESULT([no])
130         ])
131 ])dnl