Skip to content

Commit 8c5de45

Browse files
committed
Fix the detection of 128 bits atomics.
Thanks to Stefan Teleman for identifying this issue and providing a proof-of-concept patch. It turns out we were missing the check for the need of -latomic to get support for 128-bits atomics. Signed-off-by: George Bosilca <[email protected]>
1 parent 1b96be5 commit 8c5de45

File tree

2 files changed

+73
-7
lines changed

2 files changed

+73
-7
lines changed

config/opal_config_asm.m4

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ dnl
22
dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
33
dnl University Research and Technology
44
dnl 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
66
dnl of Tennessee Research Foundation. All rights
77
dnl reserved.
88
dnl Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
@@ -27,7 +27,7 @@ dnl
2727

2828
AC_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

121152
AC_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],

config/opal_functions.m4

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dnl
33
dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
44
dnl University Research and Technology
55
dnl Corporation. All rights reserved.
6-
dnl Copyright (c) 2004-2005 The University of Tennessee and The University
6+
dnl Copyright (c) 2004-2018 The University of Tennessee and The University
77
dnl of Tennessee Research Foundation. All rights
88
dnl reserved.
99
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -506,7 +506,7 @@ dnl #######################################################################
506506
dnl #######################################################################
507507
dnl #######################################################################
508508

509-
# Declare some variables; use OPAL_VAR_SCOPE_END to ensure that they
509+
# Declare some variables; use OPAL_VAR_SCOPE_POP to ensure that they
510510
# are cleaned up / undefined.
511511
AC_DEFUN([OPAL_VAR_SCOPE_PUSH],[
512512

@@ -524,7 +524,7 @@ AC_DEFUN([OPAL_VAR_SCOPE_PUSH],[
524524
eval $opal_str
525525

526526
if test "x$opal_str" != "x"; then
527-
AC_MSG_WARN([Found configure shell variable clash!])
527+
AC_MSG_WARN([Found configure shell variable clash at line $LINENO!])
528528
AC_MSG_WARN([[OPAL_VAR_SCOPE_PUSH] called on "$opal_var",])
529529
AC_MSG_WARN([but it is already defined with value "$opal_str"])
530530
AC_MSG_WARN([This usually indicates an error in configure.])

0 commit comments

Comments
 (0)