Skip to content

Commit 799aedd

Browse files
committed
Make atomic cswap and swap mandatory
The compare and swap and swap atomic interfaces are de facto mandatory, as no code actually checks for their existance before using them (with the notable exception of the 128 bit cswap), so make those interfaces mandatory and remove all the complex code to detect implementations of them. At the same time, reorder the implementation files to all have consistent ordering of the cswap and swap implementations, to ease maintenance and move to a implementation includes the compatibility layer mode instead of the previous overly complex all in one software implementation model. Finally, remove the untyped macro wrappers as 1) no one uses them and 2) they're a pain to maintain. Signed-off-by: Brian Barrett <[email protected]>
1 parent 4ac5059 commit 799aedd

File tree

11 files changed

+630
-582
lines changed

11 files changed

+630
-582
lines changed

opal/include/opal/sys/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# Copyright (c) 2017 Research Organization for Information Science
1717
# and Technology (RIST). All rights reserved.
1818
# Copyright (c) 2020-2021 Google, LLC. All rights reserved.
19+
# Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
20+
# All Rights reserved.
1921
# $COPYRIGHT$
2022
#
2123
# Additional copyrights may follow
@@ -30,6 +32,8 @@ headers += \
3032
opal/sys/atomic.h \
3133
opal/sys/atomic_stdc.h \
3234
opal/sys/atomic_impl.h \
35+
opal/sys/atomic_impl_ptr_cswap.h \
36+
opal/sys/atomic_impl_ptr_swap.h \
3337
opal/sys/timer.h \
3438
opal/sys/cma.h
3539

opal/include/opal/sys/arm64/atomic.h

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030
#ifndef OPAL_SYS_ARCH_ATOMIC_H
3131
#define OPAL_SYS_ARCH_ATOMIC_H 1
3232

33-
#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1
34-
#define OPAL_HAVE_ATOMIC_SWAP_32 1
35-
#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1
36-
#define OPAL_HAVE_ATOMIC_SWAP_64 1
3733
#define OPAL_HAVE_ATOMIC_ADD_32 1
3834
#define OPAL_HAVE_ATOMIC_AND_32 1
3935
#define OPAL_HAVE_ATOMIC_OR_32 1
@@ -72,9 +68,10 @@ static inline void opal_atomic_isync(void)
7268
__asm__ __volatile__("isb");
7369
}
7470

71+
7572
/**********************************************************************
7673
*
77-
* Atomic math operations
74+
* Compare and Swap
7875
*
7976
*********************************************************************/
8077

@@ -99,20 +96,6 @@ static inline bool opal_atomic_compare_exchange_strong_32(opal_atomic_int32_t *a
9996
return ret;
10097
}
10198

102-
static inline int32_t opal_atomic_swap_32(opal_atomic_int32_t *addr, int32_t newval)
103-
{
104-
int32_t ret, tmp;
105-
106-
__asm__ __volatile__("1: ldaxr %w0, [%2] \n"
107-
" stlxr %w1, %w3, [%2] \n"
108-
" cbnz %w1, 1b \n"
109-
: "=&r"(ret), "=&r"(tmp)
110-
: "r"(addr), "r"(newval)
111-
: "cc", "memory");
112-
113-
return ret;
114-
}
115-
11699
/* these two functions aren't inlined in the non-gcc case because then
117100
there would be two function calls (since neither cmpset_32 nor
118101
atomic_?mb can be inlined). Instead, we "inline" them by hand in
@@ -182,21 +165,6 @@ static inline bool opal_atomic_compare_exchange_strong_64(opal_atomic_int64_t *a
182165
return ret;
183166
}
184167

185-
static inline int64_t opal_atomic_swap_64(opal_atomic_int64_t *addr, int64_t newval)
186-
{
187-
int64_t ret;
188-
int tmp;
189-
190-
__asm__ __volatile__("1: ldaxr %0, [%2] \n"
191-
" stlxr %w1, %3, [%2] \n"
192-
" cbnz %w1, 1b \n"
193-
: "=&r"(ret), "=&r"(tmp)
194-
: "r"(addr), "r"(newval)
195-
: "cc", "memory");
196-
197-
return ret;
198-
}
199-
200168
/* these two functions aren't inlined in the non-gcc case because then
201169
there would be two function calls (since neither cmpset_64 nor
202170
atomic_?mb can be inlined). Instead, we "inline" them by hand in
@@ -246,6 +214,53 @@ static inline bool opal_atomic_compare_exchange_strong_rel_64(opal_atomic_int64_
246214
return ret;
247215
}
248216

217+
#include "opal/sys/atomic_impl_ptr_cswap.h"
218+
219+
220+
/**********************************************************************
221+
*
222+
* Swap
223+
*
224+
*********************************************************************/
225+
226+
static inline int32_t opal_atomic_swap_32(opal_atomic_int32_t *addr, int32_t newval)
227+
{
228+
int32_t ret, tmp;
229+
230+
__asm__ __volatile__("1: ldaxr %w0, [%2] \n"
231+
" stlxr %w1, %w3, [%2] \n"
232+
" cbnz %w1, 1b \n"
233+
: "=&r"(ret), "=&r"(tmp)
234+
: "r"(addr), "r"(newval)
235+
: "cc", "memory");
236+
237+
return ret;
238+
}
239+
240+
static inline int64_t opal_atomic_swap_64(opal_atomic_int64_t *addr, int64_t newval)
241+
{
242+
int64_t ret;
243+
int tmp;
244+
245+
__asm__ __volatile__("1: ldaxr %0, [%2] \n"
246+
" stlxr %w1, %3, [%2] \n"
247+
" cbnz %w1, 1b \n"
248+
: "=&r"(ret), "=&r"(tmp)
249+
: "r"(addr), "r"(newval)
250+
: "cc", "memory");
251+
252+
return ret;
253+
}
254+
255+
#include "opal/sys/atomic_impl_ptr_swap.h"
256+
257+
258+
/**********************************************************************
259+
*
260+
* Atomic math operations
261+
*
262+
*********************************************************************/
263+
249264
#define OPAL_ASM_MAKE_ATOMIC(type, bits, name, inst, reg) \
250265
static inline type opal_atomic_fetch_##name##_##bits(opal_atomic_##type *addr, \
251266
type value) \

0 commit comments

Comments
 (0)