Blame m4/longlong.m4

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