diff --git a/CMakeLists.txt b/CMakeLists.txt index e07a06d..6e7438f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,7 +94,15 @@ if (WIN32) endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - target_compile_options(snmalloc_lib INTERFACE -mcx16) + 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 () # Have to set this globally, as can't be set on an interface target. @@ -136,7 +144,8 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY) add_compile_options(-march=native) elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") add_compile_options(-march=native) - # XXX elseif ARM? + elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") + add_compile_options(-march=native) endif() endif() diff --git a/src/aal/aal.h b/src/aal/aal.h index e963250..4f5355f 100644 --- a/src/aal/aal.h +++ b/src/aal/aal.h @@ -1,6 +1,7 @@ #pragma once #include "../ds/defines.h" +#include #include #if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || \ @@ -9,6 +10,10 @@ # define PLATFORM_IS_X86 #endif +#if defined(__arm__) || defined(__aarch64__) +# define PLATFORM_IS_ARM +#endif + namespace snmalloc { /** @@ -22,6 +27,10 @@ namespace snmalloc * and so may use bit operations on pointer values. */ IntegerPointers = (1 << 0), + /** + * This architecture cannot access cpu cycles counters. + */ + NoCpuCycleCounters = (1 << 1), }; /** @@ -59,6 +68,15 @@ namespace snmalloc */ static inline uint64_t tick() { + if constexpr ( + (Arch::aal_features & NoCpuCycleCounters) == NoCpuCycleCounters) + { + auto tick = std::chrono::high_resolution_clock::now(); + return static_cast( + std::chrono::duration_cast( + tick.time_since_epoch()) + .count()); + } #if __has_builtin(__builtin_readcyclecounter) && \ !defined(SNMALLOC_NO_AAL_BUILTINS) return __builtin_readcyclecounter(); @@ -70,8 +88,10 @@ namespace snmalloc } // namespace snmalloc -#ifdef PLATFORM_IS_X86 +#if defined(PLATFORM_IS_X86) # include "aal_x86.h" +#elif defined(PLATFORM_IS_ARM) +# include "aal_arm.h" #endif namespace snmalloc diff --git a/src/aal/aal_arm.h b/src/aal/aal_arm.h new file mode 100644 index 0000000..9dc722b --- /dev/null +++ b/src/aal/aal_arm.h @@ -0,0 +1,34 @@ +#pragma once + +#if defined(__arch64__) +# define SNMALLOC_VA_BITS_64 +#else +# define SNMALLOC_VA_BITS_32 +#endif + +#include +namespace snmalloc +{ + /** + * ARM-specific architecture abstraction layer. + */ + class AAL_arm + { + public: + /** + * Bitmap of AalFeature flags + */ + static constexpr uint64_t aal_features = + IntegerPointers | NoCpuCycleCounters; + /** + * On pipelined processors, notify the core that we are in a spin loop and + * that speculative execution past this point may not be a performance gain. + */ + static inline void pause() + { + __asm__ volatile("yield"); + } + }; + + using AAL_Arch = AAL_arm; +} // namespace snmalloc diff --git a/src/ds/bits.h b/src/ds/bits.h index 9dc05b0..12c9bdc 100644 --- a/src/ds/bits.h +++ b/src/ds/bits.h @@ -1,5 +1,6 @@ #pragma once +#include #include // #define USE_LZCNT diff --git a/src/pal/pal_posix.h b/src/pal/pal_posix.h index 57d76ac..4c3a842 100644 --- a/src/pal/pal_posix.h +++ b/src/pal/pal_posix.h @@ -3,6 +3,7 @@ #include "../ds/address.h" #include "../mem/allocconfig.h" +#include #include #include