]> granicus.if.org Git - postgresql/blobdiff - config/c-compiler.m4
Extend configure's __int128 test to check for a known gcc bug.
[postgresql] / config / c-compiler.m4
index 802f5539d34bdf133486556e03863588fa6320ba..689bb7f181bd92c35fe03bcdba6fafbd43be6cb1 100644 (file)
@@ -7,8 +7,8 @@
 # Check if the C compiler understands signed types.
 AC_DEFUN([PGAC_C_SIGNED],
 [AC_CACHE_CHECK(for signed types, pgac_cv_c_signed,
-[AC_TRY_COMPILE([],
-[signed char c; signed short s; signed int i;],
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
+[signed char c; signed short s; signed int i;])],
 [pgac_cv_c_signed=yes],
 [pgac_cv_c_signed=no])])
 if test x"$pgac_cv_c_signed" = xno ; then
@@ -17,39 +17,26 @@ fi])# PGAC_C_SIGNED
 
 
 
-# PGAC_C_INLINE
-# -------------
-# Check if the C compiler understands inline functions without being
-# noisy about unused static inline functions. Some older compilers
-# understand inline functions (as tested by AC_C_INLINE) but warn about
-# them if they aren't used in a translation unit.
-#
-# This test used to just define an inline function, but some compilers
-# (notably clang) got too smart and now warn about unused static
-# inline functions when defined inside a .c file, but not when defined
-# in an included header. Since the latter is what we want to use, test
-# to see if the warning appears when the function is in a header file.
-# Not pretty, but it works.
-#
-# Defines: inline, PG_USE_INLINE
-AC_DEFUN([PGAC_C_INLINE],
-[AC_C_INLINE
-AC_CACHE_CHECK([for quiet inline (no complaint if unreferenced)], pgac_cv_c_inline_quietly,
-  [pgac_cv_c_inline_quietly=no
-  if test "$ac_cv_c_inline" != no; then
-    pgac_c_inline_save_werror=$ac_c_werror_flag
-    ac_c_werror_flag=yes
-    AC_LINK_IFELSE([AC_LANG_PROGRAM([#include "$srcdir/config/test_quiet_include.h"],[])],
-                   [pgac_cv_c_inline_quietly=yes])
-    ac_c_werror_flag=$pgac_c_inline_save_werror
-  fi])
-if test "$pgac_cv_c_inline_quietly" != no; then
-  AC_DEFINE_UNQUOTED([PG_USE_INLINE], 1,
-    [Define to 1 if "static inline" works without unwanted warnings from ]
-    [compilations where static inline functions are defined but not called.])
-fi
-])# PGAC_C_INLINE
-
+# PGAC_C_PRINTF_ARCHETYPE
+# -----------------------
+# Set the format archetype used by gcc to check printf type functions.  We
+# prefer "gnu_printf", which includes what glibc uses, such as %m for error
+# strings and %lld for 64 bit long longs.  GCC 4.4 introduced it.  It makes a
+# dramatic difference on Windows.
+AC_DEFUN([PGAC_PRINTF_ARCHETYPE],
+[AC_CACHE_CHECK([for printf format archetype], pgac_cv_printf_archetype,
+[ac_save_c_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag=yes
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+[extern int
+pgac_write(int ignore, const char *fmt,...)
+__attribute__((format(gnu_printf, 2, 3)));], [])],
+                  [pgac_cv_printf_archetype=gnu_printf],
+                  [pgac_cv_printf_archetype=printf])
+ac_c_werror_flag=$ac_save_c_werror_flag])
+AC_DEFINE_UNQUOTED([PG_PRINTF_ATTRIBUTE], [$pgac_cv_printf_archetype],
+                   [Define to gnu_printf if compiler supports it, else printf.])
+])# PGAC_PRINTF_ARCHETYPE
 
 
 # PGAC_TYPE_64BIT_INT(TYPE)
