22dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
33dnl University Research and Technology
44dnl Corporation. All rights reserved.
5- dnl Copyright (c) 2004-2015 The University of Tennessee and The University
5+ dnl Copyright (c) 2004-2018 The University of Tennessee and The University
66dnl of Tennessee Research Foundation. All rights
77dnl reserved.
88dnl Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
2727
2828AC_DEFUN ( [ OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128] , [
2929
30- OPAL_VAR_SCOPE_PUSH([ sync_bool_compare_and_swap_128_result CFLAGS_save] )
30+ OPAL_VAR_SCOPE_PUSH([ sync_bool_compare_and_swap_128_result CFLAGS_save LDFLAGS_save ] )
3131
3232 AC_ARG_ENABLE ( [ cross-cmpset128] ,[ AC_HELP_STRING ([ --enable-cross-cmpset128] ,
3333 [ enable the use of the __sync builtin atomic compare-and-swap 128 when cross compiling] )] )
@@ -57,6 +57,22 @@ AC_DEFUN([OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128], [
5757
5858 CFLAGS=$CFLAGS_save
5959 fi
60+
61+ if test $sync_bool_compare_and_swap_128_result = 0 ; then
62+ LDFLAGS_save=$LDFLAGS
63+ LDFLAGS="$LDFLAGS -latomic"
64+
65+ AC_MSG_CHECKING ( [ for __sync builtin atomic compare-and-swap on 128-bit values with -latomic] )
66+ AC_RUN_IFELSE ( [ AC_LANG_PROGRAM ( [ ] , [ __int128 x = 0; __sync_bool_compare_and_swap (&x, 0, 1);] ) ] ,
67+ [ AC_MSG_RESULT ( [ yes] )
68+ sync_bool_compare_and_swap_128_result=1
69+ LDFLAGS_save="$LDFLAGS"] ,
70+ [ AC_MSG_RESULT ( [ no] ) ] ,
71+ [ AC_MSG_RESULT ( [ no (cross compiling)] ) ] )
72+
73+ LDFLAGS=$LDFLAGS_save
74+ fi
75+
6076 else
6177 AC_MSG_CHECKING ( [ for compiler support of __sync builtin atomic compare-and-swap on 128-bit values] )
6278
@@ -79,6 +95,21 @@ AC_DEFUN([OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128], [
7995
8096 CFLAGS=$CFLAGS_save
8197 fi
98+
99+ if test $sync_bool_compare_and_swap_128_result = 0 ; then
100+ LDFLAGS_save=$LDFLAGS
101+ LDFLAGS="$LDFLAGS -latomic"
102+
103+ AC_MSG_CHECKING ( [ for __sync builtin atomic compare-and-swap on 128-bit values with -latomic] )
104+ AC_TRY_LINK ( [ ] , [ __int128 x = 0; __sync_bool_compare_and_swap (&x, 0, 1);] ,
105+ [ AC_MSG_RESULT ( [ yes] )
106+ sync_bool_compare_and_swap_128_result=1
107+ LDFLAGS_save="$LDFLAGS"] ,
108+ [ AC_MSG_RESULT ( [ no] ) ] )
109+
110+ LDFLAGS=$LDFLAGS_save
111+ fi
112+
82113 fi
83114
84115 AC_DEFINE_UNQUOTED ( [ OPAL_HAVE_SYNC_BUILTIN_CSWAP_INT128] , [ $sync_bool_compare_and_swap_128_result] ,
@@ -120,7 +151,7 @@ __sync_add_and_fetch(&tmp, 1);],
120151
121152AC_DEFUN ( [ OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128] , [
122153
123- OPAL_VAR_SCOPE_PUSH([ atomic_compare_exchange_n_128_result CFLAGS_save] )
154+ OPAL_VAR_SCOPE_PUSH([ atomic_compare_exchange_n_128_result CFLAGS_save LDFLAGS_save ] )
124155
125156 AC_ARG_ENABLE ( [ cross-cmpset128] ,[ AC_HELP_STRING ([ --enable-cross-cmpset128] ,
126157 [ enable the use of the __sync builtin atomic compare-and-swap 128 when cross compiling] )] )
@@ -151,15 +182,35 @@ AC_DEFUN([OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128], [
151182 CFLAGS=$CFLAGS_save
152183 fi
153184
185+ if test $atomic_compare_exchange_n_128_result = 0 ; then
186+ LDFLAGS_save=$LDFLAGS
187+ LDFLAGS="$LDFLAGS -latomic"
188+
189+ AC_MSG_CHECKING ( [ for __atomic builtin atomic compare-and-swap on 128-bit values with -latomic] )
190+ AC_RUN_IFELSE ( [ AC_LANG_PROGRAM ( [ ] , [ __int128 x = 0, y = 0; __atomic_compare_exchange_n (&x, &y, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);] ) ] ,
191+ [ AC_MSG_RESULT ( [ yes] )
192+ atomic_compare_exchange_n_128_result=1
193+ LDFLAGS_save="$LDFLAGS"] ,
194+ [ AC_MSG_RESULT ( [ no] ) ] ,
195+ [ AC_MSG_RESULT ( [ no (cross compiling)] ) ] )
196+
197+ LDFLAGS=$LDFLAGS_save
198+ fi
199+
154200 if test $atomic_compare_exchange_n_128_result = 1 ; then
155- AC_MSG_CHECKING ( [ if __int128 atomic compare-and-swap is always lock-free] )
201+ AC_MSG_CHECKING ( [ if __int128 atomic compare-and-swap is always lock-free] )
156202 AC_RUN_IFELSE ( [ AC_LANG_PROGRAM ( [ ] , [ if (!__atomic_always_lock_free(16, 0)) { return 1; }] ) ] ,
157203 [ AC_MSG_RESULT ( [ yes] ) ] ,
158204 [ AC_MSG_RESULT ( [ no] )
205+ dnl Because of the variable PUSH/POP scope we need to manually unset these 2 variables
206+ dnl before going into OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128
207+ unset CFLAGS_save
208+ unset LDFLAGS_save
159209 OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128
160210 atomic_compare_exchange_n_128_result=0] ,
161211 [ AC_MSG_RESULT ( [ no (cross compiling)] ) ] )
162212 fi
213+
163214 else
164215 AC_MSG_CHECKING ( [ for compiler support of __atomic builtin atomic compare-and-swap on 128-bit values] )
165216
@@ -182,6 +233,21 @@ AC_DEFUN([OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128], [
182233
183234 CFLAGS=$CFLAGS_save
184235 fi
236+
237+ if test $atomic_compare_exchange_n_128_result = 0 ; then
238+ LDFLAGS_save=$LDFLAGS
239+ LDFLAGS="$LDFLAGS -latomic"
240+
241+ AC_MSG_CHECKING ( [ for __atomic builtin atomic compare-and-swap on 128-bit values with -latomic] )
242+ AC_TRY_LINK ( [ ] , [ __int128 x = 0, y = 0; __atomic_compare_exchange_n (&x, &y, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);] ,
243+ [ AC_MSG_RESULT ( [ yes] )
244+ atomic_compare_exchange_n_128_result=1
245+ LDFLAGS_save="$LDFLAGS"] ,
246+ [ AC_MSG_RESULT ( [ no] ) ] )
247+
248+ LDFLAGS=$LDFLAGS_save
249+ fi
250+
185251 fi
186252
187253 AC_DEFINE_UNQUOTED ( [ OPAL_HAVE_GCC_BUILTIN_CSWAP_INT128] , [ $atomic_compare_exchange_n_128_result] ,
0 commit comments