Last active
October 31, 2019 17:21
-
-
Save jtsylve/20a5d85c0029a9aa05f04683ef07f5bb to your computer and use it in GitHub Desktop.
hardware_destructive_interference_size definition that handles compilers that don't support std::hardware_destructive_interference_size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constexpr size_t hardware_destructive_interference_size = []() -> size_t { | |
#ifdef __cpp_lib_hardware_interference_size | |
return std::hardware_destructive_interference_size; | |
#endif | |
// The following values were taken from those commonly used in Google | |
// open source projects as defined with their CACHELINE_SIZE macro | |
#if defined(__i386__) || defined(__x86_64__) | |
return 64; | |
#endif | |
#ifdef __powerpc64__ | |
return 128; | |
#endif | |
// ARM cache line sizes vary depending on implementation, but these are | |
// reasonable defaults | |
#ifdef __ARM_ARCH_5T__ | |
return 32; | |
#endif | |
#ifdef __ARM_ARCH_7A__ | |
return 64; | |
#endif | |
// Fallback to a reasonable default for undefined architectures | |
return 64; | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment