Blame gettext-runtime/m4/longlong.m4

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