aboutsummaryrefslogtreecommitdiff
path: root/m4/longlong.m4
diff options
context:
space:
mode:
Diffstat (limited to 'm4/longlong.m4')
-rw-r--r--m4/longlong.m4119
1 files changed, 92 insertions, 27 deletions
diff --git a/m4/longlong.m4 b/m4/longlong.m4
index 3716c09f6..eefb37c45 100644
--- a/m4/longlong.m4
+++ b/m4/longlong.m4
@@ -1,5 +1,5 @@
1# longlong.m4 serial 8 1# longlong.m4 serial 17
2dnl Copyright (C) 1999-2006 Free Software Foundation, Inc. 2dnl Copyright (C) 1999-2007, 2009-2014 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -7,42 +7,107 @@ dnl with or without modifications, as long as this notice is preserved.
7dnl From Paul Eggert. 7dnl From Paul Eggert.
8 8
9# Define HAVE_LONG_LONG_INT if 'long long int' works. 9# Define HAVE_LONG_LONG_INT if 'long long int' works.
10# This fixes a bug in Autoconf 2.60, but can be removed once we 10# This fixes a bug in Autoconf 2.61, and can be faster
11# assume 2.61 everywhere. 11# than what's in Autoconf 2.62 through 2.68.
12 12
13# Note: If the type 'long long int' exists but is only 32 bits large 13# Note: If the type 'long long int' exists but is only 32 bits large
14# (as on some very old compilers), AC_TYPE_LONG_LONG_INT will not be 14# (as on some very old compilers), HAVE_LONG_LONG_INT will not be
15# defined. In this case you can treat 'long long int' like 'long int'. 15# defined. In this case you can treat 'long long int' like 'long int'.
16 16
17AC_DEFUN([AC_TYPE_LONG_LONG_INT], 17AC_DEFUN([AC_TYPE_LONG_LONG_INT],
18[ 18[
19 AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
19 AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int], 20 AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
20 [AC_LINK_IFELSE( 21 [ac_cv_type_long_long_int=yes
21 [AC_LANG_PROGRAM( 22 if test "x${ac_cv_prog_cc_c99-no}" = xno; then
22 [[long long int ll = 9223372036854775807ll; 23 ac_cv_type_long_long_int=$ac_cv_type_unsigned_long_long_int
23 long long int nll = -9223372036854775807LL; 24 if test $ac_cv_type_long_long_int = yes; then
24 typedef int a[((-9223372036854775807LL < 0 25 dnl Catch a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004.
25 && 0 < 9223372036854775807ll) 26 dnl If cross compiling, assume the bug is not important, since
26 ? 1 : -1)]; 27 dnl nobody cross compiles for this platform as far as we know.
27 int i = 63;]], 28 AC_RUN_IFELSE(
28 [[long long int llmax = 9223372036854775807ll; 29 [AC_LANG_PROGRAM(
29 return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i) 30 [[@%:@include <limits.h>
30 | (llmax / ll) | (llmax % ll));]])], 31 @%:@ifndef LLONG_MAX
31 [ac_cv_type_long_long_int=yes], 32 @%:@ define HALF \
32 [ac_cv_type_long_long_int=no])]) 33 (1LL << (sizeof (long long int) * CHAR_BIT - 2))
34 @%:@ define LLONG_MAX (HALF - 1 + HALF)
35 @%:@endif]],
36 [[long long int n = 1;
37 int i;
38 for (i = 0; ; i++)
39 {
40 long long int m = n << i;
41 if (m >> i != n)
42 return 1;
43 if (LLONG_MAX / 2 < m)
44 break;
45 }
46 return 0;]])],
47 [],
48 [ac_cv_type_long_long_int=no],
49 [:])
50 fi
51 fi])
33 if test $ac_cv_type_long_long_int = yes; then 52 if test $ac_cv_type_long_long_int = yes; then
34 AC_DEFINE([HAVE_LONG_LONG_INT], 1, 53 AC_DEFINE([HAVE_LONG_LONG_INT], [1],
35 [Define to 1 if the system has the type `long long int'.]) 54 [Define to 1 if the system has the type 'long long int'.])
36 fi 55 fi
37]) 56])
38 57
39# This macro is obsolescent and should go away soon. 58# Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works.
40AC_DEFUN([gl_AC_TYPE_LONG_LONG], 59# This fixes a bug in Autoconf 2.61, and can be faster
60# than what's in Autoconf 2.62 through 2.68.
61
62# Note: If the type 'unsigned long long int' exists but is only 32 bits
63# large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT
64# will not be defined. In this case you can treat 'unsigned long long int'
65# like 'unsigned long int'.
66
67AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
41[ 68[
42 AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) 69 AC_CACHE_CHECK([for unsigned long long int],
43 ac_cv_type_long_long=$ac_cv_type_long_long_int 70 [ac_cv_type_unsigned_long_long_int],
44 if test $ac_cv_type_long_long = yes; then 71 [ac_cv_type_unsigned_long_long_int=yes
45 AC_DEFINE(HAVE_LONG_LONG, 1, 72 if test "x${ac_cv_prog_cc_c99-no}" = xno; then
46 [Define if you have the 'long long' type.]) 73 AC_LINK_IFELSE(
74 [_AC_TYPE_LONG_LONG_SNIPPET],
75 [],
76 [ac_cv_type_unsigned_long_long_int=no])
77 fi])
78 if test $ac_cv_type_unsigned_long_long_int = yes; then
79 AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], [1],
80 [Define to 1 if the system has the type 'unsigned long long int'.])
47 fi 81 fi
48]) 82])
83
84# Expands to a C program that can be used to test for simultaneous support
85# of 'long long' and 'unsigned long long'. We don't want to say that
86# 'long long' is available if 'unsigned long long' is not, or vice versa,
87# because too many programs rely on the symmetry between signed and unsigned
88# integer types (excluding 'bool').
89AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET],
90[
91 AC_LANG_PROGRAM(
92 [[/* For now, do not test the preprocessor; as of 2007 there are too many
93 implementations with broken preprocessors. Perhaps this can
94 be revisited in 2012. In the meantime, code should not expect
95 #if to work with literals wider than 32 bits. */
96 /* Test literals. */
97 long long int ll = 9223372036854775807ll;
98 long long int nll = -9223372036854775807LL;
99 unsigned long long int ull = 18446744073709551615ULL;
100 /* Test constant expressions. */
101 typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
102 ? 1 : -1)];
103 typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
104 ? 1 : -1)];
105 int i = 63;]],
106 [[/* Test availability of runtime routines for shift and division. */
107 long long int llmax = 9223372036854775807ll;
108 unsigned long long int ullmax = 18446744073709551615ull;
109 return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
110 | (llmax / ll) | (llmax % ll)
111 | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
112 | (ullmax / ull) | (ullmax % ull));]])
113])