longlong.m4 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # longlong.m4 serial 14
  2. dnl Copyright (C) 1999-2007, 2009-2010 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. dnl From Paul Eggert.
  7. # Define HAVE_LONG_LONG_INT if 'long long int' works.
  8. # This fixes a bug in Autoconf 2.61, but can be removed once we
  9. # assume 2.62 everywhere.
  10. # Note: If the type 'long long int' exists but is only 32 bits large
  11. # (as on some very old compilers), HAVE_LONG_LONG_INT will not be
  12. # defined. In this case you can treat 'long long int' like 'long int'.
  13. AC_DEFUN([AC_TYPE_LONG_LONG_INT],
  14. [
  15. AC_CACHE_CHECK([for long long int], [ac_cv_type_long_long_int],
  16. [AC_LINK_IFELSE(
  17. [_AC_TYPE_LONG_LONG_SNIPPET],
  18. [dnl This catches a bug in Tandem NonStop Kernel (OSS) cc -O circa 2004.
  19. dnl If cross compiling, assume the bug isn't important, since
  20. dnl nobody cross compiles for this platform as far as we know.
  21. AC_RUN_IFELSE(
  22. [AC_LANG_PROGRAM(
  23. [[@%:@include <limits.h>
  24. @%:@ifndef LLONG_MAX
  25. @%:@ define HALF \
  26. (1LL << (sizeof (long long int) * CHAR_BIT - 2))
  27. @%:@ define LLONG_MAX (HALF - 1 + HALF)
  28. @%:@endif]],
  29. [[long long int n = 1;
  30. int i;
  31. for (i = 0; ; i++)
  32. {
  33. long long int m = n << i;
  34. if (m >> i != n)
  35. return 1;
  36. if (LLONG_MAX / 2 < m)
  37. break;
  38. }
  39. return 0;]])],
  40. [ac_cv_type_long_long_int=yes],
  41. [ac_cv_type_long_long_int=no],
  42. [ac_cv_type_long_long_int=yes])],
  43. [ac_cv_type_long_long_int=no])])
  44. if test $ac_cv_type_long_long_int = yes; then
  45. AC_DEFINE([HAVE_LONG_LONG_INT], [1],
  46. [Define to 1 if the system has the type `long long int'.])
  47. fi
  48. ])
  49. # Define HAVE_UNSIGNED_LONG_LONG_INT if 'unsigned long long int' works.
  50. # This fixes a bug in Autoconf 2.61, but can be removed once we
  51. # assume 2.62 everywhere.
  52. # Note: If the type 'unsigned long long int' exists but is only 32 bits
  53. # large (as on some very old compilers), AC_TYPE_UNSIGNED_LONG_LONG_INT
  54. # will not be defined. In this case you can treat 'unsigned long long int'
  55. # like 'unsigned long int'.
  56. AC_DEFUN([AC_TYPE_UNSIGNED_LONG_LONG_INT],
  57. [
  58. AC_CACHE_CHECK([for unsigned long long int],
  59. [ac_cv_type_unsigned_long_long_int],
  60. [AC_LINK_IFELSE(
  61. [_AC_TYPE_LONG_LONG_SNIPPET],
  62. [ac_cv_type_unsigned_long_long_int=yes],
  63. [ac_cv_type_unsigned_long_long_int=no])])
  64. if test $ac_cv_type_unsigned_long_long_int = yes; then
  65. AC_DEFINE([HAVE_UNSIGNED_LONG_LONG_INT], [1],
  66. [Define to 1 if the system has the type `unsigned long long int'.])
  67. fi
  68. ])
  69. # Expands to a C program that can be used to test for simultaneous support
  70. # of 'long long' and 'unsigned long long'. We don't want to say that
  71. # 'long long' is available if 'unsigned long long' is not, or vice versa,
  72. # because too many programs rely on the symmetry between signed and unsigned
  73. # integer types (excluding 'bool').
  74. AC_DEFUN([_AC_TYPE_LONG_LONG_SNIPPET],
  75. [
  76. AC_LANG_PROGRAM(
  77. [[/* For now, do not test the preprocessor; as of 2007 there are too many
  78. implementations with broken preprocessors. Perhaps this can
  79. be revisited in 2012. In the meantime, code should not expect
  80. #if to work with literals wider than 32 bits. */
  81. /* Test literals. */
  82. long long int ll = 9223372036854775807ll;
  83. long long int nll = -9223372036854775807LL;
  84. unsigned long long int ull = 18446744073709551615ULL;
  85. /* Test constant expressions. */
  86. typedef int a[((-9223372036854775807LL < 0 && 0 < 9223372036854775807ll)
  87. ? 1 : -1)];
  88. typedef int b[(18446744073709551615ULL <= (unsigned long long int) -1
  89. ? 1 : -1)];
  90. int i = 63;]],
  91. [[/* Test availability of runtime routines for shift and division. */
  92. long long int llmax = 9223372036854775807ll;
  93. unsigned long long int ullmax = 18446744073709551615ull;
  94. return ((ll << 63) | (ll >> 63) | (ll < i) | (ll > i)
  95. | (llmax / ll) | (llmax % ll)
  96. | (ull << 63) | (ull >> 63) | (ull << i) | (ull >> i)
  97. | (ullmax / ull) | (ullmax % ull));]])
  98. ])