diff --git a/CMakeLists.txt b/CMakeLists.txt index 365b8546d..a77b6b42a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -386,6 +386,11 @@ if(NOT SNMALLOC_HEADER_ONLY_LIBRARY) target_compile_definitions(${name} PRIVATE "SNMALLOC_EXPORT=__attribute__((visibility(\"default\")))") target_compile_options(${name} PRIVATE -fomit-frame-pointer -ffunction-sections) + + check_cxx_compiler_flag("-Werror -Wextra -Wall -mprfchw" SUPPORT_PREFETCH_WRITE) + if (SUPPORT_PREFETCH_WRITE) + target_compile_options(${name} PRIVATE -mprfchw) + endif() # Static TLS model is unsupported on Haiku. if (NOT CMAKE_SYSTEM_NAME STREQUAL "Haiku") target_compile_options(${name} PRIVATE -ftls-model=initial-exec) diff --git a/src/snmalloc/aal/aal.h b/src/snmalloc/aal/aal.h index 49b92da68..dcdc55d98 100644 --- a/src/snmalloc/aal/aal.h +++ b/src/snmalloc/aal/aal.h @@ -147,7 +147,7 @@ namespace snmalloc static inline void prefetch(void* ptr) noexcept { #if __has_builtin(__builtin_prefetch) && !defined(SNMALLOC_NO_AAL_BUILTINS) - __builtin_prefetch(ptr); + __builtin_prefetch(ptr, 1, 3); #else Arch::prefetch(ptr); #endif diff --git a/src/snmalloc/aal/aal_arm.h b/src/snmalloc/aal/aal_arm.h index b6bae779e..8b5a07e53 100644 --- a/src/snmalloc/aal/aal_arm.h +++ b/src/snmalloc/aal/aal_arm.h @@ -54,7 +54,7 @@ namespace snmalloc #elif __has_builtin(__builtin_prefetch) && !defined(SNMALLOC_NO_AAL_BUILTINS) __builtin_prefetch(ptr); #elif defined(SNMALLOC_VA_BITS_64) - __asm__ volatile("prfm pldl1keep, [%0]" : "=r"(ptr)); + __asm__ volatile("prfm pstl1keep, [%0]" : "=r"(ptr)); #else __asm__ volatile("pld\t[%0]" : "=r"(ptr)); #endif diff --git a/src/snmalloc/aal/aal_x86.h b/src/snmalloc/aal/aal_x86.h index cc20e777a..150de2645 100644 --- a/src/snmalloc/aal/aal_x86.h +++ b/src/snmalloc/aal/aal_x86.h @@ -78,7 +78,11 @@ namespace snmalloc */ static inline void prefetch(void* ptr) { - _mm_prefetch(reinterpret_cast(ptr), _MM_HINT_T0); +#if defined(_MSC_VER) + _m_prefetchw(ptr); +#else + _mm_prefetch(reinterpret_cast(ptr), _MM_HINT_ET0); +#endif } /**