@@ -60,7 +47,7 @@ AC_DEFUN([PGAC_TYPE_64BIT_INT],
 [define([Ac_define], [translit([have_$1_64], [a-z *], [A-Z_P])])dnl
 define([Ac_cachevar], [translit([pgac_cv_type_$1_64], [ *], [_p])])dnl
 AC_CACHE_CHECK([whether $1 is 64 bits], [Ac_cachevar],
-[AC_TRY_RUN(
+[AC_RUN_IFELSE([AC_LANG_SOURCE(
 [typedef $1 ac_int64;
 
 /*
@@ -84,9 +71,11 @@ int does_int64_work()
     return 0;
   return 1;
 }
+
+int
 main() {
-  exit(! does_int64_work());
-}],
+  return (! does_int64_work());
+}])],
 [Ac_cachevar=yes],
 [Ac_cachevar=no],
 [# If cross-compiling, check the size reported by the compiler and
@@ -104,6 +93,78 @@ undefine([Ac_cachevar])dnl
 ])# PGAC_TYPE_64BIT_INT
 
 
+# PGAC_TYPE_128BIT_INT
+# ---------------------
+# Check if __int128 is a working 128 bit integer type, and if so
+# define PG_INT128_TYPE to that typename, and define ALIGNOF_PG_INT128_TYPE
+# as its alignment requirement.
+#
+# This currently only detects a GCC/clang extension, but support for other
+# environments may be added in the future.
+#
+# For the moment we only test for support for 128bit math; support for
+# 128bit literals and snprintf is not required.
+AC_DEFUN([PGAC_TYPE_128BIT_INT],
+[AC_CACHE_CHECK([for __int128], [pgac_cv__128bit_int],
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([
+/*
+ * We don't actually run this test, just link it to verify that any support
+ * functions needed for __int128 are present.
+ *
+ * These are globals to discourage the compiler from folding all the
+ * arithmetic tests down to compile-time constants.  We do not have
+ * convenient support for 128bit literals at this point...
+ */
+__int128 a = 48828125;
+__int128 b = 97656250;
+],[
+__int128 c,d;
+a = (a << 12) + 1; /* 200000000001 */
+b = (b << 12) + 5; /* 400000000005 */
+/* try the most relevant arithmetic ops */
+c = a * b;
+d = (c + b) / b;
+/* must use the results, else compiler may optimize arithmetic away */
+if (d != a+1)
+  return 1;
+])],
+[pgac_cv__128bit_int=yes],
+[pgac_cv__128bit_int=no])])
+if test x"$pgac_cv__128bit_int" = xyes ; then
+  # Use of non-default alignment with __int128 tickles bugs in some compilers.
+  # If not cross-compiling, we can test for bugs and disable use of __int128
+  # with buggy compilers.  If cross-compiling, hope for the best.
+  # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83925
+  AC_CACHE_CHECK([for __int128 alignment bug], [pgac_cv__128bit_int_bug],
+  [AC_RUN_IFELSE([AC_LANG_PROGRAM([
+/* This must match the corresponding code in c.h: */
+#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
+#define pg_attribute_aligned(a) __attribute__((aligned(a)))
+#endif
+typedef __int128 int128a
+#if defined(pg_attribute_aligned)
+pg_attribute_aligned(8)
+#endif
+;
+int128a holder;
+void pass_by_val(void *buffer, int128a par) { holder = par; }
+],[
+long int i64 = 97656225L << 12;
+int128a q;
+pass_by_val(main, (int128a) i64);
+q = (int128a) i64;
+if (q != holder)
+  return 1;
+])],
+  [pgac_cv__128bit_int_bug=ok],
+  [pgac_cv__128bit_int_bug=broken],
+  [pgac_cv__128bit_int_bug="assuming ok"])])
+  if test x"$pgac_cv__128bit_int_bug" != xbroken ; then
+    AC_DEFINE(PG_INT128_TYPE, __int128, [Define to the name of a signed 128-bit integer type.])
+    AC_CHECK_ALIGNOF(PG_INT128_TYPE)
+  fi
+fi])# PGAC_TYPE_128BIT_INT
+
 
 # PGAC_C_FUNCNAME_SUPPORT
 # -----------------------
@@ -111,8 +172,8 @@ undefine([Ac_cachevar])dnl
 # Define HAVE_FUNCNAME__FUNC or HAVE_FUNCNAME__FUNCTION accordingly.
 AC_DEFUN([PGAC_C_FUNCNAME_SUPPORT],
 [AC_CACHE_CHECK(for __func__, pgac_cv_funcname_func_support,
-[AC_TRY_COMPILE([#include <stdio.h>],
-[printf("%s\n", __func__);],
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
+[printf("%s\n", __func__);])],
 [pgac_cv_funcname_func_support=yes],
 [pgac_cv_funcname_func_support=no])])
 if test x"$pgac_cv_funcname_func_support" = xyes ; then
@@ -120,8 +181,8 @@ AC_DEFINE(HAVE_FUNCNAME__FUNC, 1,
           [Define to 1 if your compiler understands __func__.])
 else
 AC_CACHE_CHECK(for __FUNCTION__, pgac_cv_funcname_function_support,
-[AC_TRY_COMPILE([#include <stdio.h>],
-[printf("%s\n", __FUNCTION__);],
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
+[printf("%s\n", __FUNCTION__);])],
 [pgac_cv_funcname_function_support=yes],
 [pgac_cv_funcname_function_support=no])])
 if test x"$pgac_cv_funcname_function_support" = xyes ; then
@@ -141,8 +202,8 @@ fi])# PGAC_C_FUNCNAME_SUPPORT
 # gcc-style compound expressions to be able to wrap the thing into macros.
 AC_DEFUN([PGAC_C_STATIC_ASSERT],
 [AC_CACHE_CHECK(for _Static_assert, pgac_cv__static_assert,
-[AC_TRY_LINK([],
-[({ _Static_assert(1, "foo"); })],
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([],
+[({ _Static_assert(1, "foo"); })])],
 [pgac_cv__static_assert=yes],
 [pgac_cv__static_assert=no])])
 if test x"$pgac_cv__static_assert" = xyes ; then
@@ -152,6 +213,33 @@ fi])# PGAC_C_STATIC_ASSERT
 
 
 
