Skip to content

Commit

Permalink
qemu/atomic128: Improve cmpxchg fallback for atomic16_set
Browse files Browse the repository at this point in the history
Use __sync_bool_compare_and_swap_16 to control the loop,
rather than a separate comparison.

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed May 24, 2023
1 parent 427fbf3 commit b35b812
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions host/include/generic/host/atomic128-ldst.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ atomic16_read_rw(Int128 *ptr)
static inline void ATTRIBUTE_ATOMIC128_OPT
atomic16_set(Int128 *ptr, Int128 val)
{
Int128 old = *ptr, cmp;
__int128_t *ptr_align = __builtin_assume_aligned(ptr, 16);
__int128_t old;
Int128Alias new;

new.s = val;
do {
cmp = old;
old = atomic16_cmpxchg(ptr, cmp, val);
} while (int128_ne(old, cmp));
old = *ptr_align;
} while (!__sync_bool_compare_and_swap_16(ptr_align, old, new.i));
}

#else
Expand Down

0 comments on commit b35b812

Please sign in to comment.