Skip to content

Commit 7590b31

Browse files
committed
LL/SC: be flexible with ret type
Do not use a temporary variable for holding the loaded value for ll/sc calls, eliminiating warnings about type mismatches for places where the compiler can implicitly cast into a register type anyway. This likely removes a slight bit of type safety, but also removes an ugly to fix warning about the use of typeof() on recent LLVM compilers that would be near impossible to fix and would hide all other warnings in noise. Given the relatively infrequent use of LL/SC and the ability to pay close attention when using it anyway, this is probably the more sane call. Signed-off-by: Brian Barrett <bbarrett@amazon.com>
1 parent 01a4ed9 commit 7590b31

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

opal/include/opal/sys/arm64/atomic_llsc.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@
3838
# define opal_atomic_ll_32(addr, ret) \
3939
do { \
4040
opal_atomic_int32_t *_addr = (addr); \
41-
int32_t _ret; \
4241
\
43-
__asm__ __volatile__("ldaxr %w0, [%1] \n" : "=&r"(_ret) : "r"(_addr)); \
44-
\
45-
ret = (typeof(ret)) _ret; \
42+
__asm__ __volatile__("ldaxr %w0, [%1] \n" : "=&r"(ret) : "r"(_addr)); \
4643
} while (0)
4744

4845
# define opal_atomic_sc_32(addr, newval, ret) \
@@ -62,11 +59,8 @@
6259
# define opal_atomic_ll_64(addr, ret) \
6360
do { \
6461
opal_atomic_int64_t *_addr = (addr); \
65-
int64_t _ret; \
66-
\
67-
__asm__ __volatile__("ldaxr %0, [%1] \n" : "=&r"(_ret) : "r"(_addr)); \
6862
\
69-
ret = (typeof(ret)) _ret; \
63+
__asm__ __volatile__("ldaxr %0, [%1] \n" : "=&r"(ret) : "r"(_addr)); \
7064
} while (0)
7165

7266
# define opal_atomic_sc_64(addr, newval, ret) \

opal/include/opal/sys/powerpc/atomic.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ static inline bool opal_atomic_compare_exchange_strong_32(opal_atomic_int32_t *a
139139
# define opal_atomic_ll_32(addr, ret) \
140140
do { \
141141
opal_atomic_int32_t *_addr = (addr); \
142-
int32_t _ret; \
143-
__asm__ __volatile__("lwarx %0, 0, %1 \n\t" : "=&r"(_ret) : "r"(_addr)); \
144-
ret = (typeof(ret)) _ret; \
142+
__asm__ __volatile__("lwarx %0, 0, %1 \n\t" : "=&r"(ret) : "r"(_addr)); \
145143
} while (0)
146144

147145
# define opal_atomic_sc_32(addr, value, ret) \
@@ -248,9 +246,7 @@ static inline bool opal_atomic_compare_exchange_strong_64(opal_atomic_int64_t *a
248246
# define opal_atomic_ll_64(addr, ret) \
249247
do { \
250248
opal_atomic_int64_t *_addr = (addr); \
251-
int64_t _ret; \
252-
__asm__ __volatile__("ldarx %0, 0, %1 \n\t" : "=&r"(_ret) : "r"(_addr)); \
253-
ret = (typeof(ret)) _ret; \
249+
__asm__ __volatile__("ldarx %0, 0, %1 \n\t" : "=&r"(ret) : "r"(_addr)); \
254250
} while (0)
255251

256252
# define opal_atomic_sc_64(addr, value, ret) \

0 commit comments

Comments
 (0)