diff mbox series

[4/4] include/qemu/atomic128: Avoid __sync_val_compare_and_swap_16

Message ID 20221024232435.3334600-5-richard.henderson@linaro.org
State New
Headers show
Series atomic: Friendlier assertions, avoidance of __sync | expand

Commit Message

Richard Henderson Oct. 24, 2022, 11:24 p.m. UTC
Merge the CONFIG_ATOMIC128 and CONFIG_CMPXCHG128 cases
with respect to atomic16_cmpxchg and use
__atomic_compare_exchange_nomic (via qatomic_cmpxchg)
instead of the "legacy" __sync_val_compare_and_swap_16.

Update the meson has_cmpxchg128 test to match.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/qemu/atomic128.h | 8 +-------
 meson.build              | 3 ++-
 2 files changed, 3 insertions(+), 8 deletions(-)

Comments

Richard Henderson Oct. 25, 2022, 1:59 a.m. UTC | #1
On 10/25/22 09:24, Richard Henderson wrote:
> Merge the CONFIG_ATOMIC128 and CONFIG_CMPXCHG128 cases
> with respect to atomic16_cmpxchg and use
> __atomic_compare_exchange_nomic (via qatomic_cmpxchg)
> instead of the "legacy" __sync_val_compare_and_swap_16.
> 
> Update the meson has_cmpxchg128 test to match.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   include/qemu/atomic128.h | 8 +-------
>   meson.build              | 3 ++-
>   2 files changed, 3 insertions(+), 8 deletions(-)

Ho hum.  Must drop this one since for reasons that I cannot fathom, x86_64 does not 
implement the __atomic version.


r~
diff mbox series

Patch

diff --git a/include/qemu/atomic128.h b/include/qemu/atomic128.h
index adb9a1a260..ec45754515 100644
--- a/include/qemu/atomic128.h
+++ b/include/qemu/atomic128.h
@@ -41,18 +41,12 @@ 
  * Therefore, special case each platform.
  */
 
-#if defined(CONFIG_ATOMIC128)
+#if defined(CONFIG_ATOMIC128) || defined(CONFIG_CMPXCHG128)
 static inline Int128 atomic16_cmpxchg(Int128 *ptr, Int128 cmp, Int128 new)
 {
     return qatomic_cmpxchg__nocheck(ptr, cmp, new);
 }
 # define HAVE_CMPXCHG128 1
-#elif defined(CONFIG_CMPXCHG128)
-static inline Int128 atomic16_cmpxchg(Int128 *ptr, Int128 cmp, Int128 new)
-{
-    return __sync_val_compare_and_swap_16(ptr, cmp, new);
-}
-# define HAVE_CMPXCHG128 1
 #elif defined(__aarch64__)
 /* Through gcc 8, aarch64 has no support for 128-bit at all.  */
 static inline Int128 atomic16_cmpxchg(Int128 *ptr, Int128 cmp, Int128 new)
diff --git a/meson.build b/meson.build
index 1ec3f72edc..d8c4e76e7b 100644
--- a/meson.build
+++ b/meson.build
@@ -2224,7 +2224,8 @@  if has_int128
       int main(void)
       {
         unsigned __int128 x = 0, y = 0;
-        __sync_val_compare_and_swap_16(&x, y, x);
+        __atomic_compare_exchange_n(&x, &y, x, 0,
+            __ATOMIC_RELAXED, __ATOMIC_RELAXED);
         return 0;
       }
     ''')