+# PGAC_C_TYPEOF
+# -------------
+# Check if the C compiler understands typeof or a variant.  Define
+# HAVE_TYPEOF if so, and define 'typeof' to the actual key word.
+#
+AC_DEFUN([PGAC_C_TYPEOF],
+[AC_CACHE_CHECK(for typeof, pgac_cv_c_typeof,
+[pgac_cv_c_typeof=no
+for pgac_kw in typeof __typeof__ decltype; do
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
+[int x = 0;
+$pgac_kw(x) y;
+y = x;
+return y;])],
+[pgac_cv_c_typeof=$pgac_kw])
+  test "$pgac_cv_c_typeof" != no && break
+done])
+if test "$pgac_cv_c_typeof" != no; then
+  AC_DEFINE(HAVE_TYPEOF, 1,
+            [Define to 1 if your compiler understands `typeof' or something similar.])
+  if test "$pgac_cv_c_typeof" != typeof; then
+    AC_DEFINE_UNQUOTED(typeof, $pgac_cv_c_typeof, [Define to how the compiler spells `typeof'.])
+  fi
+fi])# PGAC_C_TYPEOF
+
+
+
 # PGAC_C_TYPES_COMPATIBLE
 # -----------------------
 # Check if the C compiler understands __builtin_types_compatible_p,
@@ -161,8 +249,8 @@ fi])# PGAC_C_STATIC_ASSERT
 # have the former and not the latter.
 AC_DEFUN([PGAC_C_TYPES_COMPATIBLE],
 [AC_CACHE_CHECK(for __builtin_types_compatible_p, pgac_cv__types_compatible,
-[AC_TRY_COMPILE([],
-[ int x; static int y[__builtin_types_compatible_p(__typeof__(x), int)]; ],
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
+[[ int x; static int y[__builtin_types_compatible_p(__typeof__(x), int)]; ]])],
 [pgac_cv__types_compatible=yes],
 [pgac_cv__types_compatible=no])])
 if test x"$pgac_cv__types_compatible" = xyes ; then
@@ -171,15 +259,74 @@ AC_DEFINE(HAVE__BUILTIN_TYPES_COMPATIBLE_P, 1,
 fi])# PGAC_C_TYPES_COMPATIBLE
 
 
