longlong.m4 4.6 KB

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