[PATCH 2/3] host/x86_64: Implement atomic64_set with MOVDIR64B

Richard Henderson <[email protected]>
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel
Message-ID <[email protected]>
Detect the host feature in cpuid, then use it.

Signed-off-by: Richard Henderson <[email protected]>
---
 host/include/x86_64/host/cpuinfo.h            |  1 +
 include/qemu/cpuid.h                          |  3 +++
 util/cpuinfo-i386.c                           |  1 +
 host/include/x86_64/host/atomic512-ldst.h.inc | 21 +++++++++++++++++++
 4 files changed, 26 insertions(+)
 create mode 100644 host/include/x86_64/host/atomic512-ldst.h.inc

diff --git a/host/include/x86_64/host/cpuinfo.h b/host/include/x86_64/host/cpuinfo.h
index 93d029d499..34c4334f3d 100644
--- a/host/include/x86_64/host/cpuinfo.h
+++ b/host/include/x86_64/host/cpuinfo.h
@@ -28,6 +28,7 @@
 #define CPUINFO_AES             (1u << 18)
 #define CPUINFO_PCLMUL          (1u << 19)
 #define CPUINFO_GFNI            (1u << 20)
+#define CPUINFO_MOVDIR64B       (1u << 21)
 
 /* Initialized with a constructor. */
 extern unsigned cpuinfo;
diff --git a/include/qemu/cpuid.h b/include/qemu/cpuid.h
index de7a900509..435fc7af9c 100644
--- a/include/qemu/cpuid.h
+++ b/include/qemu/cpuid.h
@@ -71,6 +71,9 @@
 #ifndef bit_GFNI
 #define bit_GFNI        (1 << 8)
 #endif
+#ifndef bit_MOVDIR64B
+#define bit_MOVDIR64B   (1 << 28)
+#endif
 
 /* Leaf 0x80000001, %ecx */
 #ifndef bit_LZCNT
diff --git a/util/cpuinfo-i386.c b/util/cpuinfo-i386.c
index f4c5b6ff40..bb88abcf8f 100644
--- a/util/cpuinfo-i386.c
+++ b/util/cpuinfo-i386.c
@@ -29,6 +29,7 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)
         __cpuid_count(7, 0, a, b7, c7, d);
         info |= (b7 & bit_BMI ? CPUINFO_BMI1 : 0);
         info |= (b7 & bit_BMI2 ? CPUINFO_BMI2 : 0);
+        info |= (c7 & bit_MOVDIR64B ? CPUINFO_MOVDIR64B : 0);
     }
 
     if (max >= 1) {
diff --git a/host/include/x86_64/host/atomic512-ldst.h.inc b/host/include/x86_64/host/atomic512-ldst.h.inc
new file mode 100644
index 0000000000..7db9a0b753
--- /dev/null
+++ b/host/include/x86_64/host/atomic512-ldst.h.inc
@@ -0,0 +1,21 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * Load/store for 512-bit atomic operations, generic version.
+ */
+
+#ifndef HOST_ATOMIC512_LDST_H
+#define HOST_ATOMIC512_LDST_H
+
+#include "host/cpuinfo.h"
+
+#define HAVE_ATOMIC512_LD 0
+#define HAVE_ATOMIC512_ST likely(cpuinfo & CPUINFO_MOVDIR64B)
+
+Value64 QEMU_ERROR("unsupported atomic") atomic64_read(const void *s);
+
+static inline void atomic64_set(void *d, const Value64 *v)
+{
+    asm volatile("movdir64b (%1),%0" : : "r"(d), "r"(v) : "memory");
+}
+
+#endif /* HOST_ATOMIC512_LDST_H */
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.