Skip to content

igzip: copy inflate matches 32 bytes at a time with AVX2 - #469

Open
ptweezy wants to merge 1 commit into
intel:masterfrom
ptweezy:igzip-x86-inflate-copy32-v2
Open

ptweezy wants to merge 1 commit into
intel:masterfrom
ptweezy:igzip-x86-inflate-copy32-v2

Conversation

@ptweezy

@ptweezy ptweezy commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

The AVX2 inflate decoder (decode_huffman_code_block_stateless_04) copies matches 32 bytes at a time with ymm registers instead of 16 with xmm, so a match of up to 32 bytes whose distance is at least its length takes one store. Matches whose distance is less than both 32 and their length still go through small_byte_copy. The main-loop output slop grows from 274 to 290 bytes. _01 does not change.

Decoded output does not change. On main-loop ISAL_INVALID_LOOKBACK and ISAL_INVALID_SYMBOL failures, which master already miscounts (#446), stateless avail_out comes out 290 bytes short instead of 274.

This PR conflicts with #446 in igzip/igzip_decode_block_stateless.asm.

Results

Inflate MB/s on GitHub runners: master's best of 11 rounds, and this PR's median change over two in-process A/B runs per runner (harness; runs 1, 2, 3). 4 KB and 1 KB slices change by 1.2% or less.

CPU (runners) Silesia, zlib -6 64 KB slices, isa-l L1
Zen 3 EPYC 7763 (4) 850, +1.0% 686, +0.7%
Zen 4 EPYC 9V74 (6) 986, +1.6% 806, +1.3%
Zen 5 EPYC 9V45 (6) 1159, +2.7% 936, +1.9%
Ice Lake Xeon 8370C (1) 818, +1.5% 666, +1.2%
Emerald Rapids Xeon 8573C (5) 852, +2.0% 709, +1.8%
Granite Rapids Xeon 6973P-C (2) 958, +1.6% 792, +1.5%

Testing

  • make check passes with _04 and with _01 forced, and natively on Windows (mingw-w64), where 2.2 million win64 calls per decoder leave callee-saved registers and the upper ymm state clean.
  • Worst-case streams inflated into every output size, ending at a guard page, don't fault; _04 faults with a slop one byte smaller.
  • 8,000 valid and corrupted streams give master's results except in the failures above; with igzip: fix x86 inflate counts when the main loop finds an error #446 applied to both, all match.

The main loop of the x86 inflate decoder copies a match 16 bytes at a
time, so a match longer than 16 bytes takes a second store and a loop
branch that is hard to predict. In the AVX2 decoder,
decode_huffman_code_block_stateless_04, copy 32 bytes at a time with
ymm registers, so most matches take one load, one store and no loop
branch. The output slop of the main loop grows by 16 bytes to cover
the longer stores. A match whose distance is less than 32 bytes and
less than its length keeps going through small_byte_copy, which
doubles the distance until it is at least the copy size.

On GitHub-hosted runners with AMD Zen 3, Zen 4 and Zen 5 and Intel Ice
Lake, Emerald Rapids and Granite Rapids CPUs, inflate gets 1.0% to 2.7%
faster on the Silesia files compressed by zlib -6, and 0.7% to 1.9%
faster on 64 KB pieces of them compressed at isa-l level 1.

Signed-off-by: Parker Loflin <parker@cronstable.dev>
@ptweezy
ptweezy marked this pull request as ready for review October 30, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant