@@ -285,37 +285,6 @@ AC_DEFUN([OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128], [
285285 OPAL_VAR_SCOPE_POP
286286] )
287287
288- AC_DEFUN ( [ OPAL_CHECK_SYNC_BUILTINS] , [
289- AC_MSG_CHECKING ( [ for __sync builtin atomics] )
290-
291- AC_TRY_LINK ( [ long tmp;] , [ __sync_synchronize();
292- __sync_bool_compare_and_swap(&tmp, 0, 1);
293- __sync_add_and_fetch(&tmp, 1);] ,
294- [ AC_MSG_RESULT ( [ yes] )
295- $1 ] ,
296- [ AC_MSG_RESULT ( [ no] )
297- $2 ] )
298-
299- AC_MSG_CHECKING ( [ for 64-bit __sync builtin atomics] )
300-
301- AC_TRY_LINK ( [
302- #include <stdint.h>
303- uint64_t tmp;] , [
304- __sync_bool_compare_and_swap(&tmp, 0, 1);
305- __sync_add_and_fetch(&tmp, 1);] ,
306- [ AC_MSG_RESULT ( [ yes] )
307- opal_asm_sync_have_64bit=1] ,
308- [ AC_MSG_RESULT ( [ no] )
309- opal_asm_sync_have_64bit=0] )
310-
311- AC_DEFINE_UNQUOTED ( [ OPAL_ASM_SYNC_HAVE_64BIT] ,[ $opal_asm_sync_have_64bit] ,
312- [ Whether 64-bit is supported by the __sync builtin atomics] )
313-
314- # Check for 128-bit support
315- OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128
316- ] )
317-
318-
319288AC_DEFUN ( [ OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128] , [
320289 OPAL_VAR_SCOPE_PUSH([ atomic_compare_exchange_n_128_result atomic_compare_exchange_n_128_CFLAGS_save atomic_compare_exchange_n_128_LIBS_save] )
321290
@@ -361,9 +330,10 @@ AC_DEFUN([OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128], [
361330] )
362331
363332AC_DEFUN ( [ OPAL_CHECK_GCC_ATOMIC_BUILTINS] , [
364- AC_MSG_CHECKING ( [ for __atomic builtin atomics] )
333+ if test -z "$opal_cv_have___atomic" ; then
334+ AC_MSG_CHECKING ( [ for 32-bit GCC built-in atomics] )
365335
366- AC_TRY_LINK ( [
336+ AC_TRY_LINK ( [
367337#include <stdint.h>
368338uint32_t tmp, old = 0;
369339uint64_t tmp64, old64 = 0;] , [
@@ -372,13 +342,39 @@ __atomic_compare_exchange_n(&tmp, &old, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED
372342__atomic_add_fetch(&tmp, 1, __ATOMIC_RELAXED);
373343__atomic_compare_exchange_n(&tmp64, &old64, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
374344__atomic_add_fetch(&tmp64, 1, __ATOMIC_RELAXED);] ,
375- [ AC_MSG_RESULT ( [ yes] )
376- $1 ] ,
377- [ AC_MSG_RESULT ( [ no] )
378- $2 ] )
345+ [ opal_cv_have___atomic=yes] ,
346+ [ opal_cv_have___atomic=no] )
347+
348+ AC_MSG_RESULT ( [ $opal_cv_have___atomic] )
349+
350+ if test $opal_cv_have___atomic = "yes" ; then
351+ AC_MSG_CHECKING ( [ for 64-bit GCC built-in atomics] )
379352
380- # Check for 128-bit support
381- OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128
353+ AC_TRY_LINK ( [
354+ #include <stdint.h>
355+ uint64_t tmp64, old64 = 0;] , [
356+ __atomic_compare_exchange_n(&tmp64, &old64, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
357+ __atomic_add_fetch(&tmp64, 1, __ATOMIC_RELAXED);] ,
358+ [ opal_cv_have___atomic_64=yes] ,
359+ [ opal_cv_have___atomic_64=no] )
360+
361+ AC_MSG_RESULT ( [ $opal_cv_have___atomic_64] )
362+
363+ if test $opal_cv_have___atomic_64 = "yes" ; then
364+ AC_MSG_CHECKING ( [ if 64-bit GCC built-in atomics are lock-free] )
365+ AC_RUN_IFELSE ( [ AC_LANG_PROGRAM ( [ ] , [ if (!__atomic_is_lock_free (8, 0)) { return 1; }] ) ] ,
366+ [ AC_MSG_RESULT ( [ yes] ) ] ,
367+ [ AC_MSG_RESULT ( [ no] )
368+ opal_cv_have___atomic_64=no] ,
369+ [ AC_MSG_RESULT ( [ cannot test -- assume yes (cross compiling)] ) ] )
370+ fi
371+ else
372+ opal_cv_have___atomic_64=no
373+ fi
374+
375+ # Check for 128-bit support
376+ OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128
377+ fi
382378] )
383379
384380AC_DEFUN ( [ OPAL_CHECK_C11_CSWAP_INT128] , [
@@ -425,28 +421,6 @@ AC_DEFUN([OPAL_CHECK_C11_CSWAP_INT128], [
425421 OPAL_VAR_SCOPE_POP
426422] )
427423
428- AC_DEFUN ( [ OPAL_CHECK_GCC_ATOMIC_BUILTINS] , [
429- AC_MSG_CHECKING ( [ for __atomic builtin atomics] )
430-
431- AC_TRY_LINK ( [
432- #include <stdint.h>
433- uint32_t tmp, old = 0;
434- uint64_t tmp64, old64 = 0;] , [
435- __atomic_thread_fence(__ATOMIC_SEQ_CST);
436- __atomic_compare_exchange_n(&tmp, &old, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
437- __atomic_add_fetch(&tmp, 1, __ATOMIC_RELAXED);
438- __atomic_compare_exchange_n(&tmp64, &old64, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
439- __atomic_add_fetch(&tmp64, 1, __ATOMIC_RELAXED);] ,
440- [ AC_MSG_RESULT ( [ yes] )
441- $1 ] ,
442- [ AC_MSG_RESULT ( [ no] )
443- $2 ] )
444-
445- # Check for 128-bit support
446- OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128
447- ] )
448-
449-
450424dnl #################################################################
451425dnl
452426dnl OPAL_CHECK_ASM_TEXT
@@ -1142,24 +1116,25 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
11421116
11431117 AC_ARG_ENABLE ( [ builtin-atomics] ,
11441118 [ AC_HELP_STRING ([ --enable-builtin-atomics] ,
1145- [ Enable use of __sync builtin atomics (default: disabled )] )] )
1119+ [ Enable use of GCC built-in atomics (default: autodetect )] )] )
11461120
11471121 OPAL_CHECK_C11_CSWAP_INT128
1122+ opal_cv_asm_builtin="BUILTIN_NO"
1123+ OPAL_CHECK_GCC_ATOMIC_BUILTINS
11481124
11491125 if test "x$enable_c11_atomics" != "xno" && test "$opal_cv_c11_supported" = "yes" ; then
11501126 opal_cv_asm_builtin="BUILTIN_C11"
11511127 OPAL_CHECK_C11_CSWAP_INT128
11521128 elif test "x$enable_c11_atomics" = "xyes"; then
11531129 AC_MSG_WARN ( [ C11 atomics were requested but are not supported] )
11541130 AC_MSG_ERROR ( [ Cannot continue] )
1155- else
1156- opal_cv_asm_builtin="BUILTIN_NO"
1157- AS_IF ( [ test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" = "yes"] ,
1158- [ OPAL_CHECK_GCC_ATOMIC_BUILTINS([ opal_cv_asm_builtin="BUILTIN_GCC"] , [ ] )] )
1159- AS_IF ( [ test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" = "yes"] ,
1160- [ OPAL_CHECK_SYNC_BUILTINS([ opal_cv_asm_builtin="BUILTIN_SYNC"] , [ ] )] )
1161- AS_IF ( [ test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" = "yes"] ,
1162- [ AC_MSG_ERROR ( [ __sync builtin atomics requested but not found.] ) ] )
1131+ elif test "$enable_builtin_atomics" = "yes" ; then
1132+ if test $opal_cv_have___atomic = "yes" ; then
1133+ opal_cv_asm_builtin="BUILTIN_GCC"
1134+ else
1135+ AC_MSG_WARN ( [ GCC built-in atomics requested but not found.] )
1136+ AC_MSG_ERROR ( [ Cannot continue] )
1137+ fi
11631138 fi
11641139
11651140 OPAL_CHECK_ASM_PROC
@@ -1176,7 +1151,12 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
11761151 # find our architecture for purposes of assembly stuff
11771152 opal_cv_asm_arch="UNSUPPORTED"
11781153 OPAL_GCC_INLINE_ASSIGN=""
1179- OPAL_ASM_SUPPORT_64BIT=0
1154+ if test "$opal_cv_have___atomic_64" ; then
1155+ OPAL_ASM_SUPPORT_64BIT=1
1156+ else
1157+ OPAL_ASM_SUPPORT_64BIT=0
1158+ fi
1159+
11801160 case "${host}" in
11811161 x86_64-*x32)
11821162 opal_cv_asm_arch="X86_64"
@@ -1198,17 +1178,13 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
11981178 opal_cv_asm_arch="ARM64"
11991179 OPAL_ASM_SUPPORT_64BIT=1
12001180 OPAL_ASM_ARM_VERSION=8
1201- AC_DEFINE_UNQUOTED ( [ OPAL_ASM_ARM_VERSION] , [ $OPAL_ASM_ARM_VERSION] ,
1202- [ What ARM assembly version to use] )
12031181 OPAL_GCC_INLINE_ASSIGN='"mov %0, #0" : "=&r"(ret)'
12041182 ;;
12051183
12061184 armv7*|arm-*-linux-gnueabihf)
12071185 opal_cv_asm_arch="ARM"
12081186 OPAL_ASM_SUPPORT_64BIT=1
12091187 OPAL_ASM_ARM_VERSION=7
1210- AC_DEFINE_UNQUOTED ( [ OPAL_ASM_ARM_VERSION] , [ $OPAL_ASM_ARM_VERSION] ,
1211- [ What ARM assembly version to use] )
12121188 OPAL_GCC_INLINE_ASSIGN='"mov %0, #0" : "=&r"(ret)'
12131189 ;;
12141190
@@ -1217,8 +1193,6 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
12171193 OPAL_ASM_SUPPORT_64BIT=0
12181194 OPAL_ASM_ARM_VERSION=6
12191195 CCASFLAGS="$CCASFLAGS -march=armv7-a"
1220- AC_DEFINE_UNQUOTED ( [ OPAL_ASM_ARM_VERSION] , [ $OPAL_ASM_ARM_VERSION] ,
1221- [ What ARM assembly version to use] )
12221196 OPAL_GCC_INLINE_ASSIGN='"mov %0, #0" : "=&r"(ret)'
12231197 ;;
12241198
@@ -1269,37 +1243,27 @@ AC_MSG_ERROR([Can not continue.])
12691243 ;;
12701244
12711245 *)
1272- OPAL_CHECK_SYNC_BUILTINS([ opal_cv_asm_builtin="BUILTIN_SYNC"] ,
1273- [ AC_MSG_ERROR ( [ No atomic primitives available for $host] ) ] )
1274- ;;
1246+ if test $opal_cv_have___atomic = "yes" ; then
1247+ opal_cv_asm_builtin="BUILTIN_GCC"
1248+ else
1249+ AC_MSG_ERROR ( [ No atomic primitives available for $host] )
1250+ fi
1251+ ;;
12751252 esac
12761253
1277- if test "x$OPAL_ASM_SUPPORT_64BIT" = "x1" && test "$opal_cv_asm_builtin" = "BUILTIN_SYNC" &&
1278- test "$opal_asm_sync_have_64bit" = "0" ; then
1279- # __sync builtins exist but do not implement 64-bit support. Fall back on inline asm.
1280- opal_cv_asm_builtin="BUILTIN_NO"
1281- fi
1254+ if ! test -z "$OPAL_ASM_ARM_VERSION" ; then
1255+ AC_DEFINE_UNQUOTED ( [ OPAL_ASM_ARM_VERSION] , [ $OPAL_ASM_ARM_VERSION] ,
1256+ [ What ARM assembly version to use] )
1257+ fi
12821258
1283- if test "$opal_cv_asm_builtin" = "BUILTIN_SYNC" || test "$opal_cv_asm_builtin" = "BUILTIN_GCC" ; then
1284- AC_DEFINE ( [ OPAL_C_GCC_INLINE_ASSEMBLY] , [ 1] ,
1285- [ Whether C compiler supports GCC style inline assembly] )
1286- else
1287- AC_DEFINE_UNQUOTED ( [ OPAL_ASM_SUPPORT_64BIT] ,
1288- [ $OPAL_ASM_SUPPORT_64BIT] ,
1289- [ Whether we can do 64bit assembly operations or not. Should not be used outside of the assembly header files] )
1290- AC_SUBST ( [ OPAL_ASM_SUPPORT_64BIT] )
1291-
1292- #
1293- # figure out if we need any special function start / stop code
1294- #
1295- case $host_os in
1296- aix*)
1297- opal_asm_arch_config="aix"
1298- ;;
1299- *)
1300- opal_asm_arch_config="default"
1301- ;;
1302- esac
1259+ if test "$opal_cv_asm_builtin" = "BUILTIN_GCC" ; then
1260+ AC_DEFINE ( [ OPAL_C_GCC_INLINE_ASSEMBLY] , [ 1] ,
1261+ [ Whether C compiler supports GCC style inline assembly] )
1262+ else
1263+ AC_DEFINE_UNQUOTED ( [ OPAL_ASM_SUPPORT_64BIT] ,
1264+ [ $OPAL_ASM_SUPPORT_64BIT] ,
1265+ [ Whether we can do 64bit assembly operations or not. Should not be used outside of the assembly header files] )
1266+ AC_SUBST ( [ OPAL_ASM_SUPPORT_64BIT] )
13031267
13041268 opal_cv_asm_inline_supported="no"
13051269 # now that we know our architecture, try to inline assemble
@@ -1330,7 +1294,7 @@ AC_MSG_ERROR([Can not continue.])
13301294 AC_DEFINE_UNQUOTED ( [ OPAL_ASSEMBLY_FORMAT] , [ "$OPAL_ASSEMBLY_FORMAT"] ,
13311295 [ Format of assembly file] )
13321296 AC_SUBST ( [ OPAL_ASSEMBLY_FORMAT] )
1333- fi # if opal_cv_asm_builtin = BUILTIN_SYNC
1297+ fi # if opal_cv_asm_builtin = BUILTIN_GCC
13341298
13351299 result="OPAL_$opal_cv_asm_arch"
13361300 OPAL_ASSEMBLY_ARCH="$opal_cv_asm_arch"
@@ -1388,7 +1352,7 @@ AC_DEFUN([OPAL_ASM_FIND_FILE], [
13881352 AC_REQUIRE ( [ AC_PROG_GREP ] )
13891353 AC_REQUIRE ( [ AC_PROG_FGREP ] )
13901354
1391- if test "$opal_cv_asm_arch" != "WINDOWS" && test "$opal_cv_asm_builtin" != "BUILTIN_SYNC" && test "$opal_cv_asm_builtin" != " BUILTIN_GCC" && test "$opal_cv_asm_builtin" != "BUILTIN_OSX" && test "$opal_cv_asm_inline_arch" = "no" ; then
1355+ if test "$opal_cv_asm_arch" != "WINDOWS" && test "$opal_cv_asm_builtin" != "BUILTIN_GCC" && test "$opal_cv_asm_builtin" != "BUILTIN_OSX" && test "$opal_cv_asm_inline_arch" = "no" ; then
13921356 AC_MSG_ERROR ( [ no atomic support available. exiting] )
13931357else
13941358 # On windows with VC++, atomics are done with compiler primitives
0 commit comments