Skip to content

Add prefetch instructions in FindMatchLength #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions snappy-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,28 @@ char* CompressFragment(const char* input,
// Separate implementation for 64-bit, little-endian cpus.
#if !defined(SNAPPY_IS_BIG_ENDIAN) && \
(defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM))

#if ARCH_ARM
static inline void Prefetch(const void* data) {
__asm__ __volatile__(
"prfm PLDL1STRM, [%[data]] \n\t"
:: [data] "r" (data)
);
}
#endif //ARCH_ARM

static inline std::pair<size_t, bool> FindMatchLength(const char* s1,
const char* s2,
const char* s2_limit,
uint64_t* data) {
assert(s2_limit >= s2);
size_t matched = 0;

#if ARCH_ARM
Prefetch(s1 + 256);
Prefetch(s2 + 256);
#endif //ARCH_ARM

// 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
Expand Down