Update Gnulib to the latest git version
[deliverable/binutils-gdb.git] / gnulib / import / m4 / longlong.m4
CommitLineData
c0c3707f
CB
1# longlong.m4 serial 18
2dnl Copyright (C) 1999-2007, 2009-2019 Free Software Foundation, Inc.
f6ea5628
DJ
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Paul Eggert.
8
c0c3707f
CB
9AC_PREREQ([2.62])
10
f6ea5628 11# Define HAVE_LONG_LONG_INT if 'long long int' works.
c0c3707f 12# This can be faster than what's in Autoconf 2.62 through 2.68.
f6ea5628
DJ
13
14# Note: If the type 'long long int' exists but is only 32 bits large
15# (as on some very old compilers), HAVE_LONG_LONG_INT will not be
16# defined. In this case you can treat 'long long int' like 'long int'.
17
18AC_DEFUN([AC_TYPE_LONG_LONG_INT],
19[
770d76d7 20 AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
f6ea5628 21 AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
770d76d7
PA
22 [ac_cv_type_long_long_int=yes
23 if test "x${ac_cv_prog_cc_c99-no}" = xno; then
24 ac_cv_type_long_long_int=$ac_cv_type_unsigned_long_long_int
25 if test $ac_cv_type_long_long_int = yes; then
26 dnl Catch a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004.
27 dnl If cross compiling, assume the bug is not important, since
28 dnl nobody cross compiles for this platform as far as we know.
29 AC_RUN_IFELSE(
30 [AC_LANG_PROGRAM(
31 [[@%:@include <limits.h>
32 @%:@ifndef LLONG_MAX
33 @%:@ define HALF \
34 (1LL << (sizeof (long long int) * CHAR_BIT - 2))
35 @%:@ define LLONG_MAX (HALF - 1 + HALF)
36 @%:@endif]],
37 [[long long int n = 1;
38 int i;
39 for (i = 0; ; i++)
40 {
41 long long int m = n << i;
42 if (m >> i != n)
43 return 1;
44 if (LLONG_MAX / 2 < m)
45 break;
46 }
47 return 0;]])],
48 [],
49 [ac_cv_type_long_long_int=no],
50 [:])
51 fi
52 fi])
f6ea5628 53 if test $ac_cv_type_long_long_int = yes; then
f434ba03 54 AC_DEFINE([HAVE_LONG_LONG_INT], [1],
770d76d7 55 [Define to 1 if the system has the type 'long long int'.])
f6ea5628
DJ
56 fi
57])
58
59# Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works.
c0c3707f 60# This can be faster than what's in Autoconf 2.62 through 2.68.
f6ea5628
DJ
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],
68[
69 AC_CACHE_CHECK([for unsigned long long int],
70 [ac_cv_type_unsigned_long_long_int],
770d76d7
PA
71 [ac_cv_type_unsigned_long_long_int=yes
72 if test "x${ac_cv_prog_cc_c99-no}" = xno; then
73 AC_LINK_IFELSE(
74 [_AC_TYPE_LONG_LONG_SNIPPET],
75 [],
76 [ac_cv_type_unsigned_long_long_int=no])
77 fi])
f6ea5628 78 if test $ac_cv_type_unsigned_long_long_int = yes; then
f434ba03 79 AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], [1],
770d76d7 80 [Define to 1 if the system has the type 'unsigned long long int'.])
f6ea5628
DJ
81 fi
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
f434ba03
PA
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. */
f6ea5628
DJ
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)
f434ba03 102 ? 1 : -1)];
f6ea5628 103 typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
f434ba03 104 ? 1 : -1)];
f6ea5628
DJ
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)
f434ba03
PA
110 | (llmax / ll) | (llmax % ll)
111 | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
112 | (ullmax / ull) | (ullmax % ull));]])
f6ea5628 113])
This page took 0.967597 seconds and 4 git commands to generate.