+# PGAC_C_BUILTIN_BSWAP16
+# -------------------------
+# Check if the C compiler understands __builtin_bswap16(),
+# and define HAVE__BUILTIN_BSWAP16 if so.
+AC_DEFUN([PGAC_C_BUILTIN_BSWAP16],
+[AC_CACHE_CHECK(for __builtin_bswap16, pgac_cv__builtin_bswap16,
+[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+[static unsigned long int x = __builtin_bswap16(0xaabb);]
+)],
+[pgac_cv__builtin_bswap16=yes],
+[pgac_cv__builtin_bswap16=no])])
+if test x"$pgac_cv__builtin_bswap16" = xyes ; then
+AC_DEFINE(HAVE__BUILTIN_BSWAP16, 1,
+          [Define to 1 if your compiler understands __builtin_bswap16.])
+fi])# PGAC_C_BUILTIN_BSWAP16
+
+
+
+# PGAC_C_BUILTIN_BSWAP32
+# -------------------------
+# Check if the C compiler understands __builtin_bswap32(),
+# and define HAVE__BUILTIN_BSWAP32 if so.
+AC_DEFUN([PGAC_C_BUILTIN_BSWAP32],
+[AC_CACHE_CHECK(for __builtin_bswap32, pgac_cv__builtin_bswap32,
+[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+[static unsigned long int x = __builtin_bswap32(0xaabbccdd);]
+)],
+[pgac_cv__builtin_bswap32=yes],
+[pgac_cv__builtin_bswap32=no])])
+if test x"$pgac_cv__builtin_bswap32" = xyes ; then
+AC_DEFINE(HAVE__BUILTIN_BSWAP32, 1,
+          [Define to 1 if your compiler understands __builtin_bswap32.])
+fi])# PGAC_C_BUILTIN_BSWAP32
+
+
+
+# PGAC_C_BUILTIN_BSWAP64
+# -------------------------
+# Check if the C compiler understands __builtin_bswap64(),
+# and define HAVE__BUILTIN_BSWAP64 if so.
+AC_DEFUN([PGAC_C_BUILTIN_BSWAP64],
+[AC_CACHE_CHECK(for __builtin_bswap64, pgac_cv__builtin_bswap64,
+[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+[static unsigned long int x = __builtin_bswap64(0xaabbccddeeff0011);]
+)],
+[pgac_cv__builtin_bswap64=yes],
+[pgac_cv__builtin_bswap64=no])])
+if test x"$pgac_cv__builtin_bswap64" = xyes ; then
+AC_DEFINE(HAVE__BUILTIN_BSWAP64, 1,
+          [Define to 1 if your compiler understands __builtin_bswap64.])
+fi])# PGAC_C_BUILTIN_BSWAP64
+
+
 
 # PGAC_C_BUILTIN_CONSTANT_P
 # -------------------------
 # Check if the C compiler understands __builtin_constant_p(),
 # and define HAVE__BUILTIN_CONSTANT_P if so.
+# We need __builtin_constant_p("string literal") to be true, but some older
+# compilers don't think that, so test for that case explicitly.
 AC_DEFUN([PGAC_C_BUILTIN_CONSTANT_P],
 [AC_CACHE_CHECK(for __builtin_constant_p, pgac_cv__builtin_constant_p,
-[AC_TRY_COMPILE([static int x; static int y[__builtin_constant_p(x) ? x : 1];],
-[],
+[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+[[static int x;
+  static int y[__builtin_constant_p(x) ? x : 1];
+  static int z[__builtin_constant_p("string literal") ? 1 : x];
+]]
+)],
 [pgac_cv__builtin_constant_p=yes],
 [pgac_cv__builtin_constant_p=no])])
 if test x"$pgac_cv__builtin_constant_p" = xyes ; then
@@ -189,6 +336,34 @@ fi])# PGAC_C_BUILTIN_CONSTANT_P
 
 
 
