Blame m4/longlong.m4

Packit 575503
# longlong.m4 serial 17
Packit 575503
dnl Copyright (C) 1999-2007, 2009-2014 Free Software Foundation, Inc.
Packit 575503
dnl This file is free software; the Free Software Foundation
Packit 575503
dnl gives unlimited permission to copy and/or distribute it,
Packit 575503
dnl with or without modifications, as long as this notice is preserved.
Packit 575503
Packit 575503
dnl From Paul Eggert.
Packit 575503
Packit 575503
# Define HAVE_LONG_LONG_INT if 'long long int' works.
Packit 575503
# This fixes a bug in Autoconf 2.61, and can be faster
Packit 575503
# than what's in Autoconf 2.62 through 2.68.
Packit 575503
Packit 575503
# Note: If the type 'long long int' exists but is only 32 bits large
Packit 575503
# (as on some very old compilers), HAVE_LONG_LONG_INT will not be
Packit 575503
# defined. In this case you can treat 'long long int' like 'long int'.
Packit 575503
Packit 575503
AC_DEFUN([AC_TYPE_LONG_LONG_INT],
Packit 575503
[
Packit 575503
  AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
Packit 575503
  AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
Packit 575503
     [ac_cv_type_long_long_int=yes
Packit 575503
      if test "x${ac_cv_prog_cc_c99-no}" = xno; then
Packit 575503
        ac_cv_type_long_long_int=$ac_cv_type_unsigned_long_long_int
Packit 575503
        if test $ac_cv_type_long_long_int = yes; then
Packit 575503
          dnl Catch a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004.
Packit 575503
          dnl If cross compiling, assume the bug is not important, since
Packit 575503
          dnl nobody cross compiles for this platform as far as we know.
Packit 575503
          AC_RUN_IFELSE(
Packit 575503
            [AC_LANG_PROGRAM(
Packit 575503
               [[@%:@include <limits.h>
Packit 575503
                 @%:@ifndef LLONG_MAX
Packit 575503
                 @%:@ define HALF \
Packit 575503
                          (1LL << (sizeof (long long int) * CHAR_BIT - 2))
Packit 575503
                 @%:@ define LLONG_MAX (HALF - 1 + HALF)
Packit 575503
                 @%:@endif]],
Packit 575503
               [[long long int n = 1;
Packit 575503
                 int i;
Packit 575503
                 for (i = 0; ; i++)
Packit 575503
                   {
Packit 575503
                     long long int m = n << i;
Packit 575503
                     if (m >> i != n)
Packit 575503
                       return 1;
Packit 575503
                     if (LLONG_MAX / 2 < m)
Packit 575503
                       break;
Packit 575503
                   }
Packit 575503
                 return 0;]])],
Packit 575503
            [],
Packit 575503
            [ac_cv_type_long_long_int=no],
Packit 575503
            [:])
Packit 575503
        fi
Packit 575503
      fi])
Packit 575503
  if test $ac_cv_type_long_long_int = yes; then
Packit 575503
    AC_DEFINE([HAVE_LONG_LONG_INT], [1],
Packit 575503
      [Define to 1 if the system has the type 'long long int'.])
Packit 575503
  fi
Packit 575503
])
Packit 575503
Packit 575503
# Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works.
Packit 575503
# This fixes a bug in Autoconf 2.61, and can be faster
Packit 575503
# than what's in Autoconf 2.62 through 2.68.
Packit 575503
Packit 575503
# Note: If the type 'unsigned long long int' exists but is only 32 bits
Packit 575503
# large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT
Packit 575503
# will not be defined. In this case you can treat 'unsigned long long int'
Packit 575503
# like 'unsigned long int'.
Packit 575503
Packit 575503
AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
Packit 575503
[
Packit 575503
  AC_CACHE_CHECK([for unsigned long long int],
Packit 575503
    [ac_cv_type_unsigned_long_long_int],
Packit 575503
    [ac_cv_type_unsigned_long_long_int=yes
Packit 575503
     if test "x${ac_cv_prog_cc_c99-no}" = xno; then
Packit 575503
       AC_LINK_IFELSE(
Packit 575503
         [_AC_TYPE_LONG_LONG_SNIPPET],
Packit 575503
         [],
Packit 575503
         [ac_cv_type_unsigned_long_long_int=no])
Packit 575503
     fi])
Packit 575503
  if test $ac_cv_type_unsigned_long_long_int = yes; then
Packit 575503
    AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], [1],
Packit 575503
      [Define to 1 if the system has the type 'unsigned long long int'.])
Packit 575503
  fi
Packit 575503
])
Packit 575503
Packit 575503
# Expands to a C program that can be used to test for simultaneous support
Packit 575503
# of 'long long' and 'unsigned long long'. We don't want to say that
Packit 575503
# 'long long' is available if 'unsigned long long' is not, or vice versa,
Packit 575503
# because too many programs rely on the symmetry between signed and unsigned
Packit 575503
# integer types (excluding 'bool').
Packit 575503
AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET],
Packit 575503
[
Packit 575503
  AC_LANG_PROGRAM(
Packit 575503
    [[/* For now, do not test the preprocessor; as of 2007 there are too many
Packit 575503
         implementations with broken preprocessors.  Perhaps this can
Packit 575503
         be revisited in 2012.  In the meantime, code should not expect
Packit 575503
         #if to work with literals wider than 32 bits.  */
Packit 575503
      /* Test literals.  */
Packit 575503
      long long int ll = 9223372036854775807ll;
Packit 575503
      long long int nll = -9223372036854775807LL;
Packit 575503
      unsigned long long int ull = 18446744073709551615ULL;
Packit 575503
      /* Test constant expressions.   */
Packit 575503
      typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
Packit 575503
                     ? 1 : -1)];
Packit 575503
      typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
Packit 575503
                     ? 1 : -1)];
Packit 575503
      int i = 63;]],
Packit 575503
    [[/* Test availability of runtime routines for shift and division.  */
Packit 575503
      long long int llmax = 9223372036854775807ll;
Packit 575503
      unsigned long long int ullmax = 18446744073709551615ull;
Packit 575503
      return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
Packit 575503
              | (llmax / ll) | (llmax % ll)
Packit 575503
              | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
Packit 575503
              | (ullmax / ull) | (ullmax % ull));]])
Packit 575503
])