diff --git a/CMakeLists.txt b/CMakeLists.txt index f4f8e67..c313118 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,16 +113,6 @@ if(NOT MSVC) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") target_link_libraries(snmalloc_lib INTERFACE atomic) endif() - if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - # XXX elseif ARM? - endif() endif() if (WIN32) @@ -138,17 +128,11 @@ if (WIN32) endif() endif() -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") - target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) - endif() -endif () +# detect support for cmpxchg16b; werror is needed to make sure mcx16 must be used by targets +check_cxx_compiler_flag("-Werror -Wextra -Wall -mcx16" SNMALLOC_COMPILER_SUPPORT_MCX16) +if(SNMALLOC_COMPILER_SUPPORT_MCX16) + target_compile_options(snmalloc_lib INTERFACE $<$:-mcx16>) +endif() if(USE_SNMALLOC_STATS) target_compile_definitions(snmalloc_lib INTERFACE -DUSE_SNMALLOC_STATS) diff --git a/src/mem/entropy.h b/src/mem/entropy.h index d9b40ae..cf5f179 100644 --- a/src/mem/entropy.h +++ b/src/mem/entropy.h @@ -4,8 +4,10 @@ #include "../pal/pal.h" #include -#include #include +#ifndef SNMALLOC_PLATFORM_HAS_GETENTROPY +# include +#endif namespace snmalloc { @@ -18,9 +20,13 @@ namespace snmalloc template std::enable_if_t, uint64_t> get_entropy64() { +#ifdef SNMALLOC_PLATFORM_HAS_GETENTROPY + return DefaultPal::get_entropy64(); +#else std::random_device rd; uint64_t a = rd(); return (a << 32) ^ rd(); +#endif } class LocalEntropy @@ -139,4 +145,4 @@ namespace snmalloc return result; } }; -} // namespace snmalloc \ No newline at end of file +} // namespace snmalloc