+# PGAC_C_BUILTIN_OP_OVERFLOW
+# -------------------------
+# Check if the C compiler understands __builtin_$op_overflow(),
+# and define HAVE__BUILTIN_OP_OVERFLOW if so.
+#
+# Check for the most complicated case, 64 bit multiplication, as a
+# proxy for all of the operations.  To detect the case where the compiler
+# knows the function but library support is missing, we must link not just
+# compile, and store the results in global variables so the compiler doesn't
+# optimize away the call.
+AC_DEFUN([PGAC_C_BUILTIN_OP_OVERFLOW],
+[AC_CACHE_CHECK(for __builtin_mul_overflow, pgac_cv__builtin_op_overflow,
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([
+PG_INT64_TYPE a = 1;
+PG_INT64_TYPE b = 1;
+PG_INT64_TYPE result;
+int oflo;
+],
+[oflo = __builtin_mul_overflow(a, b, &result);])],
+[pgac_cv__builtin_op_overflow=yes],
+[pgac_cv__builtin_op_overflow=no])])
+if test x"$pgac_cv__builtin_op_overflow" = xyes ; then
+AC_DEFINE(HAVE__BUILTIN_OP_OVERFLOW, 1,
+          [Define to 1 if your compiler understands __builtin_$op_overflow.])
+fi])# PGAC_C_BUILTIN_OP_OVERFLOW
+
+
+
 # PGAC_C_BUILTIN_UNREACHABLE
 # --------------------------
 # Check if the C compiler understands __builtin_unreachable(),
@@ -199,8 +374,8 @@ fi])# PGAC_C_BUILTIN_CONSTANT_P
 # and only a warning instead of an error would be produced.
 AC_DEFUN([PGAC_C_BUILTIN_UNREACHABLE],
 [AC_CACHE_CHECK(for __builtin_unreachable, pgac_cv__builtin_unreachable,
-[AC_TRY_LINK([],
-[__builtin_unreachable();],
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([],
+[__builtin_unreachable();])],
 [pgac_cv__builtin_unreachable=yes],
 [pgac_cv__builtin_unreachable=no])])
 if test x"$pgac_cv__builtin_unreachable" = xyes ; then
@@ -210,16 +385,40 @@ fi])# PGAC_C_BUILTIN_UNREACHABLE
 
 
 
+# PGAC_C_COMPUTED_GOTO
+# -----------------------
+# Check if the C compiler knows computed gotos (gcc extension, also
+# available in at least clang).  If so, define HAVE_COMPUTED_GOTO.
+#
+# Checking whether computed gotos are supported syntax-wise ought to
+# be enough, as the syntax is otherwise illegal.
+AC_DEFUN([PGAC_C_COMPUTED_GOTO],
+[AC_CACHE_CHECK(for computed goto support, pgac_cv_computed_goto,
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
+[[void *labeladdrs[] = {&&my_label};
+  goto *labeladdrs[0];
+  my_label:
+  return 1;
+]])],
+[pgac_cv_computed_goto=yes],
+[pgac_cv_computed_goto=no])])
+if test x"$pgac_cv_computed_goto" = xyes ; then
+AC_DEFINE(HAVE_COMPUTED_GOTO, 1,
+          [Define to 1 if your compiler handles computed gotos.])
+fi])# PGAC_C_COMPUTED_GOTO
+
+
+
 # PGAC_C_VA_ARGS
 # --------------
 # Check if the C compiler understands C99-style variadic macros,
 # and define HAVE__VA_ARGS if so.
 AC_DEFUN([PGAC_C_VA_ARGS],
 [AC_CACHE_CHECK(for __VA_ARGS__, pgac_cv__va_args,
-[AC_TRY_COMPILE([#include <stdio.h>],
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
 [#define debug(...) fprintf(stderr, __VA_ARGS__)
 debug("%s", "blarg");
-],
+])],
 [pgac_cv__va_args=yes],
 [pgac_cv__va_args=no])])
 if test x"$pgac_cv__va_args" = xyes ; then
@@ -274,7 +473,7 @@ if test x"$Ac_cachevar" = x"yes"; then
   $1="${$1} $2"
 fi
 undefine([Ac_cachevar])dnl
-])# PGAC_PROG_CC_CFLAGS_OPT
+])# PGAC_PROG_CC_VAR_OPT
 
 
 
@@ -300,3 +499,131 @@ if test x"$Ac_cachevar" = x"yes"; then
 fi
 undefine([Ac_cachevar])dnl
 ])# PGAC_PROG_CC_LDFLAGS_OPT
