From 05654655afedca507c22c5c616b44ab05143c69d Mon Sep 17 00:00:00 2001 From: Yoqie <44141075+yoqie@users.noreply.github.com> Date: Sun, 4 Jul 2021 23:54:46 +0300 Subject: [PATCH] prefetch instructions in FindMatchLength --- snappy-internal.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/snappy-internal.h b/snappy-internal.h index 720ccd8..1b8e4dd 100644 --- a/snappy-internal.h +++ b/snappy-internal.h @@ -103,7 +103,21 @@ static inline std::pair FindMatchLength(const char* s1, uint64_t* data) { assert(s2_limit >= s2); size_t matched = 0; - + + #if defined(__has_builtin) + #if __has_builtin(__builtin_prefetch) + __builtin_prefetch(s1); + __builtin_prefetch(s2); + #endif + #elif defined(__SSE__) || (defined(_M_IX86_FP) && (_M_IX86_FP >= 1)) + #include + _mm_prefetch(s1, _MM_HINT_T1); + _mm_prefetch(s2, _MM_HINT_T1); + #elif defined(_M_ARM64) || defined(_M_ARM) + __prefetch(s1); + __prefetch(s2); + #endif + // This block isn't necessary for correctness; we could just start looping // immediately. As an optimization though, it is useful. It creates some not // uncommon code paths that determine, without extra effort, whether the match