Blame m4/longlong.m4

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