summaryrefslogtreecommitdiff
path: root/include/mimalloc-internal.h
diff options
context:
space:
mode:
authorDaan Leijen <daan@microsoft.com>2021-01-29 16:09:09 -0800
committerDaan Leijen <daan@microsoft.com>2021-01-29 16:09:09 -0800
commit0a06884732b3be074e3e2e18b096c20142ae106c (patch)
tree2b6642ef7e2d8b6e1b55a984a28ad2fcd73fed20 /include/mimalloc-internal.h
parent9b966c349236990a43318154a6c1e043dac91d05 (diff)
ensure memcpy with rep stosb is only used on windows
Diffstat (limited to 'include/mimalloc-internal.h')
-rw-r--r--include/mimalloc-internal.h22
1 files changed, 9 insertions, 13 deletions
diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h
index b6bf6f1..da123bf 100644
--- a/include/mimalloc-internal.h
+++ b/include/mimalloc-internal.h
@@ -172,23 +172,19 @@ bool _mi_page_is_valid(mi_page_t* page);
#define EOVERFLOW (75)
#endif
-// ------------------------------------------------------
-// Fast `memcpy()` on x86(_64) platforms unavailable
-// on Windows, use REP MOVSB if necessary
-// ------------------------------------------------------
-#if defined(_M_IX86) || defined(_M_X64)
+// -----------------------------------------------------------------------------------
+// On windows x86/x64 with msvc/clang-cl, use `rep movsb` for `memcpy` (issue #201)
+// -----------------------------------------------------------------------------------
+
+#if defined(_WIN32) && (defined(_M_IX86) || defined(_M_X64))
#include <intrin.h>
-#define _mi_memcpy _mi_memcpy_rep_movsb
-static inline void _mi_memcpy_rep_movsb (void *d, const void *s, size_t n) {
- unsigned char* Destination = (unsigned char*) d;
- unsigned const char* Source = (unsigned const char*) s;
- size_t Count = n;
- __movsb(Destination, Source, Count);
- return;
+static inline void _mi_memcpy_rep_movsb(void* d, const void* s, size_t n) {
+ __movsb((unsigned char*)d, (const unsigned char*)s, n);
}
+#define _mi_memcpy(d,s,n) _mi_memcpy_rep_movsb(d,s,n)
#else
-#define _mi_memcpy memcpy
+#define _mi_memcpy(d,s,n) memcpy(d,s,n)
#endif