Fix memory leak in repeated GIN index searches.
[pgsql.git] / config / c-compiler.m4
blob550d03474c63dc63a3f399bf45e02bf089c9f043
1 # Macros to detect C compiler features
2 # config/c-compiler.m4
5 # PGAC_C_SIGNED
6 # -------------
7 # Check if the C compiler understands signed types.
8 AC_DEFUN([PGAC_C_SIGNED],
9 [AC_CACHE_CHECK(for signed types, pgac_cv_c_signed,
10 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
11 [signed char c; signed short s; signed int i;])],
12 [pgac_cv_c_signed=yes],
13 [pgac_cv_c_signed=no])])
14 if test x"$pgac_cv_c_signed" = xno ; then
15   AC_DEFINE(signed,, [Define to empty if the C compiler does not understand signed types.])
16 fi])# PGAC_C_SIGNED
20 # PGAC_C_PRINTF_ARCHETYPE
21 # -----------------------
22 # Set the format archetype used by gcc to check printf type functions.  We
23 # prefer "gnu_printf", which includes what glibc uses, such as %m for error
24 # strings and %lld for 64 bit long longs.  GCC 4.4 introduced it.  It makes a
25 # dramatic difference on Windows.
26 AC_DEFUN([PGAC_PRINTF_ARCHETYPE],
27 [AC_CACHE_CHECK([for printf format archetype], pgac_cv_printf_archetype,
28 [ac_save_c_werror_flag=$ac_c_werror_flag
29 ac_c_werror_flag=yes
30 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
31 [extern int
32 pgac_write(int ignore, const char *fmt,...)
33 __attribute__((format(gnu_printf, 2, 3)));], [])],
34                   [pgac_cv_printf_archetype=gnu_printf],
35                   [pgac_cv_printf_archetype=printf])
36 ac_c_werror_flag=$ac_save_c_werror_flag])
37 AC_DEFINE_UNQUOTED([PG_PRINTF_ATTRIBUTE], [$pgac_cv_printf_archetype],
38                    [Define to gnu_printf if compiler supports it, else printf.])
39 ])# PGAC_PRINTF_ARCHETYPE
42 # PGAC_TYPE_64BIT_INT(TYPE)
43 # -------------------------
44 # Check if TYPE is a working 64 bit integer type. Set HAVE_TYPE_64 to
45 # yes or no respectively, and define HAVE_TYPE_64 if yes.
46 AC_DEFUN([PGAC_TYPE_64BIT_INT],
47 [define([Ac_define], [translit([have_$1_64], [a-z *], [A-Z_P])])dnl
48 define([Ac_cachevar], [translit([pgac_cv_type_$1_64], [ *], [_p])])dnl
49 AC_CACHE_CHECK([whether $1 is 64 bits], [Ac_cachevar],
50 [AC_RUN_IFELSE([AC_LANG_SOURCE(
51 [typedef $1 ac_int64;
54  * These are globals to discourage the compiler from folding all the
55  * arithmetic tests down to compile-time constants.
56  */
57 ac_int64 a = 20000001;
58 ac_int64 b = 40000005;
60 int does_int64_work()
62   ac_int64 c,d;
64   if (sizeof(ac_int64) != 8)
65     return 0;                   /* definitely not the right size */
67   /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
68   c = a * b;
69   d = (c + b) / b;
70   if (d != a+1)
71     return 0;
72   return 1;
74 main() {
75   exit(! does_int64_work());
76 }])],
77 [Ac_cachevar=yes],
78 [Ac_cachevar=no],
79 [# If cross-compiling, check the size reported by the compiler and
80 # trust that the arithmetic works.
81 AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([], [sizeof($1) == 8])],
82                   Ac_cachevar=yes,
83                   Ac_cachevar=no)])])
85 Ac_define=$Ac_cachevar
86 if test x"$Ac_cachevar" = xyes ; then
87   AC_DEFINE(Ac_define, 1, [Define to 1 if `]$1[' works and is 64 bits.])
89 undefine([Ac_define])dnl
90 undefine([Ac_cachevar])dnl
91 ])# PGAC_TYPE_64BIT_INT
94 # PGAC_TYPE_128BIT_INT
95 # ---------------------
96 # Check if __int128 is a working 128 bit integer type, and if so
97 # define PG_INT128_TYPE to that typename.  This currently only detects
98 # a GCC/clang extension, but support for different environments may be
99 # added in the future.
101 # For the moment we only test for support for 128bit math; support for
102 # 128bit literals and snprintf is not required.
103 AC_DEFUN([PGAC_TYPE_128BIT_INT],
104 [AC_CACHE_CHECK([for __int128], [pgac_cv__128bit_int],
105 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
107  * These are globals to discourage the compiler from folding all the
108  * arithmetic tests down to compile-time constants.  We do not have
109  * convenient support for 64bit literals at this point...
110  */
111 __int128 a = 48828125;
112 __int128 b = 97656255;
114 __int128 c,d;
115 a = (a << 12) + 1; /* 200000000001 */
116 b = (b << 12) + 5; /* 400000000005 */
117 /* use the most relevant arithmetic ops */
118 c = a * b;
119 d = (c + b) / b;
120 /* return different values, to prevent optimizations */
121 if (d != a+1)
122   return 0;
123 return 1;
124 ])],
125 [pgac_cv__128bit_int=yes],
126 [pgac_cv__128bit_int=no])])
127 if test x"$pgac_cv__128bit_int" = xyes ; then
128   AC_DEFINE(PG_INT128_TYPE, __int128, [Define to the name of a signed 128-bit integer type.])
129 fi])# PGAC_TYPE_128BIT_INT
132 # PGAC_C_FUNCNAME_SUPPORT
133 # -----------------------
134 # Check if the C compiler understands __func__ (C99) or __FUNCTION__ (gcc).
135 # Define HAVE_FUNCNAME__FUNC or HAVE_FUNCNAME__FUNCTION accordingly.
136 AC_DEFUN([PGAC_C_FUNCNAME_SUPPORT],
137 [AC_CACHE_CHECK(for __func__, pgac_cv_funcname_func_support,
138 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
139 [printf("%s\n", __func__);])],
140 [pgac_cv_funcname_func_support=yes],
141 [pgac_cv_funcname_func_support=no])])
142 if test x"$pgac_cv_funcname_func_support" = xyes ; then
143 AC_DEFINE(HAVE_FUNCNAME__FUNC, 1,
144           [Define to 1 if your compiler understands __func__.])
145 else
146 AC_CACHE_CHECK(for __FUNCTION__, pgac_cv_funcname_function_support,
147 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
148 [printf("%s\n", __FUNCTION__);])],
149 [pgac_cv_funcname_function_support=yes],
150 [pgac_cv_funcname_function_support=no])])
151 if test x"$pgac_cv_funcname_function_support" = xyes ; then
152 AC_DEFINE(HAVE_FUNCNAME__FUNCTION, 1,
153           [Define to 1 if your compiler understands __FUNCTION__.])
155 fi])# PGAC_C_FUNCNAME_SUPPORT
159 # PGAC_C_STATIC_ASSERT
160 # --------------------
161 # Check if the C compiler understands _Static_assert(),
162 # and define HAVE__STATIC_ASSERT if so.
164 # We actually check the syntax ({ _Static_assert(...) }), because we need
165 # gcc-style compound expressions to be able to wrap the thing into macros.
166 AC_DEFUN([PGAC_C_STATIC_ASSERT],
167 [AC_CACHE_CHECK(for _Static_assert, pgac_cv__static_assert,
168 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
169 [({ _Static_assert(1, "foo"); })])],
170 [pgac_cv__static_assert=yes],
171 [pgac_cv__static_assert=no])])
172 if test x"$pgac_cv__static_assert" = xyes ; then
173 AC_DEFINE(HAVE__STATIC_ASSERT, 1,
174           [Define to 1 if your compiler understands _Static_assert.])
175 fi])# PGAC_C_STATIC_ASSERT
179 # PGAC_C_TYPES_COMPATIBLE
180 # -----------------------
181 # Check if the C compiler understands __builtin_types_compatible_p,
182 # and define HAVE__BUILTIN_TYPES_COMPATIBLE_P if so.
184 # We check usage with __typeof__, though it's unlikely any compiler would
185 # have the former and not the latter.
186 AC_DEFUN([PGAC_C_TYPES_COMPATIBLE],
187 [AC_CACHE_CHECK(for __builtin_types_compatible_p, pgac_cv__types_compatible,
188 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
189 [[ int x; static int y[__builtin_types_compatible_p(__typeof__(x), int)]; ]])],
190 [pgac_cv__types_compatible=yes],
191 [pgac_cv__types_compatible=no])])
192 if test x"$pgac_cv__types_compatible" = xyes ; then
193 AC_DEFINE(HAVE__BUILTIN_TYPES_COMPATIBLE_P, 1,
194           [Define to 1 if your compiler understands __builtin_types_compatible_p.])
195 fi])# PGAC_C_TYPES_COMPATIBLE
199 # PGAC_C_BUILTIN_BSWAP32
200 # -------------------------
201 # Check if the C compiler understands __builtin_bswap32(),
202 # and define HAVE__BUILTIN_BSWAP32 if so.
203 AC_DEFUN([PGAC_C_BUILTIN_BSWAP32],
204 [AC_CACHE_CHECK(for __builtin_bswap32, pgac_cv__builtin_bswap32,
205 [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
206 [static unsigned long int x = __builtin_bswap32(0xaabbccdd);]
208 [pgac_cv__builtin_bswap32=yes],
209 [pgac_cv__builtin_bswap32=no])])
210 if test x"$pgac_cv__builtin_bswap32" = xyes ; then
211 AC_DEFINE(HAVE__BUILTIN_BSWAP32, 1,
212           [Define to 1 if your compiler understands __builtin_bswap32.])
213 fi])# PGAC_C_BUILTIN_BSWAP32
217 # PGAC_C_BUILTIN_BSWAP64
218 # -------------------------
219 # Check if the C compiler understands __builtin_bswap64(),
220 # and define HAVE__BUILTIN_BSWAP64 if so.
221 AC_DEFUN([PGAC_C_BUILTIN_BSWAP64],
222 [AC_CACHE_CHECK(for __builtin_bswap64, pgac_cv__builtin_bswap64,
223 [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
224 [static unsigned long int x = __builtin_bswap64(0xaabbccddeeff0011);]
226 [pgac_cv__builtin_bswap64=yes],
227 [pgac_cv__builtin_bswap64=no])])
228 if test x"$pgac_cv__builtin_bswap64" = xyes ; then
229 AC_DEFINE(HAVE__BUILTIN_BSWAP64, 1,
230           [Define to 1 if your compiler understands __builtin_bswap64.])
231 fi])# PGAC_C_BUILTIN_BSWAP64
235 # PGAC_C_BUILTIN_CONSTANT_P
236 # -------------------------
237 # Check if the C compiler understands __builtin_constant_p(),
238 # and define HAVE__BUILTIN_CONSTANT_P if so.
239 AC_DEFUN([PGAC_C_BUILTIN_CONSTANT_P],
240 [AC_CACHE_CHECK(for __builtin_constant_p, pgac_cv__builtin_constant_p,
241 [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
242 [[static int x; static int y[__builtin_constant_p(x) ? x : 1];]]
244 [pgac_cv__builtin_constant_p=yes],
245 [pgac_cv__builtin_constant_p=no])])
246 if test x"$pgac_cv__builtin_constant_p" = xyes ; then
247 AC_DEFINE(HAVE__BUILTIN_CONSTANT_P, 1,
248           [Define to 1 if your compiler understands __builtin_constant_p.])
249 fi])# PGAC_C_BUILTIN_CONSTANT_P
253 # PGAC_C_BUILTIN_UNREACHABLE
254 # --------------------------
255 # Check if the C compiler understands __builtin_unreachable(),
256 # and define HAVE__BUILTIN_UNREACHABLE if so.
258 # NB: Don't get the idea of putting a for(;;); or such before the
259 # __builtin_unreachable() call.  Some compilers would remove it before linking
260 # and only a warning instead of an error would be produced.
261 AC_DEFUN([PGAC_C_BUILTIN_UNREACHABLE],
262 [AC_CACHE_CHECK(for __builtin_unreachable, pgac_cv__builtin_unreachable,
263 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
264 [__builtin_unreachable();])],
265 [pgac_cv__builtin_unreachable=yes],
266 [pgac_cv__builtin_unreachable=no])])
267 if test x"$pgac_cv__builtin_unreachable" = xyes ; then
268 AC_DEFINE(HAVE__BUILTIN_UNREACHABLE, 1,
269           [Define to 1 if your compiler understands __builtin_unreachable.])
270 fi])# PGAC_C_BUILTIN_UNREACHABLE
274 # PGAC_C_VA_ARGS
275 # --------------
276 # Check if the C compiler understands C99-style variadic macros,
277 # and define HAVE__VA_ARGS if so.
278 AC_DEFUN([PGAC_C_VA_ARGS],
279 [AC_CACHE_CHECK(for __VA_ARGS__, pgac_cv__va_args,
280 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
281 [#define debug(...) fprintf(stderr, __VA_ARGS__)
282 debug("%s", "blarg");
283 ])],
284 [pgac_cv__va_args=yes],
285 [pgac_cv__va_args=no])])
286 if test x"$pgac_cv__va_args" = xyes ; then
287 AC_DEFINE(HAVE__VA_ARGS, 1,
288           [Define to 1 if your compiler understands __VA_ARGS__ in macros.])
289 fi])# PGAC_C_VA_ARGS
293 # PGAC_PROG_CC_CFLAGS_OPT
294 # -----------------------
295 # Given a string, check if the compiler supports the string as a
296 # command-line option. If it does, add the string to CFLAGS.
297 AC_DEFUN([PGAC_PROG_CC_CFLAGS_OPT],
298 [define([Ac_cachevar], [AS_TR_SH([pgac_cv_prog_cc_cflags_$1])])dnl
299 AC_CACHE_CHECK([whether $CC supports $1], [Ac_cachevar],
300 [pgac_save_CFLAGS=$CFLAGS
301 CFLAGS="$pgac_save_CFLAGS $1"
302 ac_save_c_werror_flag=$ac_c_werror_flag
303 ac_c_werror_flag=yes
304 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
305                    [Ac_cachevar=yes],
306                    [Ac_cachevar=no])
307 ac_c_werror_flag=$ac_save_c_werror_flag
308 CFLAGS="$pgac_save_CFLAGS"])
309 if test x"$Ac_cachevar" = x"yes"; then
310   CFLAGS="$CFLAGS $1"
312 undefine([Ac_cachevar])dnl
313 ])# PGAC_PROG_CC_CFLAGS_OPT
317 # PGAC_PROG_CC_VAR_OPT
318 # -----------------------
319 # Given a variable name and a string, check if the compiler supports
320 # the string as a command-line option. If it does, add the string to
321 # the given variable.
322 AC_DEFUN([PGAC_PROG_CC_VAR_OPT],
323 [define([Ac_cachevar], [AS_TR_SH([pgac_cv_prog_cc_cflags_$2])])dnl
324 AC_CACHE_CHECK([whether $CC supports $2], [Ac_cachevar],
325 [pgac_save_CFLAGS=$CFLAGS
326 CFLAGS="$pgac_save_CFLAGS $2"
327 ac_save_c_werror_flag=$ac_c_werror_flag
328 ac_c_werror_flag=yes
329 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
330                    [Ac_cachevar=yes],
331                    [Ac_cachevar=no])
332 ac_c_werror_flag=$ac_save_c_werror_flag
333 CFLAGS="$pgac_save_CFLAGS"])
334 if test x"$Ac_cachevar" = x"yes"; then
335   $1="${$1} $2"
337 undefine([Ac_cachevar])dnl
338 ])# PGAC_PROG_CC_CFLAGS_OPT
342 # PGAC_PROG_CC_LDFLAGS_OPT
343 # ------------------------
344 # Given a string, check if the compiler supports the string as a
345 # command-line option. If it does, add the string to LDFLAGS.
346 # For reasons you'd really rather not know about, this checks whether
347 # you can link to a particular function, not just whether you can link.
348 # In fact, we must actually check that the resulting program runs :-(
349 AC_DEFUN([PGAC_PROG_CC_LDFLAGS_OPT],
350 [define([Ac_cachevar], [AS_TR_SH([pgac_cv_prog_cc_ldflags_$1])])dnl
351 AC_CACHE_CHECK([whether $CC supports $1], [Ac_cachevar],
352 [pgac_save_LDFLAGS=$LDFLAGS
353 LDFLAGS="$pgac_save_LDFLAGS $1"
354 AC_RUN_IFELSE([AC_LANG_PROGRAM([extern void $2 (); void (*fptr) () = $2;],[])],
355               [Ac_cachevar=yes],
356               [Ac_cachevar=no],
357               [Ac_cachevar="assuming no"])
358 LDFLAGS="$pgac_save_LDFLAGS"])
359 if test x"$Ac_cachevar" = x"yes"; then
360   LDFLAGS="$LDFLAGS $1"
362 undefine([Ac_cachevar])dnl
363 ])# PGAC_PROG_CC_LDFLAGS_OPT
365 # PGAC_HAVE_GCC__SYNC_CHAR_TAS
366 # -------------------------
367 # Check if the C compiler understands __sync_lock_test_and_set(char),
368 # and define HAVE_GCC__SYNC_CHAR_TAS
370 # NB: There are platforms where test_and_set is available but compare_and_swap
371 # is not, so test this separately.
372 # NB: Some platforms only do 32bit tas, others only do 8bit tas. Test both.
373 AC_DEFUN([PGAC_HAVE_GCC__SYNC_CHAR_TAS],
374 [AC_CACHE_CHECK(for builtin __sync char locking functions, pgac_cv_gcc_sync_char_tas,
375 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
376   [char lock = 0;
377    __sync_lock_test_and_set(&lock, 1);
378    __sync_lock_release(&lock);])],
379   [pgac_cv_gcc_sync_char_tas="yes"],
380   [pgac_cv_gcc_sync_char_tas="no"])])
381 if test x"$pgac_cv_gcc_sync_char_tas" = x"yes"; then
382   AC_DEFINE(HAVE_GCC__SYNC_CHAR_TAS, 1, [Define to 1 if you have __sync_lock_test_and_set(char *) and friends.])
383 fi])# PGAC_HAVE_GCC__SYNC_CHAR_TAS
385 # PGAC_HAVE_GCC__SYNC_INT32_TAS
386 # -------------------------
387 # Check if the C compiler understands __sync_lock_test_and_set(),
388 # and define HAVE_GCC__SYNC_INT32_TAS
389 AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT32_TAS],
390 [AC_CACHE_CHECK(for builtin __sync int32 locking functions, pgac_cv_gcc_sync_int32_tas,
391 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
392   [int lock = 0;
393    __sync_lock_test_and_set(&lock, 1);
394    __sync_lock_release(&lock);])],
395   [pgac_cv_gcc_sync_int32_tas="yes"],
396   [pgac_cv_gcc_sync_int32_tas="no"])])
397 if test x"$pgac_cv_gcc_sync_int32_tas" = x"yes"; then
398   AC_DEFINE(HAVE_GCC__SYNC_INT32_TAS, 1, [Define to 1 if you have __sync_lock_test_and_set(int *) and friends.])
399 fi])# PGAC_HAVE_GCC__SYNC_INT32_TAS
401 # PGAC_HAVE_GCC__SYNC_INT32_CAS
402 # -------------------------
403 # Check if the C compiler understands __sync_compare_and_swap() for 32bit
404 # types, and define HAVE_GCC__SYNC_INT32_CAS if so.
405 AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT32_CAS],
406 [AC_CACHE_CHECK(for builtin __sync int32 atomic operations, pgac_cv_gcc_sync_int32_cas,
407 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
408   [int val = 0;
409    __sync_val_compare_and_swap(&val, 0, 37);])],
410   [pgac_cv_gcc_sync_int32_cas="yes"],
411   [pgac_cv_gcc_sync_int32_cas="no"])])
412 if test x"$pgac_cv_gcc_sync_int32_cas" = x"yes"; then
413   AC_DEFINE(HAVE_GCC__SYNC_INT32_CAS, 1, [Define to 1 if you have __sync_compare_and_swap(int *, int, int).])
414 fi])# PGAC_HAVE_GCC__SYNC_INT32_CAS
416 # PGAC_HAVE_GCC__SYNC_INT64_CAS
417 # -------------------------
418 # Check if the C compiler understands __sync_compare_and_swap() for 64bit
419 # types, and define HAVE_GCC__SYNC_INT64_CAS if so.
420 AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT64_CAS],
421 [AC_CACHE_CHECK(for builtin __sync int64 atomic operations, pgac_cv_gcc_sync_int64_cas,
422 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
423   [PG_INT64_TYPE lock = 0;
424    __sync_val_compare_and_swap(&lock, 0, (PG_INT64_TYPE) 37);])],
425   [pgac_cv_gcc_sync_int64_cas="yes"],
426   [pgac_cv_gcc_sync_int64_cas="no"])])
427 if test x"$pgac_cv_gcc_sync_int64_cas" = x"yes"; then
428   AC_DEFINE(HAVE_GCC__SYNC_INT64_CAS, 1, [Define to 1 if you have __sync_compare_and_swap(int64 *, int64, int64).])
429 fi])# PGAC_HAVE_GCC__SYNC_INT64_CAS
431 # PGAC_HAVE_GCC__ATOMIC_INT32_CAS
432 # -------------------------
433 # Check if the C compiler understands __atomic_compare_exchange_n() for 32bit
434 # types, and define HAVE_GCC__ATOMIC_INT32_CAS if so.
435 AC_DEFUN([PGAC_HAVE_GCC__ATOMIC_INT32_CAS],
436 [AC_CACHE_CHECK(for builtin __atomic int32 atomic operations, pgac_cv_gcc_atomic_int32_cas,
437 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
438   [int val = 0;
439    int expect = 0;
440    __atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);])],
441   [pgac_cv_gcc_atomic_int32_cas="yes"],
442   [pgac_cv_gcc_atomic_int32_cas="no"])])
443 if test x"$pgac_cv_gcc_atomic_int32_cas" = x"yes"; then
444   AC_DEFINE(HAVE_GCC__ATOMIC_INT32_CAS, 1, [Define to 1 if you have __atomic_compare_exchange_n(int *, int *, int).])
445 fi])# PGAC_HAVE_GCC__ATOMIC_INT32_CAS
447 # PGAC_HAVE_GCC__ATOMIC_INT64_CAS
448 # -------------------------
449 # Check if the C compiler understands __atomic_compare_exchange_n() for 64bit
450 # types, and define HAVE_GCC__ATOMIC_INT64_CAS if so.
451 AC_DEFUN([PGAC_HAVE_GCC__ATOMIC_INT64_CAS],
452 [AC_CACHE_CHECK(for builtin __atomic int64 atomic operations, pgac_cv_gcc_atomic_int64_cas,
453 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
454   [PG_INT64_TYPE val = 0;
455    PG_INT64_TYPE expect = 0;
456    __atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);])],
457   [pgac_cv_gcc_atomic_int64_cas="yes"],
458   [pgac_cv_gcc_atomic_int64_cas="no"])])
459 if test x"$pgac_cv_gcc_atomic_int64_cas" = x"yes"; then
460   AC_DEFINE(HAVE_GCC__ATOMIC_INT64_CAS, 1, [Define to 1 if you have __atomic_compare_exchange_n(int64 *, int *, int64).])
461 fi])# PGAC_HAVE_GCC__ATOMIC_INT64_CAS
463 # PGAC_SSE42_CRC32_INTRINSICS
464 # -----------------------
465 # Check if the compiler supports the x86 CRC instructions added in SSE 4.2,
466 # using the _mm_crc32_u8 and _mm_crc32_u32 intrinsic functions. (We don't
467 # test the 8-byte variant, _mm_crc32_u64, but it is assumed to be present if
468 # the other ones are, on x86-64 platforms)
470 # An optional compiler flag can be passed as argument (e.g. -msse4.2). If the
471 # intrinsics are supported, sets pgac_sse42_crc32_intrinsics, and CFLAGS_SSE42.
472 AC_DEFUN([PGAC_SSE42_CRC32_INTRINSICS],
473 [define([Ac_cachevar], [AS_TR_SH([pgac_cv_sse42_crc32_intrinsics_$1])])dnl
474 AC_CACHE_CHECK([for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=$1], [Ac_cachevar],
475 [pgac_save_CFLAGS=$CFLAGS
476 CFLAGS="$pgac_save_CFLAGS $1"
477 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <nmmintrin.h>],
478   [unsigned int crc = 0;
479    crc = _mm_crc32_u8(crc, 0);
480    crc = _mm_crc32_u32(crc, 0);
481    /* return computed value, to prevent the above being optimized away */
482    return crc == 0;])],
483   [Ac_cachevar=yes],
484   [Ac_cachevar=no])
485 CFLAGS="$pgac_save_CFLAGS"])
486 if test x"$Ac_cachevar" = x"yes"; then
487   CFLAGS_SSE42="$1"
488   pgac_sse42_crc32_intrinsics=yes
490 undefine([Ac_cachevar])dnl
491 ])# PGAC_SSE42_CRC32_INTRINSICS