]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
atomic: Consolidate atomic_read_barrier implementation
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 11 Sep 2025 13:49:45 +0000 (10:49 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 4 Nov 2025 07:14:01 +0000 (04:14 -0300)
All ABIs, except alpha, powerpc, and x86_64, define it to
atomic_full_barrier/__sync_synchronize, which can be mapped to
__atomic_thread_fence (__ATOMIC_SEQ_CST) in most cases, with the
exception of aarch64 (where the acquire fence is generated as
'dmb ishld' instead of 'dmb ish').

For s390x, it defaults to a memory barrier where __sync_synchronize
emits a 'bcr 15,0' (which the manual describes as pipeline
synchronization).

For PowerPC, it allows the use of lwsync for additional chips
(since _ARCH_PWR4 does not cover all chips that support it).

Tested on aarch64-linux-gnu, where the acquire produces a different
instruction that the current code.

Co-authored-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
include/atomic.h
sysdeps/alpha/atomic-machine.h
sysdeps/generic/malloc-machine.h
sysdeps/powerpc/atomic-machine.h
sysdeps/x86/atomic-machine.h

index 227c4cdf27baae1c2a6e338fa7cbbd94cefc46ef..866c11c11f04def0c2802e577ca55cac77b975e7 100644 (file)
 
 
 #ifndef atomic_read_barrier
-# define atomic_read_barrier() atomic_full_barrier ()
+# define atomic_read_barrier() __atomic_thread_fence (__ATOMIC_ACQUIRE);
 #endif
 
 
index a1d74a930e8a0a04dfec4a0bc764f410ea0c9f0d..198f5dc037cb7d6f923123e84647f40dd3de1721 100644 (file)
@@ -22,5 +22,4 @@
 /* XXX Is this actually correct?  */
 #define ATOMIC_EXCHANGE_USES_CAS 1
 
-#define atomic_read_barrier()  __asm ("mb" : : : "memory");
 #define atomic_write_barrier() __asm ("wmb" : : : "memory");
index 195fd8c5e6f6acf327c2751330915366fd100344..4fb8e809ccb7fa608b6edbf495498e7f10414687 100644 (file)
 
 #include <atomic.h>
 
-#ifndef atomic_read_barrier
-# define atomic_read_barrier() atomic_full_barrier ()
-#endif
-
 #ifndef atomic_write_barrier
 # define atomic_write_barrier() atomic_full_barrier ()
 #endif
index 65c774a06404f091b6347737cc016987061c5726..e173b61e9cde70c6ed161299b89b52e4ad9429f8 100644 (file)
 #endif
 
 #ifdef _ARCH_PWR4
-/*
- * Newer powerpc64 processors support the new "light weight" sync (lwsync)
- * So if the build is using -mcpu=[power4,power5,power5+,970] we can
- * safely use lwsync.
- */
-# define atomic_read_barrier() __asm ("lwsync" ::: "memory")
 /*
  * "light weight" sync can also be used for the release barrier.
  */
 # define atomic_write_barrier()        __asm ("lwsync" ::: "memory")
 #else
-/*
- * Older powerpc32 processors don't support the new "light weight"
- * sync (lwsync).  So the only safe option is to use normal sync
- * for all powerpc32 applications.
- */
-# define atomic_read_barrier() __asm ("sync" ::: "memory")
 # define atomic_write_barrier()        __asm ("sync" ::: "memory")
 #endif
 
index 97d9c99fa68310647ce4b0e8644a84bd09c1c19b..f46a0868e3ecc59902c92807e6bec6c7491463f5 100644 (file)
@@ -31,7 +31,6 @@
 
 #define ATOMIC_EXCHANGE_USES_CAS       0
 
-#define atomic_read_barrier() __asm ("" ::: "memory")
 #define atomic_write_barrier() __asm ("" ::: "memory")
 
 #define atomic_spin_nop() __asm ("pause")