+
+# PGAC_HAVE_GCC__SYNC_CHAR_TAS
+# -------------------------
+# Check if the C compiler understands __sync_lock_test_and_set(char),
+# and define HAVE_GCC__SYNC_CHAR_TAS
+#
+# NB: There are platforms where test_and_set is available but compare_and_swap
+# is not, so test this separately.
+# NB: Some platforms only do 32bit tas, others only do 8bit tas. Test both.
+AC_DEFUN([PGAC_HAVE_GCC__SYNC_CHAR_TAS],
+[AC_CACHE_CHECK(for builtin __sync char locking functions, pgac_cv_gcc_sync_char_tas,
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([],
+  [char lock = 0;
+   __sync_lock_test_and_set(&lock, 1);
+   __sync_lock_release(&lock);])],
+  [pgac_cv_gcc_sync_char_tas="yes"],
+  [pgac_cv_gcc_sync_char_tas="no"])])
+if test x"$pgac_cv_gcc_sync_char_tas" = x"yes"; then
+  AC_DEFINE(HAVE_GCC__SYNC_CHAR_TAS, 1, [Define to 1 if you have __sync_lock_test_and_set(char *) and friends.])
+fi])# PGAC_HAVE_GCC__SYNC_CHAR_TAS
+
+# PGAC_HAVE_GCC__SYNC_INT32_TAS
+# -------------------------
+# Check if the C compiler understands __sync_lock_test_and_set(),
+# and define HAVE_GCC__SYNC_INT32_TAS
+AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT32_TAS],
+[AC_CACHE_CHECK(for builtin __sync int32 locking functions, pgac_cv_gcc_sync_int32_tas,
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([],
+  [int lock = 0;
+   __sync_lock_test_and_set(&lock, 1);
+   __sync_lock_release(&lock);])],
+  [pgac_cv_gcc_sync_int32_tas="yes"],
+  [pgac_cv_gcc_sync_int32_tas="no"])])
+if test x"$pgac_cv_gcc_sync_int32_tas" = x"yes"; then
+  AC_DEFINE(HAVE_GCC__SYNC_INT32_TAS, 1, [Define to 1 if you have __sync_lock_test_and_set(int *) and friends.])
+fi])# PGAC_HAVE_GCC__SYNC_INT32_TAS
+
+# PGAC_HAVE_GCC__SYNC_INT32_CAS
+# -------------------------
+# Check if the C compiler understands __sync_compare_and_swap() for 32bit
+# types, and define HAVE_GCC__SYNC_INT32_CAS if so.
+AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT32_CAS],
+[AC_CACHE_CHECK(for builtin __sync int32 atomic operations, pgac_cv_gcc_sync_int32_cas,
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([],
+  [int val = 0;
+   __sync_val_compare_and_swap(&val, 0, 37);])],
+  [pgac_cv_gcc_sync_int32_cas="yes"],
+  [pgac_cv_gcc_sync_int32_cas="no"])])
+if test x"$pgac_cv_gcc_sync_int32_cas" = x"yes"; then
+  AC_DEFINE(HAVE_GCC__SYNC_INT32_CAS, 1, [Define to 1 if you have __sync_compare_and_swap(int *, int, int).])
+fi])# PGAC_HAVE_GCC__SYNC_INT32_CAS
+
+# PGAC_HAVE_GCC__SYNC_INT64_CAS
+# -------------------------
+# Check if the C compiler understands __sync_compare_and_swap() for 64bit
+# types, and define HAVE_GCC__SYNC_INT64_CAS if so.
+AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT64_CAS],
+[AC_CACHE_CHECK(for builtin __sync int64 atomic operations, pgac_cv_gcc_sync_int64_cas,
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([],
+  [PG_INT64_TYPE lock = 0;
+   __sync_val_compare_and_swap(&lock, 0, (PG_INT64_TYPE) 37);])],
+  [pgac_cv_gcc_sync_int64_cas="yes"],
+  [pgac_cv_gcc_sync_int64_cas="no"])])
+if test x"$pgac_cv_gcc_sync_int64_cas" = x"yes"; then
+  AC_DEFINE(HAVE_GCC__SYNC_INT64_CAS, 1, [Define to 1 if you have __sync_compare_and_swap(int64 *, int64, int64).])
+fi])# PGAC_HAVE_GCC__SYNC_INT64_CAS
+
+# PGAC_HAVE_GCC__ATOMIC_INT32_CAS
+# -------------------------
+# Check if the C compiler understands __atomic_compare_exchange_n() for 32bit
+# types, and define HAVE_GCC__ATOMIC_INT32_CAS if so.
+AC_DEFUN([PGAC_HAVE_GCC__ATOMIC_INT32_CAS],
+[AC_CACHE_CHECK(for builtin __atomic int32 atomic operations, pgac_cv_gcc_atomic_int32_cas,
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([],
+  [int val = 0;
+   int expect = 0;
+   __atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);])],
+  [pgac_cv_gcc_atomic_int32_cas="yes"],
+  [pgac_cv_gcc_atomic_int32_cas="no"])])
+if test x"$pgac_cv_gcc_atomic_int32_cas" = x"yes"; then
+  AC_DEFINE(HAVE_GCC__ATOMIC_INT32_CAS, 1, [Define to 1 if you have __atomic_compare_exchange_n(int *, int *, int).])
+fi])# PGAC_HAVE_GCC__ATOMIC_INT32_CAS
+
+# PGAC_HAVE_GCC__ATOMIC_INT64_CAS
+# -------------------------
+# Check if the C compiler understands __atomic_compare_exchange_n() for 64bit
+# types, and define HAVE_GCC__ATOMIC_INT64_CAS if so.
+AC_DEFUN([PGAC_HAVE_GCC__ATOMIC_INT64_CAS],
+[AC_CACHE_CHECK(for builtin __atomic int64 atomic operations, pgac_cv_gcc_atomic_int64_cas,
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([],
+  [PG_INT64_TYPE val = 0;
+   PG_INT64_TYPE expect = 0;
+   __atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);])],
+  [pgac_cv_gcc_atomic_int64_cas="yes"],
+  [pgac_cv_gcc_atomic_int64_cas="no"])])
+if test x"$pgac_cv_gcc_atomic_int64_cas" = x"yes"; then
+  AC_DEFINE(HAVE_GCC__ATOMIC_INT64_CAS, 1, [Define to 1 if you have __atomic_compare_exchange_n(int64 *, int *, int64).])
+fi])# PGAC_HAVE_GCC__ATOMIC_INT64_CAS
+
+# PGAC_SSE42_CRC32_INTRINSICS
+# -----------------------
+# Check if the compiler supports the x86 CRC instructions added in SSE 4.2,
+# using the _mm_crc32_u8 and _mm_crc32_u32 intrinsic functions. (We don't
+# test the 8-byte variant, _mm_crc32_u64, but it is assumed to be present if
+# the other ones are, on x86-64 platforms)
+#
+# An optional compiler flag can be passed as argument (e.g. -msse4.2). If the
+# intrinsics are supported, sets pgac_sse42_crc32_intrinsics, and CFLAGS_SSE42.
+AC_DEFUN([PGAC_SSE42_CRC32_INTRINSICS],
+[define([Ac_cachevar], [AS_TR_SH([pgac_cv_sse42_crc32_intrinsics_$1])])dnl
+AC_CACHE_CHECK([for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=$1], [Ac_cachevar],
+[pgac_save_CFLAGS=$CFLAGS
+CFLAGS="$pgac_save_CFLAGS $1"
+AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <nmmintrin.h>],
+  [unsigned int crc = 0;
+   crc = _mm_crc32_u8(crc, 0);
+   crc = _mm_crc32_u32(crc, 0);
+   /* return computed value, to prevent the above being optimized away */
+   return crc == 0;])],
+  [Ac_cachevar=yes],
+  [Ac_cachevar=no])
+CFLAGS="$pgac_save_CFLAGS"])
+if test x"$Ac_cachevar" = x"yes"; then
+  CFLAGS_SSE42="$1"
+  pgac_sse42_crc32_intrinsics=yes
+fi
+undefine([Ac_cachevar])dnl
+])# PGAC_SSE42_CRC32_INTRINSICS