Skip to content

Commit f693886

Browse files
committed
Merge pull request #1659 from hjelmn/sync_64
sync_builtin: check for 64-bit atomic support
2 parents 8b534e9 + b2f33bc commit f693886

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

config/opal_config_asm.m4

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ __sync_add_and_fetch(&tmp, 1);],
9595
$1],
9696
[AC_MSG_RESULT([no])
9797
$2])
98+
99+
AC_MSG_CHECKING([for 64-bit __sync builtin atomics])
100+
101+
AC_TRY_LINK([
102+
#include <stdint.h>
103+
uint64_t tmp;], [
104+
__sync_bool_compare_and_swap(&tmp, 0, 1);
105+
__sync_add_and_fetch(&tmp, 1);],
106+
[AC_MSG_RESULT([yes])
107+
opal_asm_sync_have_64bit=1],
108+
[AC_MSG_RESULT([no])
109+
opal_asm_sync_have_64bit=0])
110+
111+
AC_DEFINE_UNQUOTED([OPAL_ASM_SYNC_HAVE_64BIT],[$opal_asm_sync_have_64bit],
112+
[Whether 64-bit is supported by the __sync builtin atomics])
113+
114+
# Check for 128-bit support
115+
OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128
98116
])
99117

100118

@@ -878,7 +896,6 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
878896
opal_cv_asm_builtin="BUILTIN_NO"
879897
if test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" = "yes" ; then
880898
OPAL_CHECK_SYNC_BUILTINS([opal_cv_asm_builtin="BUILTIN_SYNC"], [])
881-
OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128
882899
fi
883900
if test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_osx_builtin_atomics" = "yes" ; then
884901
AC_CHECK_HEADER([libkern/OSAtomic.h],
@@ -1009,6 +1026,12 @@ AC_MSG_ERROR([Can not continue.])
10091026
;;
10101027
esac
10111028
1029+
if test "x$OPAL_ASM_SUPPORT_64BIT" = "x1" && test "$opal_cv_asm_builtin" = "BUILTIN_SYNC" &&
1030+
test "$opal_asm_sync_have_64bit" = "0" ; then
1031+
# __sync builtins exist but do not implement 64-bit support. Fall back on inline asm.
1032+
opal_cv_asm_builtin="BUILTIN_NO"
1033+
fi
1034+
10121035
if test "$opal_cv_asm_builtin" = "BUILTIN_SYNC" ; then
10131036
AC_DEFINE([OPAL_C_GCC_INLINE_ASSEMBLY], [1],
10141037
[Whether C compiler supports GCC style inline assembly])

opal/include/opal/sys/sync_builtin/atomic.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2011 Sandia National Laboratories. All rights reserved.
14-
* Copyright (c) 2014 Los Alamos National Security, LLC. All rights
14+
* Copyright (c) 2014-2016 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* $COPYRIGHT$
1717
*
@@ -86,6 +86,8 @@ static inline int32_t opal_atomic_sub_32(volatile int32_t *addr, int32_t delta)
8686
return __sync_sub_and_fetch(addr, delta);
8787
}
8888

89+
#if OPAL_ASM_SYNC_HAVE_64BIT
90+
8991
#define OPAL_HAVE_ATOMIC_CMPSET_64 1
9092
static inline int opal_atomic_cmpset_acq_64( volatile int64_t *addr,
9193
int64_t oldval, int64_t newval)
@@ -105,17 +107,6 @@ static inline int opal_atomic_cmpset_64( volatile int64_t *addr,
105107
return __sync_bool_compare_and_swap(addr, oldval, newval);
106108
}
107109

108-
#if OPAL_HAVE_SYNC_BUILTIN_CSWAP_INT128
109-
static inline int opal_atomic_cmpset_128 (volatile opal_int128_t *addr,
110-
opal_int128_t oldval, opal_int128_t newval)
111-
{
112-
return __sync_bool_compare_and_swap(addr, oldval, newval);
113-
}
114-
115-
#define OPAL_HAVE_ATOMIC_CMPSET_128 1
116-
117-
#endif
118-
119110
#define OPAL_HAVE_ATOMIC_MATH_64 1
120111
#define OPAL_HAVE_ATOMIC_ADD_64 1
121112
static inline int64_t opal_atomic_add_64(volatile int64_t *addr, int64_t delta)
@@ -129,4 +120,17 @@ static inline int64_t opal_atomic_sub_64(volatile int64_t *addr, int64_t delta)
129120
return __sync_sub_and_fetch(addr, delta);
130121
}
131122

123+
#endif
124+
125+
#if OPAL_HAVE_SYNC_BUILTIN_CSWAP_INT128
126+
static inline int opal_atomic_cmpset_128 (volatile opal_int128_t *addr,
127+
opal_int128_t oldval, opal_int128_t newval)
128+
{
129+
return __sync_bool_compare_and_swap(addr, oldval, newval);
130+
}
131+
132+
#define OPAL_HAVE_ATOMIC_CMPSET_128 1
133+
134+
#endif
135+
132136
#endif /* ! OPAL_SYS_ARCH_ATOMIC_H */

0 commit comments

Comments
 (0)