@@ -25,6 +25,50 @@ dnl $HEADER$
25
25
dnl
26
26
27
27
28
+ AC_DEFUN ( [ OPAL_CHECK_C11_CSWAP_INT128] , [
29
+
30
+ OPAL_VAR_SCOPE_PUSH([ c11_compare_and_swap_128_result c11_CFLAGS_save] )
31
+
32
+ AC_ARG_ENABLE ( [ cross-cmpset128] ,[ AC_HELP_STRING ([ --enable-cross-cmpset128] ,
33
+ [ enable the use of the C11 atomic compare-and-swap 128 when cross compiling] )] )
34
+
35
+ c11_compare_and_swap_128_result=0
36
+
37
+ # This test specifically DOES NOT use -latomic because we do not want a lock-based atomic
38
+ for flag in "" "-mcx16" ; do
39
+ c11_CFLAGS_save=$CFLAGS
40
+ if test "x$flag" != "x" ; then
41
+ AC_MSG_CHECKING ( [ for compiler support for C11 atomic compare-and-swap on 128-bit values with flag $flag] )
42
+ CFLAGS="$CFLAGS $flag"
43
+ else
44
+ AC_MSG_CHECKING ( [ for compiler support for C11 atomic compare-and-swap on 128-bit values] )
45
+ fi
46
+
47
+ if test ! "$enable_cross_cmpset128" = "yes" ; then
48
+ AC_RUN_IFELSE ( [ AC_LANG_PROGRAM ( [ #include <stdatomic.h>] , [ __int128 x = 0; atomic_compare_exchange_strong (&x, &(__int128){0}, 1); return !atomic_is_lock_free(&x);] ) ] ,
49
+ [ AC_MSG_RESULT ( [ yes] ) ; c11_compare_and_swap_128_result=1; break] ,
50
+ [ AC_MSG_RESULT ( [ no] ) ] , [ AC_MSG_RESULT ( [ no (cross compiling)] ) ] )
51
+ else
52
+ AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ #include <stdatomic.h>] , [ __int128 x = 0; atomic_compare_exchange_strong (&x, &(__int128){0}, 1);] ) ] ,
53
+ [ AC_MSG_RESULT ( [ yes] ) ; c11_compare_and_swap_128_result=1; break] ,
54
+ [ AC_MSG_RESULT ( [ no] ) ] )
55
+ fi
56
+
57
+ CFLAGS=$c11_CFLAGS_save
58
+ done
59
+
60
+ AC_DEFINE_UNQUOTED ( [ OPAL_HAVE_C11_CSWAP_INT128] , [ $c11_compare_and_swap_128_result] ,
61
+ [ Whether the compiler support C11 atomic compare and swap supports 128-bit values] )
62
+
63
+ # For x86_64 systems it is impossible to get cmpxchng16b to be used do to slow reads of atomic variables. In Open MPI
64
+ # we are careful to read these values in consistent way so use __sync instead.
65
+ if test $c11_compare_and_swap_128_result = 0 ; then
66
+ OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128
67
+ fi
68
+
69
+ OPAL_VAR_SCOPE_POP
70
+ ] )
71
+
28
72
AC_DEFUN ( [ OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128] , [
29
73
30
74
OPAL_VAR_SCOPE_PUSH([ sync_bool_compare_and_swap_128_result CFLAGS_save] )
@@ -911,17 +955,27 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
911
955
AC_REQUIRE ( [ OPAL_SETUP_CC] )
912
956
AC_REQUIRE ( [ AM_PROG_AS ] )
913
957
958
+ AC_ARG_ENABLE ( [ c11-atomics] ,[ AC_HELP_STRING ([ --enable-c11-atomics] ,
959
+ [ Enable use of C11 atomics if available (default: enabled)] )] )
960
+
914
961
AC_ARG_ENABLE ( [ builtin-atomics] ,
915
962
[ AC_HELP_STRING ([ --enable-builtin-atomics] ,
916
- [ Enable use of __sync builtin atomics (default: enabled)] )] )
917
-
918
- opal_cv_asm_builtin="BUILTIN_NO"
919
- AS_IF ( [ test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" != "no"] ,
920
- [ OPAL_CHECK_GCC_ATOMIC_BUILTINS([ opal_cv_asm_builtin="BUILTIN_GCC"] , [ ] )] )
921
- AS_IF ( [ test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" != "no"] ,
922
- [ OPAL_CHECK_SYNC_BUILTINS([ opal_cv_asm_builtin="BUILTIN_SYNC"] , [ ] )] )
923
- AS_IF ( [ test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" = "yes"] ,
924
- [ AC_MSG_ERROR ( [ __sync builtin atomics requested but not found.] ) ] )
963
+ [ Enable use of __sync builtin atomics (default: disabled)] )] )
964
+
965
+ OPAL_CHECK_C11_CSWAP_INT128
966
+
967
+ if test "x$enable_c11_atomics" != "no" && test "$opal_cv_c11_supported" = "yes" ; then
968
+ opal_cv_asm_builtin="BUILTIN_C11"
969
+ OPAL_CHECK_C11_CSWAP_INT128
970
+ else
971
+ opal_cv_asm_builtin="BUILTIN_NO"
972
+ AS_IF ( [ test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" = "yes"] ,
973
+ [ OPAL_CHECK_GCC_ATOMIC_BUILTINS([ opal_cv_asm_builtin="BUILTIN_GCC"] , [ ] )] )
974
+ AS_IF ( [ test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" = "yes"] ,
975
+ [ OPAL_CHECK_SYNC_BUILTINS([ opal_cv_asm_builtin="BUILTIN_SYNC"] , [ ] )] )
976
+ AS_IF ( [ test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" = "yes"] ,
977
+ [ AC_MSG_ERROR ( [ __sync builtin atomics requested but not found.] ) ] )
978
+ fi
925
979
926
980
OPAL_CHECK_ASM_PROC
927
981
OPAL_CHECK_ASM_TEXT
0 commit comments