[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 10/80] tcg/i386: Add have_atomic16
|
From: |
Richard Henderson |
|
Subject: |
[PULL 10/80] tcg/i386: Add have_atomic16 |
|
Date: |
Tue, 16 May 2023 12:40:35 -0700 |
Notice when Intel or AMD have guaranteed that vmovdqa is atomic.
The new variable will also be used in generated code.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/qemu/cpuid.h | 18 ++++++++++++++++++
tcg/i386/tcg-target.h | 1 +
tcg/i386/tcg-target.c.inc | 27 +++++++++++++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/include/qemu/cpuid.h b/include/qemu/cpuid.h
index 1451e8ef2f..35325f1995 100644
--- a/include/qemu/cpuid.h
+++ b/include/qemu/cpuid.h
@@ -71,6 +71,24 @@
#define bit_LZCNT (1 << 5)
#endif
+/*
+ * Signatures for different CPU implementations as returned from Leaf 0.
+ */
+
+#ifndef signature_INTEL_ecx
+/* "Genu" "ineI" "ntel" */
+#define signature_INTEL_ebx 0x756e6547
+#define signature_INTEL_edx 0x49656e69
+#define signature_INTEL_ecx 0x6c65746e
+#endif
+
+#ifndef signature_AMD_ecx
+/* "Auth" "enti" "cAMD" */
+#define signature_AMD_ebx 0x68747541
+#define signature_AMD_edx 0x69746e65
+#define signature_AMD_ecx 0x444d4163
+#endif
+
static inline unsigned xgetbv_low(unsigned c)
{
unsigned a, d;
diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h
index d4f2a6f8c2..0421776cb8 100644
--- a/tcg/i386/tcg-target.h
+++ b/tcg/i386/tcg-target.h
@@ -120,6 +120,7 @@ extern bool have_avx512dq;
extern bool have_avx512vbmi2;
extern bool have_avx512vl;
extern bool have_movbe;
+extern bool have_atomic16;
/* optional instructions */
#define TCG_TARGET_HAS_div2_i32 1
diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
index 826f7764c9..911123cfa8 100644
--- a/tcg/i386/tcg-target.c.inc
+++ b/tcg/i386/tcg-target.c.inc
@@ -185,6 +185,7 @@ bool have_avx512dq;
bool have_avx512vbmi2;
bool have_avx512vl;
bool have_movbe;
+bool have_atomic16;
#ifdef CONFIG_CPUID_H
static bool have_bmi2;
@@ -4026,6 +4027,32 @@ static void tcg_target_init(TCGContext *s)
have_avx512dq = (b7 & bit_AVX512DQ) != 0;
have_avx512vbmi2 = (c7 & bit_AVX512VBMI2) != 0;
}
+
+ /*
+ * The 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.
+ *
+ * AMD has provided an even stronger guarantee that processors
+ * with AVX provide 16-byte atomicity for all cachable,
+ * naturally aligned single loads and stores, e.g. MOVDQU.
+ *
+ * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104688
+ */
+ if (have_avx1) {
+ __cpuid(0, a, b, c, d);
+ have_atomic16 = (c == signature_INTEL_ecx ||
+ c == signature_AMD_ecx);
+ }
}
}
}
--
2.34.1
- [PULL 00/80] tcg patch queue, Richard Henderson, 2023/05/16
- [PULL 02/80] include/exec/memop: Add MO_ATOM_*, Richard Henderson, 2023/05/16
- [PULL 01/80] tcg/i386: Set P_REXW in tcg_out_addi_ptr, Richard Henderson, 2023/05/16
- [PULL 03/80] accel/tcg: Honor atomicity of loads, Richard Henderson, 2023/05/16
- [PULL 07/80] tcg/tci: Use helper_{ld,st}*_mmu for user-only, Richard Henderson, 2023/05/16
- [PULL 05/80] tcg: Unify helper_{be,le}_{ld,st}*, Richard Henderson, 2023/05/16
- [PULL 09/80] meson: Detect atomic128 support with optimization, Richard Henderson, 2023/05/16
- [PULL 06/80] accel/tcg: Implement helper_{ld,st}*_mmu for user-only, Richard Henderson, 2023/05/16
- [PULL 08/80] tcg: Add 128-bit guest memory primitives, Richard Henderson, 2023/05/16
- [PULL 04/80] accel/tcg: Honor atomicity of stores, Richard Henderson, 2023/05/16
- [PULL 10/80] tcg/i386: Add have_atomic16,
Richard Henderson <=
- [PULL 11/80] tcg/aarch64: Detect have_lse, have_lse2 for linux, Richard Henderson, 2023/05/16
- [PULL 13/80] tcg/i386: Use full load/store helpers in user-only mode, Richard Henderson, 2023/05/16
- [PULL 14/80] tcg/aarch64: Use full load/store helpers in user-only mode, Richard Henderson, 2023/05/16
- [PULL 12/80] tcg/aarch64: Detect have_lse, have_lse2 for darwin, Richard Henderson, 2023/05/16
- [PULL 17/80] tcg/riscv: Use full load/store helpers in user-only mode, Richard Henderson, 2023/05/16
- [PULL 15/80] tcg/ppc: Use full load/store helpers in user-only mode, Richard Henderson, 2023/05/16
- [PULL 16/80] tcg/loongarch64: Use full load/store helpers in user-only mode, Richard Henderson, 2023/05/16
- [PULL 18/80] tcg/arm: Adjust constraints on qemu_ld/st, Richard Henderson, 2023/05/16
- [PULL 19/80] tcg/arm: Use full load/store helpers in user-only mode, Richard Henderson, 2023/05/16
- [PULL 20/80] tcg/mips: Use full load/store helpers in user-only mode, Richard Henderson, 2023/05/16