Blame m4/longlong.m4

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