diff --git a/CMakeLists.txt b/CMakeLists.txt index c3062e2..7711693 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,6 +153,12 @@ int main() { return __builtin_ctzll(0); }" HAVE_BUILTIN_CTZ) +check_cxx_source_compiles(" +int main() { + __builtin_prefetch(0, 0, 3); + return 0; +}" HAVE_BUILTIN_PREFETCH) + check_cxx_source_compiles(" __attribute__((always_inline)) int zero() { return 0; } diff --git a/cmake/config.h.in b/cmake/config.h.in index d1de25c..3510c27 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -10,6 +10,9 @@ /* Define to 1 if the compiler supports __builtin_expect. */ #cmakedefine01 HAVE_BUILTIN_EXPECT +/* Define to 1 if the compiler supports __builtin_prefetch. */ +#cmakedefine01 HAVE_BUILTIN_PREFETCH + /* Define to 1 if you have a definition for mmap() in . */ #cmakedefine01 HAVE_FUNC_MMAP diff --git a/snappy-stubs-internal.h b/snappy-stubs-internal.h index 1548ed7..526c38b 100644 --- a/snappy-stubs-internal.h +++ b/snappy-stubs-internal.h @@ -105,6 +105,12 @@ #define SNAPPY_ATTRIBUTE_ALWAYS_INLINE #endif // HAVE_ATTRIBUTE_ALWAYS_INLINE +#if HAVE_BUILTIN_PREFETCH +#define SNAPPY_PREFETCH(ptr) __builtin_prefetch(ptr, 0, 3) +#else +#define SNAPPY_PREFETCH(ptr) (void)(ptr) +#endif + // Stubbed version of ABSL_FLAG. // // In the open source version, flags can only be changed at compile time.