Skip to content

Instantly share code, notes, and snippets.

@jtsylve
Last active October 31, 2019 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtsylve/20a5d85c0029a9aa05f04683ef07f5bb to your computer and use it in GitHub Desktop.
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
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