diff --git a/CMakeLists.txt b/CMakeLists.txt index e07a06d..d7dc850 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,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..d323bfd 100644 --- a/src/aal/aal.h +++ b/src/aal/aal.h @@ -9,6 +9,10 @@ # define PLATFORM_IS_X86 #endif +#if defined(__arm__) || defined(__aarch64__) +# define PLATFORM_IS_ARM +#endif + namespace snmalloc { /** @@ -70,8 +74,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..52bb0d0 --- /dev/null +++ b/src/aal/aal_arm.h @@ -0,0 +1,53 @@ +#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; + /** + * 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"); + } + + /** + * Issue a prefetch hint at the specified address. + */ + static inline void prefetch(void* ptr) + { + __builtin_prefetch(ptr, 0, 1); + } + + /** + * Return a cycle counter value. + * on ARM cpu counters are accessible only in privileged mode + */ + static inline uint64_t tick() + { + struct timespec n = {0, 0ul}; + clock_gettime(CLOCK_MONOTONIC, &n); + + return static_cast((n.tv_sec) * (1000000000ul * n.tv_nsec)); + } + }; + + using AAL_Arch = AAL_arm; +} // namespace snmalloc diff --git a/src/ds/bits.h b/src/ds/bits.h index 9dc05b0..6f3621e 100644 --- a/src/ds/bits.h +++ b/src/ds/bits.h @@ -1,6 +1,7 @@ #pragma once #include +#include // #define USE_LZCNT diff --git a/src/pal/pal_posix.h b/src/pal/pal_posix.h index 57d76ac..4344ad4 100644 --- a/src/pal/pal_posix.h +++ b/src/pal/pal_posix.h @@ -4,6 +4,7 @@ #include "../mem/allocconfig.h" #include +#include #include extern "C" int puts(const char* str);