From c2e4a12e21ab3f034f719a01132d159aacc079b1 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Wed, 9 Aug 2023 07:15:37 +0100 Subject: [PATCH] Using exclusive mode prefetch (#627) * Using exclusive mode prefetch The prefetching is always used to move the cache line to the current core for writing. This change makes it use exclusive mode prefetch and enables it as a feature flag for x64. * Debug platform for BSDs * CI fixes * More CI * Update ARM prefetch * Update x64 prefetch default --- CMakeLists.txt | 5 +++++ src/snmalloc/aal/aal.h | 2 +- src/snmalloc/aal/aal_arm.h | 2 +- src/snmalloc/aal/aal_x86.h | 6 +++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 365b854..a77b6b4 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 49b92da..dcdc55d 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 b6bae77..8b5a07e 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 cc20e77..150de26 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 } /**