Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
accel/tcg: Add aarch64 store_atom_insert_al16
Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-2.0-or-later | ||
| * Atomic store insert into 128-bit, AArch64 version. | ||
| * | ||
| * Copyright (C) 2023 Linaro, Ltd. | ||
| */ | ||
|
|
||
| #ifndef AARCH64_STORE_INSERT_AL16_H | ||
| #define AARCH64_STORE_INSERT_AL16_H | ||
|
|
||
| /** | ||
| * store_atom_insert_al16: | ||
| * @p: host address | ||
| * @val: shifted value to store | ||
| * @msk: mask for value to store | ||
| * | ||
| * Atomically store @val to @p masked by @msk. | ||
| */ | ||
| static inline void ATTRIBUTE_ATOMIC128_OPT | ||
| store_atom_insert_al16(Int128 *ps, Int128 val, Int128 msk) | ||
| { | ||
| /* | ||
| * GCC only implements __sync* primitives for int128 on aarch64. | ||
| * We can do better without the barriers, and integrating the | ||
| * arithmetic into the load-exclusive/store-conditional pair. | ||
| */ | ||
| uint64_t tl, th, vl, vh, ml, mh; | ||
| uint32_t fail; | ||
|
|
||
| qemu_build_assert(!HOST_BIG_ENDIAN); | ||
| vl = int128_getlo(val); | ||
| vh = int128_gethi(val); | ||
| ml = int128_getlo(msk); | ||
| mh = int128_gethi(msk); | ||
|
|
||
| asm("0: ldxp %[l], %[h], %[mem]\n\t" | ||
| "bic %[l], %[l], %[ml]\n\t" | ||
| "bic %[h], %[h], %[mh]\n\t" | ||
| "orr %[l], %[l], %[vl]\n\t" | ||
| "orr %[h], %[h], %[vh]\n\t" | ||
| "stxp %w[f], %[l], %[h], %[mem]\n\t" | ||
| "cbnz %w[f], 0b\n" | ||
| : [mem] "+Q"(*ps), [f] "=&r"(fail), [l] "=&r"(tl), [h] "=&r"(th) | ||
| : [vl] "r"(vl), [vh] "r"(vh), [ml] "r"(ml), [mh] "r"(mh)); | ||
| } | ||
|
|
||
| #endif /* AARCH64_STORE_INSERT_AL16_H */ |