Repository navigation
AArch64: Enhance struct access in Huffman decode 2X - #4413
Conversation
|
It does make sense. I'll measure the claimed benefits on a few platforms and compilers. |
| op[(_stream)][(_symbol)] = (BYTE)(entry >> 8); \ | ||
| } while (0) | ||
|
|
||
| #define HUF_4X1_RELOAD_STREAM(_stream) \ |
There was a problem hiding this comment.
This should rather be called 5x1 i.e. HUF_5X1_RELOAD_STREAM now.
There was a problem hiding this comment.
Renamed it in bd38fc2, I also did it with HUF_4X2_RELOAD_STREAM.
|
I tested across a range of compilers, to mitigate instruction alignment impact with random impact on performance. This gives the following results: In other words : it's wash. I cannot prove that the modifications are "better", even if they improve instruction count (which could be proven via assembly view). I think that makes the second axis more important, which is that the modification is still welcome if it helps clarity. Or possibly, maybe I should start another PR and recreate this PR there, little by little, selectively deciding which parts gets in, and which part gets modified. |
In the multi-stream multi-symbol Huffman decoder GCC generates
suboptimal code - emitting more loads for HUF_DEltX2 struct member
accesses. Forcing it to use 32-bit loads and bit arithmetic to extract
the necessary parts (UBFX) improves the overall decode speed.
Also avoid integer type conversions in the symbol decodes, which
leads to better instruction selection in table lookup accesses.
On AArch64 the decoder no longer runs into register-pressure limits,
so we can simplify the hot path and improve throughput
Decompression uplifts on a Neoverse V2 system, using Zstd-1.5.8
compiled with "-O3 -march=armv8.2-a+sve2":
Clang-20 Clang-* GCC-13 GCC-14 GCC-15
1#silesia.tar: +0.820% +1.365% +2.480% +1.348% +0.987%
2#silesia.tar: +0.426% +0.784% +1.218% +0.665% +0.554%
3#silesia.tar: +0.112% +0.389% +0.508% +0.188% +0.261%
* Requires Clang-21 support from LLVM commit hash
`a53003fe23cb6c871e72d70ff2d3a075a7490da2`
(Clang-21 hasn’t been released as of this writing)
da16a20 to
bd38fc2
Compare
|
Thanks for the review and extensive testing! In bd38fc2 we added a bit more hint for GCC to let it generate simpler addressing instructions without index register widening. Clang's code generation is not affected. Smaller out-of-order CPU can gain a bit more performance from this change because of the limited execution resources, on a Cortex-A720 we can see these overall uplifts:
|
| do { \ | ||
| if ((_decode3) || (_stream) != 3) { \ | ||
| U64 const index = bits[(_stream)] >> 53; \ | ||
| size_t const entry = MEM_readLE32(&dtable[index]); \ |
There was a problem hiding this comment.
Reading again this PR,
it seems this is the only place where I would expect a potential performance difference.
The other changes only affect type casting, which should be harmless, and I generally prefer the new types.
I don't doubt this change is favorable for the platforms tested,
but it may also be non-neutral for other platforms, even possibly detrimental.
So I'll have to check it.
|
I controlled this impact on decompression speed on a I believe it's a good enough outcome to validate this PR, |
In the multi-stream multi-symbol Huffman decoder GCC generates suboptimal code - emitting more loads for
HUF_DEltX2struct member accesses. Forcing it to use 32-bit loads and bit arithmetic to extract the necessary parts (UBFX) improves the overall decode speed.Also avoid integer type conversions in the symbol decodes, which leads to better instruction selection in table lookup accesses.
On AArch64 the decoder no longer runs into register-pressure limits, so we can simplify the hot path and improve throughput.
Decompression uplifts on a Neoverse V2 system, using Zstd-1.5.8 compiled with
-O3 -march=armv8.2-a+sve2:Mostly the fastest compression levels are affected.
This patch can also save some instructions in the hot path on x86 compiled by GCC.