zstd/lib/compress
Arpad Panyik 7e4937bc75 AArch64: Add SVE2 implementation of histogram computation
The existing scalar implementation uses a 4-way pipelined histogram
calculation which is very efficient on out-of-order CPUs. However,
this can be further accelerated using the SVE2 HISTSEG instructions -
which compute a histogram for 16 byte chunks in a vector register.

On a system with 128-bit vectors (VL128) we need 16 HISTSEG executions
to compute the histogram for the whole symbol space (0..255) of 16
bytes input. However we can only accumulate 15 of such 16 byte strips
before possible overflow. So we need to extend and save the 8-bit
histogram accumulators to 16-bit after every 240 byte chunks of input.
To store all in registers we would need 32 128-bit registers. Longer
SVE2 vectors could help here, if such machines become available.

The maximum input block size in Zstd is 128 KiB, so 16-bit accumulators
would not be enough. However an LZ pass will prepend the histogram
calculation, so it is impossible (my assumption) to overflow the 16-bit
accumulators.

The symbol distribution is also not uniform, the lower values are more
common, so we used a 3 pass algorithm to prevent stack spilling. In the
first pass we only compute histograms for 64 symbols (4-way SIMD) while
also computing the maximum symbol value. If we have symbol values
larger than 64 we start the second pass to compute the next 96 elements
of the histogram. The final pass calculates the remaining part of the
histogram (256 symbols in total) if needed. This split of histogram
generation gave the best overall results for performance.

This implementation is the best performing of a number of different
cache blocking schemes tested.

Compression uplifts on a Neoverse V2 system, using Zstd-1.5.8
(e26dde3d) as a baseline, compiled with "-O3 -march=armv8.2-a+sve2":

                 Clang-20    GCC-14
 1#silesia.tar:   +6.173%   +5.987%
 2#silesia.tar:   +5.200%   +5.011%
 3#silesia.tar:   +4.332%   +5.031%
 4#silesia.tar:   +2.789%   +3.064%
 5#silesia.tar:   +2.028%   +1.838%
 6#silesia.tar:   +1.562%   +1.340%
 7#silesia.tar:   +1.160%   +0.959%
2025-06-11 12:14:22 +00:00
..
clevels.h initial commit 2023-01-04 13:01:54 -08:00
fse_compress.c reduce the amount of includes in "cover.h" 2024-03-13 11:29:28 -07:00
hist.c AArch64: Add SVE2 implementation of histogram computation 2025-06-11 12:14:22 +00:00
hist.h AArch64: Add SVE2 implementation of histogram computation 2025-06-11 12:14:22 +00:00
huf_compress.c add an assert 2025-03-22 18:23:31 -07:00
zstd_compress.c Improve speed of ZSTD_compressSequencesAndLiterals() using RVV 2025-06-02 17:21:02 +08:00
zstd_compress_internal.h Merge pull request #4317 from hirohira9119/fix-function-signature 2025-02-27 13:03:03 -08:00
zstd_compress_literals.c codemod: symbolEncodingType_e -> SymbolEncodingType_e 2024-12-20 10:36:56 -08:00
zstd_compress_literals.h fix root cause of #3416 2023-01-12 15:41:08 -08:00
zstd_compress_sequences.c codemod: ZSTD_defaultPolicy_e -> ZSTD_DefaultPolicy_e 2024-12-20 10:36:56 -08:00
zstd_compress_sequences.h codemod: ZSTD_defaultPolicy_e -> ZSTD_DefaultPolicy_e 2024-12-20 10:36:56 -08:00
zstd_compress_superblock.c codemod: repcodes_t -> Repcodes_t 2024-12-20 10:36:57 -08:00
zstd_compress_superblock.h initial commit 2023-01-04 13:01:54 -08:00
zstd_cwksp.h Remove extern C blocks from lib/* internal APIs (except xxhash.h) 2024-12-19 16:00:11 -08:00
zstd_double_fast.c codemod: ZSTD_matchState_t -> ZSTD_MatchState_t 2024-12-20 10:36:57 -08:00
zstd_double_fast.h Merge pull request #4218 from facebook/externC 2025-01-07 10:06:08 -08:00
zstd_fast.c codemod: ZSTD_matchState_t -> ZSTD_MatchState_t 2024-12-20 10:36:57 -08:00
zstd_fast.h Merge pull request #4218 from facebook/externC 2025-01-07 10:06:08 -08:00
zstd_lazy.c Revert "pass dictionary loading method as parameter" 2025-02-05 18:47:26 -08:00
zstd_lazy.h Merge pull request #4218 from facebook/externC 2025-01-07 10:06:08 -08:00
zstd_ldm.c update hrlog comment 2025-02-10 10:48:56 -08:00
zstd_ldm.h Merge pull request #4218 from facebook/externC 2025-01-07 10:06:08 -08:00
zstd_ldm_geartab.h initial commit 2023-01-04 13:01:54 -08:00
zstd_opt.c Revert "pass dictionary loading method as parameter" 2025-02-05 18:47:26 -08:00
zstd_opt.h Merge pull request #4218 from facebook/externC 2025-01-07 10:06:08 -08:00
zstd_preSplit.c added a test 2024-10-28 16:31:15 -07:00
zstd_preSplit.h Remove extern C blocks from lib/* internal APIs (except xxhash.h) 2024-12-19 16:00:11 -08:00
zstdmt_compress.c Revert "pass dictionary loading method as parameter" 2025-02-05 18:47:26 -08:00
zstdmt_compress.h Revert "pass dictionary loading method as parameter" 2025-02-05 18:47:26 -08:00