]> granicus.if.org Git - postgresql/blob - config/c-compiler.m4
Tighten configure's test for __builtin_constant_p().
[postgresql] / config / c-compiler.m4
1 # Macros to detect C compiler features
2 # config/c-compiler.m4
3
4
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
17
18
19
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
40
41
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;
52
53 /*
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;
59
60 int does_int64_work()
61 {
62   ac_int64 c,d;
63
64   if (sizeof(ac_int64) != 8)
65     return 0;                   /* definitely not the right size */
66
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;
73 }
74
75 int
76 main() {
77   return (! does_int64_work());
78 }])],
79 [Ac_cachevar=yes],
80 [Ac_cachevar=no],
81 [# If cross-compiling, check the size reported by the compiler and
82 # trust that the arithmetic works.
83 AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([], [sizeof($1) == 8])],
84                   Ac_cachevar=yes,
85                   Ac_cachevar=no)])])
86
87 Ac_define=$Ac_cachevar
88 if test x"$Ac_cachevar" = xyes ; then
89   AC_DEFINE(Ac_define, 1, [Define to 1 if `]$1[' works and is 64 bits.])
90 fi
91 undefine([Ac_define])dnl
92 undefine([Ac_cachevar])dnl
93 ])# PGAC_TYPE_64BIT_INT
94
95
96 # PGAC_TYPE_128BIT_INT
97 # ---------------------
98 # Check if __int128 is a working 128 bit integer type, and if so
99 # define PG_INT128_TYPE to that typename, and define ALIGNOF_PG_INT128_TYPE
100 # as its alignment requirement.
101 #
102 # This currently only detects a GCC/clang extension, but support for other
103 # environments may be added in the future.
104 #
105 # For the moment we only test for support for 128bit math; support for
106 # 128bit literals and snprintf is not required.
107 AC_DEFUN([PGAC_TYPE_128BIT_INT],
108 [AC_CACHE_CHECK([for __int128], [pgac_cv__128bit_int],
109 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
110 /*
111  * These are globals to discourage the compiler from folding all the
112  * arithmetic tests down to compile-time constants.  We do not have
113  * convenient support for 64bit literals at this point...
114  */
115 __int128 a = 48828125;
116 __int128 b = 97656255;
117 ],[
118 __int128 c,d;
119 a = (a << 12) + 1; /* 200000000001 */
120 b = (b << 12) + 5; /* 400000000005 */
121 /* use the most relevant arithmetic ops */
122 c = a * b;
123 d = (c + b) / b;
124 /* return different values, to prevent optimizations */
125 if (d != a+1)
126   return 0;
127 return 1;
128 ])],
129 [pgac_cv__128bit_int=yes],
130 [pgac_cv__128bit_int=no])])
131 if test x"$pgac_cv__128bit_int" = xyes ; then
132   AC_DEFINE(PG_INT128_TYPE, __int128, [Define to the name of a signed 128-bit integer type.])
133   AC_CHECK_ALIGNOF(PG_INT128_TYPE)
134 fi])# PGAC_TYPE_128BIT_INT
135
136
137 # PGAC_C_FUNCNAME_SUPPORT
138 # -----------------------
139 # Check if the C compiler understands __func__ (C99) or __FUNCTION__ (gcc).
140 # Define HAVE_FUNCNAME__FUNC or HAVE_FUNCNAME__FUNCTION accordingly.
141 AC_DEFUN([PGAC_C_FUNCNAME_SUPPORT],
142 [AC_CACHE_CHECK(for __func__, pgac_cv_funcname_func_support,
143 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
144 [printf("%s\n", __func__);])],
145 [pgac_cv_funcname_func_support=yes],
146 [pgac_cv_funcname_func_support=no])])
147 if test x"$pgac_cv_funcname_func_support" = xyes ; then
148 AC_DEFINE(HAVE_FUNCNAME__FUNC, 1,
149           [Define to 1 if your compiler understands __func__.])
150 else
151 AC_CACHE_CHECK(for __FUNCTION__, pgac_cv_funcname_function_support,
152 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
153 [printf("%s\n", __FUNCTION__);])],
154 [pgac_cv_funcname_function_support=yes],
155 [pgac_cv_funcname_function_support=no])])
156 if test x"$pgac_cv_funcname_function_support" = xyes ; then
157 AC_DEFINE(HAVE_FUNCNAME__FUNCTION, 1,
158           [Define to 1 if your compiler understands __FUNCTION__.])
159 fi
160 fi])# PGAC_C_FUNCNAME_SUPPORT
161
162
163
164 # PGAC_C_STATIC_ASSERT
165 # --------------------
166 # Check if the C compiler understands _Static_assert(),
167 # and define HAVE__STATIC_ASSERT if so.
168 #
169 # We actually check the syntax ({ _Static_assert(...) }), because we need
170 # gcc-style compound expressions to be able to wrap the thing into macros.
171 AC_DEFUN([PGAC_C_STATIC_ASSERT],
172 [AC_CACHE_CHECK(for _Static_assert, pgac_cv__static_assert,
173 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
174 [({ _Static_assert(1, "foo"); })])],
175 [pgac_cv__static_assert=yes],
176 [pgac_cv__static_assert=no])])
177 if test x"$pgac_cv__static_assert" = xyes ; then
178 AC_DEFINE(HAVE__STATIC_ASSERT, 1,
179           [Define to 1 if your compiler understands _Static_assert.])
180 fi])# PGAC_C_STATIC_ASSERT
181
182
183
184 # PGAC_C_TYPEOF
185 # -------------
186 # Check if the C compiler understands typeof or a variant.  Define
187 # HAVE_TYPEOF if so, and define 'typeof' to the actual key word.
188 #
189 AC_DEFUN([PGAC_C_TYPEOF],
190 [AC_CACHE_CHECK(for typeof, pgac_cv_c_typeof,
191 [pgac_cv_c_typeof=no
192 for pgac_kw in typeof __typeof__ decltype; do
193   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
194 [int x = 0;
195 $pgac_kw(x) y;
196 y = x;
197 return y;])],
198 [pgac_cv_c_typeof=$pgac_kw])
199   test "$pgac_cv_c_typeof" != no && break
200 done])
201 if test "$pgac_cv_c_typeof" != no; then
202   AC_DEFINE(HAVE_TYPEOF, 1,
203             [Define to 1 if your compiler understands `typeof' or something similar.])
204   if test "$pgac_cv_c_typeof" != typeof; then
205     AC_DEFINE_UNQUOTED(typeof, $pgac_cv_c_typeof, [Define to how the compiler spells `typeof'.])
206   fi
207 fi])# PGAC_C_TYPEOF
208
209
210
211 # PGAC_C_TYPES_COMPATIBLE
212 # -----------------------
213 # Check if the C compiler understands __builtin_types_compatible_p,
214 # and define HAVE__BUILTIN_TYPES_COMPATIBLE_P if so.
215 #
216 # We check usage with __typeof__, though it's unlikely any compiler would
217 # have the former and not the latter.
218 AC_DEFUN([PGAC_C_TYPES_COMPATIBLE],
219 [AC_CACHE_CHECK(for __builtin_types_compatible_p, pgac_cv__types_compatible,
220 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
221 [[ int x; static int y[__builtin_types_compatible_p(__typeof__(x), int)]; ]])],
222 [pgac_cv__types_compatible=yes],
223 [pgac_cv__types_compatible=no])])
224 if test x"$pgac_cv__types_compatible" = xyes ; then
225 AC_DEFINE(HAVE__BUILTIN_TYPES_COMPATIBLE_P, 1,
226           [Define to 1 if your compiler understands __builtin_types_compatible_p.])
227 fi])# PGAC_C_TYPES_COMPATIBLE
228
229
230 # PGAC_C_BUILTIN_BSWAP16
231 # -------------------------
232 # Check if the C compiler understands __builtin_bswap16(),
233 # and define HAVE__BUILTIN_BSWAP16 if so.
234 AC_DEFUN([PGAC_C_BUILTIN_BSWAP16],
235 [AC_CACHE_CHECK(for __builtin_bswap16, pgac_cv__builtin_bswap16,
236 [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
237 [static unsigned long int x = __builtin_bswap16(0xaabb);]
238 )],
239 [pgac_cv__builtin_bswap16=yes],
240 [pgac_cv__builtin_bswap16=no])])
241 if test x"$pgac_cv__builtin_bswap16" = xyes ; then
242 AC_DEFINE(HAVE__BUILTIN_BSWAP16, 1,
243           [Define to 1 if your compiler understands __builtin_bswap16.])
244 fi])# PGAC_C_BUILTIN_BSWAP16
245
246
247
248 # PGAC_C_BUILTIN_BSWAP32
249 # -------------------------
250 # Check if the C compiler understands __builtin_bswap32(),
251 # and define HAVE__BUILTIN_BSWAP32 if so.
252 AC_DEFUN([PGAC_C_BUILTIN_BSWAP32],
253 [AC_CACHE_CHECK(for __builtin_bswap32, pgac_cv__builtin_bswap32,
254 [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
255 [static unsigned long int x = __builtin_bswap32(0xaabbccdd);]
256 )],
257 [pgac_cv__builtin_bswap32=yes],
258 [pgac_cv__builtin_bswap32=no])])
259 if test x"$pgac_cv__builtin_bswap32" = xyes ; then
260 AC_DEFINE(HAVE__BUILTIN_BSWAP32, 1,
261           [Define to 1 if your compiler understands __builtin_bswap32.])
262 fi])# PGAC_C_BUILTIN_BSWAP32
263
264
265
266 # PGAC_C_BUILTIN_BSWAP64
267 # -------------------------
268 # Check if the C compiler understands __builtin_bswap64(),
269 # and define HAVE__BUILTIN_BSWAP64 if so.
270 AC_DEFUN([PGAC_C_BUILTIN_BSWAP64],
271 [AC_CACHE_CHECK(for __builtin_bswap64, pgac_cv__builtin_bswap64,
272 [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
273 [static unsigned long int x = __builtin_bswap64(0xaabbccddeeff0011);]
274 )],
275 [pgac_cv__builtin_bswap64=yes],
276 [pgac_cv__builtin_bswap64=no])])
277 if test x"$pgac_cv__builtin_bswap64" = xyes ; then
278 AC_DEFINE(HAVE__BUILTIN_BSWAP64, 1,
279           [Define to 1 if your compiler understands __builtin_bswap64.])
280 fi])# PGAC_C_BUILTIN_BSWAP64
281
282
283
284 # PGAC_C_BUILTIN_CONSTANT_P
285 # -------------------------
286 # Check if the C compiler understands __builtin_constant_p(),
287 # and define HAVE__BUILTIN_CONSTANT_P if so.
288 # We need __builtin_constant_p("string literal") to be true, but some older
289 # compilers don't think that, so test for that case explicitly.
290 AC_DEFUN([PGAC_C_BUILTIN_CONSTANT_P],
291 [AC_CACHE_CHECK(for __builtin_constant_p, pgac_cv__builtin_constant_p,
292 [AC_COMPILE_IFELSE([AC_LANG_SOURCE(
293 [[static int x;
294   static int y[__builtin_constant_p(x) ? x : 1];
295   static int z[__builtin_constant_p("string literal") ? 1 : x];
296 ]]
297 )],
298 [pgac_cv__builtin_constant_p=yes],
299 [pgac_cv__builtin_constant_p=no])])
300 if test x"$pgac_cv__builtin_constant_p" = xyes ; then
301 AC_DEFINE(HAVE__BUILTIN_CONSTANT_P, 1,
302           [Define to 1 if your compiler understands __builtin_constant_p.])
303 fi])# PGAC_C_BUILTIN_CONSTANT_P
304
305
306
307 # PGAC_C_BUILTIN_OP_OVERFLOW
308 # -------------------------
309 # Check if the C compiler understands __builtin_$op_overflow(),
310 # and define HAVE__BUILTIN_OP_OVERFLOW if so.
311 #
312 # Check for the most complicated case, 64 bit multiplication, as a
313 # proxy for all of the operations. Have to link to be sure to
314 # recognize a missing __builtin_mul_overflow.
315 AC_DEFUN([PGAC_C_BUILTIN_OP_OVERFLOW],
316 [AC_CACHE_CHECK(for __builtin_mul_overflow, pgac_cv__builtin_op_overflow,
317 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
318 [PG_INT64_TYPE result;
319 __builtin_mul_overflow((PG_INT64_TYPE) 1, (PG_INT64_TYPE) 2, &result);]
320 )],
321 [pgac_cv__builtin_op_overflow=yes],
322 [pgac_cv__builtin_op_overflow=no])])
323 if test x"$pgac_cv__builtin_op_overflow" = xyes ; then
324 AC_DEFINE(HAVE__BUILTIN_OP_OVERFLOW, 1,
325           [Define to 1 if your compiler understands __builtin_$op_overflow.])
326 fi])# PGAC_C_BUILTIN_OP_OVERFLOW
327
328
329
330 # PGAC_C_BUILTIN_UNREACHABLE
331 # --------------------------
332 # Check if the C compiler understands __builtin_unreachable(),
333 # and define HAVE__BUILTIN_UNREACHABLE if so.
334 #
335 # NB: Don't get the idea of putting a for(;;); or such before the
336 # __builtin_unreachable() call.  Some compilers would remove it before linking
337 # and only a warning instead of an error would be produced.
338 AC_DEFUN([PGAC_C_BUILTIN_UNREACHABLE],
339 [AC_CACHE_CHECK(for __builtin_unreachable, pgac_cv__builtin_unreachable,
340 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
341 [__builtin_unreachable();])],
342 [pgac_cv__builtin_unreachable=yes],
343 [pgac_cv__builtin_unreachable=no])])
344 if test x"$pgac_cv__builtin_unreachable" = xyes ; then
345 AC_DEFINE(HAVE__BUILTIN_UNREACHABLE, 1,
346           [Define to 1 if your compiler understands __builtin_unreachable.])
347 fi])# PGAC_C_BUILTIN_UNREACHABLE
348
349
350
351 # PGAC_C_COMPUTED_GOTO
352 # -----------------------
353 # Check if the C compiler knows computed gotos (gcc extension, also
354 # available in at least clang).  If so, define HAVE_COMPUTED_GOTO.
355 #
356 # Checking whether computed gotos are supported syntax-wise ought to
357 # be enough, as the syntax is otherwise illegal.
358 AC_DEFUN([PGAC_C_COMPUTED_GOTO],
359 [AC_CACHE_CHECK(for computed goto support, pgac_cv_computed_goto,
360 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
361 [[void *labeladdrs[] = {&&my_label};
362   goto *labeladdrs[0];
363   my_label:
364   return 1;
365 ]])],
366 [pgac_cv_computed_goto=yes],
367 [pgac_cv_computed_goto=no])])
368 if test x"$pgac_cv_computed_goto" = xyes ; then
369 AC_DEFINE(HAVE_COMPUTED_GOTO, 1,
370           [Define to 1 if your compiler handles computed gotos.])
371 fi])# PGAC_C_COMPUTED_GOTO
372
373
374
375 # PGAC_C_VA_ARGS
376 # --------------
377 # Check if the C compiler understands C99-style variadic macros,
378 # and define HAVE__VA_ARGS if so.
379 AC_DEFUN([PGAC_C_VA_ARGS],
380 [AC_CACHE_CHECK(for __VA_ARGS__, pgac_cv__va_args,
381 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>],
382 [#define debug(...) fprintf(stderr, __VA_ARGS__)
383 debug("%s", "blarg");
384 ])],
385 [pgac_cv__va_args=yes],
386 [pgac_cv__va_args=no])])
387 if test x"$pgac_cv__va_args" = xyes ; then
388 AC_DEFINE(HAVE__VA_ARGS, 1,
389           [Define to 1 if your compiler understands __VA_ARGS__ in macros.])
390 fi])# PGAC_C_VA_ARGS
391
392
393
394 # PGAC_PROG_CC_CFLAGS_OPT
395 # -----------------------
396 # Given a string, check if the compiler supports the string as a
397 # command-line option. If it does, add the string to CFLAGS.
398 AC_DEFUN([PGAC_PROG_CC_CFLAGS_OPT],
399 [define([Ac_cachevar], [AS_TR_SH([pgac_cv_prog_cc_cflags_$1])])dnl
400 AC_CACHE_CHECK([whether $CC supports $1], [Ac_cachevar],
401 [pgac_save_CFLAGS=$CFLAGS
402 CFLAGS="$pgac_save_CFLAGS $1"
403 ac_save_c_werror_flag=$ac_c_werror_flag
404 ac_c_werror_flag=yes
405 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
406                    [Ac_cachevar=yes],
407                    [Ac_cachevar=no])
408 ac_c_werror_flag=$ac_save_c_werror_flag
409 CFLAGS="$pgac_save_CFLAGS"])
410 if test x"$Ac_cachevar" = x"yes"; then
411   CFLAGS="$CFLAGS $1"
412 fi
413 undefine([Ac_cachevar])dnl
414 ])# PGAC_PROG_CC_CFLAGS_OPT
415
416
417
418 # PGAC_PROG_CC_VAR_OPT
419 # -----------------------
420 # Given a variable name and a string, check if the compiler supports
421 # the string as a command-line option. If it does, add the string to
422 # the given variable.
423 AC_DEFUN([PGAC_PROG_CC_VAR_OPT],
424 [define([Ac_cachevar], [AS_TR_SH([pgac_cv_prog_cc_cflags_$2])])dnl
425 AC_CACHE_CHECK([whether $CC supports $2], [Ac_cachevar],
426 [pgac_save_CFLAGS=$CFLAGS
427 CFLAGS="$pgac_save_CFLAGS $2"
428 ac_save_c_werror_flag=$ac_c_werror_flag
429 ac_c_werror_flag=yes
430 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
431                    [Ac_cachevar=yes],
432                    [Ac_cachevar=no])
433 ac_c_werror_flag=$ac_save_c_werror_flag
434 CFLAGS="$pgac_save_CFLAGS"])
435 if test x"$Ac_cachevar" = x"yes"; then
436   $1="${$1} $2"
437 fi
438 undefine([Ac_cachevar])dnl
439 ])# PGAC_PROG_CC_VAR_OPT
440
441
442
443 # PGAC_PROG_CC_LDFLAGS_OPT
444 # ------------------------
445 # Given a string, check if the compiler supports the string as a
446 # command-line option. If it does, add the string to LDFLAGS.
447 # For reasons you'd really rather not know about, this checks whether
448 # you can link to a particular function, not just whether you can link.
449 # In fact, we must actually check that the resulting program runs :-(
450 AC_DEFUN([PGAC_PROG_CC_LDFLAGS_OPT],
451 [define([Ac_cachevar], [AS_TR_SH([pgac_cv_prog_cc_ldflags_$1])])dnl
452 AC_CACHE_CHECK([whether $CC supports $1], [Ac_cachevar],
453 [pgac_save_LDFLAGS=$LDFLAGS
454 LDFLAGS="$pgac_save_LDFLAGS $1"
455 AC_RUN_IFELSE([AC_LANG_PROGRAM([extern void $2 (); void (*fptr) () = $2;],[])],
456               [Ac_cachevar=yes],
457               [Ac_cachevar=no],
458               [Ac_cachevar="assuming no"])
459 LDFLAGS="$pgac_save_LDFLAGS"])
460 if test x"$Ac_cachevar" = x"yes"; then
461   LDFLAGS="$LDFLAGS $1"
462 fi
463 undefine([Ac_cachevar])dnl
464 ])# PGAC_PROG_CC_LDFLAGS_OPT
465
466 # PGAC_HAVE_GCC__SYNC_CHAR_TAS
467 # -------------------------
468 # Check if the C compiler understands __sync_lock_test_and_set(char),
469 # and define HAVE_GCC__SYNC_CHAR_TAS
470 #
471 # NB: There are platforms where test_and_set is available but compare_and_swap
472 # is not, so test this separately.
473 # NB: Some platforms only do 32bit tas, others only do 8bit tas. Test both.
474 AC_DEFUN([PGAC_HAVE_GCC__SYNC_CHAR_TAS],
475 [AC_CACHE_CHECK(for builtin __sync char locking functions, pgac_cv_gcc_sync_char_tas,
476 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
477   [char lock = 0;
478    __sync_lock_test_and_set(&lock, 1);
479    __sync_lock_release(&lock);])],
480   [pgac_cv_gcc_sync_char_tas="yes"],
481   [pgac_cv_gcc_sync_char_tas="no"])])
482 if test x"$pgac_cv_gcc_sync_char_tas" = x"yes"; then
483   AC_DEFINE(HAVE_GCC__SYNC_CHAR_TAS, 1, [Define to 1 if you have __sync_lock_test_and_set(char *) and friends.])
484 fi])# PGAC_HAVE_GCC__SYNC_CHAR_TAS
485
486 # PGAC_HAVE_GCC__SYNC_INT32_TAS
487 # -------------------------
488 # Check if the C compiler understands __sync_lock_test_and_set(),
489 # and define HAVE_GCC__SYNC_INT32_TAS
490 AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT32_TAS],
491 [AC_CACHE_CHECK(for builtin __sync int32 locking functions, pgac_cv_gcc_sync_int32_tas,
492 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
493   [int lock = 0;
494    __sync_lock_test_and_set(&lock, 1);
495    __sync_lock_release(&lock);])],
496   [pgac_cv_gcc_sync_int32_tas="yes"],
497   [pgac_cv_gcc_sync_int32_tas="no"])])
498 if test x"$pgac_cv_gcc_sync_int32_tas" = x"yes"; then
499   AC_DEFINE(HAVE_GCC__SYNC_INT32_TAS, 1, [Define to 1 if you have __sync_lock_test_and_set(int *) and friends.])
500 fi])# PGAC_HAVE_GCC__SYNC_INT32_TAS
501
502 # PGAC_HAVE_GCC__SYNC_INT32_CAS
503 # -------------------------
504 # Check if the C compiler understands __sync_compare_and_swap() for 32bit
505 # types, and define HAVE_GCC__SYNC_INT32_CAS if so.
506 AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT32_CAS],
507 [AC_CACHE_CHECK(for builtin __sync int32 atomic operations, pgac_cv_gcc_sync_int32_cas,
508 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
509   [int val = 0;
510    __sync_val_compare_and_swap(&val, 0, 37);])],
511   [pgac_cv_gcc_sync_int32_cas="yes"],
512   [pgac_cv_gcc_sync_int32_cas="no"])])
513 if test x"$pgac_cv_gcc_sync_int32_cas" = x"yes"; then
514   AC_DEFINE(HAVE_GCC__SYNC_INT32_CAS, 1, [Define to 1 if you have __sync_compare_and_swap(int *, int, int).])
515 fi])# PGAC_HAVE_GCC__SYNC_INT32_CAS
516
517 # PGAC_HAVE_GCC__SYNC_INT64_CAS
518 # -------------------------
519 # Check if the C compiler understands __sync_compare_and_swap() for 64bit
520 # types, and define HAVE_GCC__SYNC_INT64_CAS if so.
521 AC_DEFUN([PGAC_HAVE_GCC__SYNC_INT64_CAS],
522 [AC_CACHE_CHECK(for builtin __sync int64 atomic operations, pgac_cv_gcc_sync_int64_cas,
523 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
524   [PG_INT64_TYPE lock = 0;
525    __sync_val_compare_and_swap(&lock, 0, (PG_INT64_TYPE) 37);])],
526   [pgac_cv_gcc_sync_int64_cas="yes"],
527   [pgac_cv_gcc_sync_int64_cas="no"])])
528 if test x"$pgac_cv_gcc_sync_int64_cas" = x"yes"; then
529   AC_DEFINE(HAVE_GCC__SYNC_INT64_CAS, 1, [Define to 1 if you have __sync_compare_and_swap(int64 *, int64, int64).])
530 fi])# PGAC_HAVE_GCC__SYNC_INT64_CAS
531
532 # PGAC_HAVE_GCC__ATOMIC_INT32_CAS
533 # -------------------------
534 # Check if the C compiler understands __atomic_compare_exchange_n() for 32bit
535 # types, and define HAVE_GCC__ATOMIC_INT32_CAS if so.
536 AC_DEFUN([PGAC_HAVE_GCC__ATOMIC_INT32_CAS],
537 [AC_CACHE_CHECK(for builtin __atomic int32 atomic operations, pgac_cv_gcc_atomic_int32_cas,
538 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
539   [int val = 0;
540    int expect = 0;
541    __atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);])],
542   [pgac_cv_gcc_atomic_int32_cas="yes"],
543   [pgac_cv_gcc_atomic_int32_cas="no"])])
544 if test x"$pgac_cv_gcc_atomic_int32_cas" = x"yes"; then
545   AC_DEFINE(HAVE_GCC__ATOMIC_INT32_CAS, 1, [Define to 1 if you have __atomic_compare_exchange_n(int *, int *, int).])
546 fi])# PGAC_HAVE_GCC__ATOMIC_INT32_CAS
547
548 # PGAC_HAVE_GCC__ATOMIC_INT64_CAS
549 # -------------------------
550 # Check if the C compiler understands __atomic_compare_exchange_n() for 64bit
551 # types, and define HAVE_GCC__ATOMIC_INT64_CAS if so.
552 AC_DEFUN([PGAC_HAVE_GCC__ATOMIC_INT64_CAS],
553 [AC_CACHE_CHECK(for builtin __atomic int64 atomic operations, pgac_cv_gcc_atomic_int64_cas,
554 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
555   [PG_INT64_TYPE val = 0;
556    PG_INT64_TYPE expect = 0;
557    __atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);])],
558   [pgac_cv_gcc_atomic_int64_cas="yes"],
559   [pgac_cv_gcc_atomic_int64_cas="no"])])
560 if test x"$pgac_cv_gcc_atomic_int64_cas" = x"yes"; then
561   AC_DEFINE(HAVE_GCC__ATOMIC_INT64_CAS, 1, [Define to 1 if you have __atomic_compare_exchange_n(int64 *, int *, int64).])
562 fi])# PGAC_HAVE_GCC__ATOMIC_INT64_CAS
563
564 # PGAC_SSE42_CRC32_INTRINSICS
565 # -----------------------
566 # Check if the compiler supports the x86 CRC instructions added in SSE 4.2,
567 # using the _mm_crc32_u8 and _mm_crc32_u32 intrinsic functions. (We don't
568 # test the 8-byte variant, _mm_crc32_u64, but it is assumed to be present if
569 # the other ones are, on x86-64 platforms)
570 #
571 # An optional compiler flag can be passed as argument (e.g. -msse4.2). If the
572 # intrinsics are supported, sets pgac_sse42_crc32_intrinsics, and CFLAGS_SSE42.
573 AC_DEFUN([PGAC_SSE42_CRC32_INTRINSICS],
574 [define([Ac_cachevar], [AS_TR_SH([pgac_cv_sse42_crc32_intrinsics_$1])])dnl
575 AC_CACHE_CHECK([for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=$1], [Ac_cachevar],
576 [pgac_save_CFLAGS=$CFLAGS
577 CFLAGS="$pgac_save_CFLAGS $1"
578 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <nmmintrin.h>],
579   [unsigned int crc = 0;
580    crc = _mm_crc32_u8(crc, 0);
581    crc = _mm_crc32_u32(crc, 0);
582    /* return computed value, to prevent the above being optimized away */
583    return crc == 0;])],
584   [Ac_cachevar=yes],
585   [Ac_cachevar=no])
586 CFLAGS="$pgac_save_CFLAGS"])
587 if test x"$Ac_cachevar" = x"yes"; then
588   CFLAGS_SSE42="$1"
589   pgac_sse42_crc32_intrinsics=yes
590 fi
591 undefine([Ac_cachevar])dnl
592 ])# PGAC_SSE42_CRC32_INTRINSICS