Skip to content

Commit 3148ede

Browse files
committed
sync_builtin: check for 64-bit atomic support
This commit adds an additional check for 64-bit atomic support for __sync builtins. If 64-bit support is not available the opal_atomic_*_64 atomics are disabled. Signed-off-by: Nathan Hjelm <hjelmn@me.com>
1 parent 1911d74 commit 3148ede

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

config/opal_config_asm.m4

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ __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=yes],
108+
[AC_MSG_RESULT([no])
109+
opal_asm_sync_have_64bit=no])
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])
98113
])
99114

100115

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)