8000 Optimize by prefetching on aarch64 by caoyzh · Pull Request #2040 · facebook/zstd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Optimize by prefetching on aarch64 #2040

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

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
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

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/common/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
# define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0)
# define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1)
# elif defined(__aarch64__)
# define PREFETCH_L1(ptr) __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr)))
# define PREFETCH_L2(ptr) __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr)))
# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
# define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
# define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
Expand Down
3 changes: 3 additions & 0 deletions lib/compress/zstd_double_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ size_t ZSTD_compressBlock_doubleFast_generic(
} }

ip += ((ip-anchor) >> kSearchStrength) + 1;
#if defined(__aarch64__)
PREFETCH_L1(ip+256);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For X86 too?

Copy link
Contributor Author
@caoyzh caoyzh Mar 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For X86 too?

There is gains on X86 too. But It may has negative effects on decompression.

x86				compression		decompression
clang9.0			1.13%			1.54%
gcc9.2.0			3.26%			-1.55%

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry about the decompression speed for compression-only changes (unless you are changing how the data gets compressed and don't have identical compressed output). That is just noise, and we shouldn't take it into account.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found on x86 it is better to put this prefetch before line 142 (hash table update). Does that work on aarch64 too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found on x86 it is better to put this prefetch before line 142 (hash table update). Does that work on aarch64 too?

Putting this prefetch before line 142 is worse in arrch64/clang9.0.0,is similar in arrch64/gcc9.2.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terrelln Do I need to remove the aarch64 switch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's land this patch with the #if defined(__aarch64__) then put up a second patch that just deletes them. I don't want to block clear aarch64 improvements with x86 benchmarking.

continue;

_search_next_long:
Expand Down
5 changes: 5 additions & 0 deletions lib/compress/zstd_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ ZSTD_compressBlock_fast_generic(
const BYTE* match0 = base + matchIndex0;
const BYTE* match1 = base + matchIndex1;
U32 offcode;

#if defined(__aarch64__)
PREFETCH_L1(ip0+256);
#endif

hashTable[h0] = current0; /* update hash table */
hashTable[h1] = current1; /* update hash table */

Expand Down
0