diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-03-17 18:49:00 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-03-17 18:49:00 +0100 |
commit | 1d47c0512a265d4bb3ab9e56259fd1e4f4d42c75 (patch) | |
tree | 082d567edef178aee086ebdb67cb4de18ebd46d8 /libatomic/Makefile.am | |
parent | 78ef40ecdc1a442587703a4daed9141cf1ab87b2 (diff) | |
download | gcc-1d47c0512a265d4bb3ab9e56259fd1e4f4d42c75.zip gcc-1d47c0512a265d4bb3ab9e56259fd1e4f4d42c75.tar.gz gcc-1d47c0512a265d4bb3ab9e56259fd1e4f4d42c75.tar.bz2 |
libatomic: Improve 16-byte atomics on Intel AVX [PR104688]
As mentioned in the PR, the latest Intel SDM has added:
"Processors that enumerate support for Intel® AVX (by setting the feature flag CPUID.01H:ECX.AVX[bit 28])
guarantee that the 16-byte memory operations performed by the following instructions will always be
carried out atomically:
• MOVAPD, MOVAPS, and MOVDQA.
• VMOVAPD, VMOVAPS, and VMOVDQA when encoded with VEX.128.
• VMOVAPD, VMOVAPS, VMOVDQA32, and VMOVDQA64 when encoded with EVEX.128 and k0 (masking disabled).
(Note that these instructions require the linear addresses of their memory operands to be 16-byte
aligned.)"
The following patch deals with it just on the libatomic library side so far,
currently (since ~ 2017) we emit all the __atomic_* 16-byte builtins as
library calls since and this is something that we can hopefully backport.
The patch simply introduces yet another ifunc variant that takes priority
over the pure CMPXCHG16B one, one that checks AVX and CMPXCHG16B bits and
on non-Intel clears the AVX bit during detection for now (if AMD comes
with the same guarantee, we could revert the config/x86/init.c hunk),
which implements 16-byte atomic load as vmovdqa and 16-byte atomic store
as vmovdqa followed by mfence.
2022-03-17 Jakub Jelinek <jakub@redhat.com>
PR target/104688
* Makefile.am (IFUNC_OPTIONS): Change on x86_64 to -mcx16 -mcx16.
(libatomic_la_LIBADD): Add $(addsuffix _16_2_.lo,$(SIZEOBJS)) for
x86_64.
* Makefile.in: Regenerated.
* config/x86/host-config.h (IFUNC_COND_1): For x86_64 define to
both AVX and CMPXCHG16B bits.
(IFUNC_COND_2): Define.
(IFUNC_NCOND): For x86_64 define to 2 * (N == 16).
(MAYBE_HAVE_ATOMIC_CAS_16, MAYBE_HAVE_ATOMIC_EXCHANGE_16,
MAYBE_HAVE_ATOMIC_LDST_16): Define to IFUNC_COND_2 rather than
IFUNC_COND_1.
(HAVE_ATOMIC_CAS_16): Redefine to 1 whenever IFUNC_ALT != 0.
(HAVE_ATOMIC_LDST_16): Redefine to 1 whenever IFUNC_ALT == 1.
(atomic_compare_exchange_n): Define whenever IFUNC_ALT != 0
on x86_64 for N == 16.
(__atomic_load_n, __atomic_store_n): Redefine whenever IFUNC_ALT == 1
on x86_64 for N == 16.
(atomic_load_n, atomic_store_n): New functions.
* config/x86/init.c (__libat_feat1_init): On x86_64 clear bit_AVX
if CPU vendor is not Intel.
Diffstat (limited to 'libatomic/Makefile.am')
-rw-r--r-- | libatomic/Makefile.am | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am index 389f3dd..d88515e 100644 --- a/libatomic/Makefile.am +++ b/libatomic/Makefile.am @@ -138,8 +138,9 @@ IFUNC_OPTIONS = -march=i586 libatomic_la_LIBADD += $(addsuffix _8_1_.lo,$(SIZEOBJS)) endif if ARCH_X86_64 -IFUNC_OPTIONS = -mcx16 -libatomic_la_LIBADD += $(addsuffix _16_1_.lo,$(SIZEOBJS)) +IFUNC_OPTIONS = -mcx16 -mcx16 +libatomic_la_LIBADD += $(addsuffix _16_1_.lo,$(SIZEOBJS)) \ + $(addsuffix _16_2_.lo,$(SIZEOBJS)) endif endif |