On Fri, 15 Aug 2025 at 13:28, Richard Henderson
<richard.hender...@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.hender...@linaro.org>
> ---
>  host/include/aarch64/host/atomic128-cas.h.inc | 57 +++++++++++
>  host/include/generic/host/atomic128-cas.h.inc | 96 +++++++++++++++++++
>  2 files changed, 153 insertions(+)
>
> diff --git a/host/include/aarch64/host/atomic128-cas.h.inc 
> b/host/include/aarch64/host/atomic128-cas.h.inc
> index 991da4ef54..aec27df182 100644
> --- a/host/include/aarch64/host/atomic128-cas.h.inc
> +++ b/host/include/aarch64/host/atomic128-cas.h.inc
> @@ -38,6 +38,63 @@ static inline Int128 atomic16_cmpxchg(Int128 *ptr, Int128 
> cmp, Int128 new)
>      return int128_make128(oldl, oldh);
>  }
>
> +static inline Int128 atomic16_xchg(Int128 *ptr, Int128 new)
> +{
> +    uint64_t newl = int128_getlo(new), newh = int128_gethi(new);
> +    uint64_t oldl, oldh;
> +    uint32_t tmp;
> +
> +    asm("0: ldaxp %[oldl], %[oldh], %[mem]\n\t"

This looks like it won't do the right thing on a big-endian
host, but nor will the existing atomic16_cmpxchg(), so
I assume we don't care about that particular unicorn.

> +        "stlxp %w[tmp], %[newl], %[newh], %[mem]\n\t"
> +        "cbnz %w[tmp], 0b"
> +        : [mem] "+m"(*ptr), [tmp] "=&r"(tmp),
> +          [oldl] "=&r"(oldl), [oldh] "=&r"(oldh)
> +        : [newl] "r"(newl), [newh] "r"(newh)
> +        : "memory");
> +    return int128_make128(oldl, oldh);
> +}

Reviewed-by: Peter Maydell <peter.mayd...@linaro.org>

-- PMM

Reply via email to