[PATCH] D36071: [builtins] Use Interlocked* intrinsics for atomics on MSVC

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 3 12:05:23 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL309974: [builtins] Use Interlocked* intrinsics for atomics on MSVC (authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D36071?vs=109487&id=109611#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36071

Files:
  compiler-rt/trunk/lib/builtins/emutls.c


Index: compiler-rt/trunk/lib/builtins/emutls.c
===================================================================
--- compiler-rt/trunk/lib/builtins/emutls.c
+++ compiler-rt/trunk/lib/builtins/emutls.c
@@ -102,7 +102,6 @@
 #include <malloc.h>
 #include <stdio.h>
 #include <assert.h>
-#include <immintrin.h>
 
 static LPCRITICAL_SECTION emutls_mutex;
 static DWORD emutls_tls_index = TLS_OUT_OF_INDEXES;
@@ -203,25 +202,24 @@
 /* Provide atomic load/store functions for emutls_get_index if built with MSVC.
  */
 #if !defined(__ATOMIC_RELEASE)
+#include <intrin.h>
 
 enum { __ATOMIC_ACQUIRE = 2, __ATOMIC_RELEASE = 3 };
 
 static __inline uintptr_t __atomic_load_n(void *ptr, unsigned type) {
     assert(type == __ATOMIC_ACQUIRE);
+    // These return the previous value - but since we do an OR with 0,
+    // it's equivalent to a plain load.
 #ifdef _WIN64
-    return (uintptr_t) _load_be_u64(ptr);
+    return InterlockedOr64(ptr, 0);
 #else
-    return (uintptr_t) _load_be_u32(ptr);
+    return InterlockedOr(ptr, 0);
 #endif
 }
 
 static __inline void __atomic_store_n(void *ptr, uintptr_t val, unsigned type) {
     assert(type == __ATOMIC_RELEASE);
-#ifdef _WIN64
-    _store_be_u64(ptr, val);
-#else
-    _store_be_u32(ptr, val);
-#endif
+    InterlockedExchangePointer((void *volatile *)ptr, (void *)val);
 }
 
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36071.109611.patch
Type: text/x-patch
Size: 1333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170803/0971ce55/attachment.bin>


More information about the llvm-commits mailing list