Blame m4/longlong.m4

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