[PATCH 4/4] libs/port: Use msvc intrinsics for interlocked functions.

Stefan Dösinger stefan at codeweavers.com
Sun Nov 17 06:43:15 CST 2019


Signed-off-by: Stefan Dösinger <stefan at codeweavers.com>

---

Visual Studio does not support inline assembly or naked functions in
x86_64. We would have to move these functions to a separate asm file to
hand-write them.

These functions exist in VS 2012, but not in VS 2003. I don't have the
intermediate versions installed. We could replace the __naked 32 bit
functions with these new ones if we don't care about breaking older VS
versions. The *Pointer intrinsics don't exist on 32 bit, so some #ifdefs
would still be needed.
---
 libs/port/interlocked.c | 42 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/libs/port/interlocked.c b/libs/port/interlocked.c
index 59b852f7e9f..040ab756eba 100644
--- a/libs/port/interlocked.c
+++ b/libs/port/interlocked.c
@@ -138,6 +138,47 @@ __ASM_GLOBAL_FUNC(interlocked_xchg_add,
 
 #elif defined(__x86_64__)
 
+#if defined(_MSC_VER)
+
+#include <intrin.h>
+
+int interlocked_cmpxchg(int *dest, int xchg, int compare)
+{
+    return _InterlockedCompareExchange(dest, xchg, compare);
+}
+
+void *interlocked_cmpxchg_ptr(void **dest, void *xchg, void *compare)
+{
+    return _InterlockedCompareExchangePointer(dest, xchg, compare);
+}
+
+__int64 interlocked_cmpxchg64(__int64 *dest, __int64 xchg, __int64 compare)
+{
+    return _InterlockedCompareExchange64(dest, xchg, compare);
+}
+
+int interlocked_xchg(int *dest, int val)
+{
+    return _InterlockedExchange(dest, val);
+}
+
+void *interlocked_xchg_ptr(void **dest, void *val)
+{
+    return _InterlockedExchangePointer(dest, val);
+}
+
+int interlocked_xchg_add(int *dest, int incr)
+{
+    return _InterlockedExchangeAdd(dest, incr);
+}
+
+int interlocked_cmpxchg128(__int64 *dest, __int64 xchg_high, __int64 xchg_low, __int64 *compare)
+{
+    return _InterlockedCompareExchange128(dest, xchg_high, xchg_low, compare);
+}
+
+#else
+
 __ASM_GLOBAL_FUNC(interlocked_cmpxchg,
                   "mov %edx, %eax\n\t"
                   "lock cmpxchgl %esi,(%rdi)\n\t"
@@ -179,6 +220,7 @@ __ASM_GLOBAL_FUNC(interlocked_cmpxchg128,
                   __ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
                   __ASM_CFI(".cfi_same_value %rbx\n\t")
                   "ret")
+#endif
 
 #elif defined(__powerpc__)
 
-- 
2.23.0




More information about the wine-devel mailing list