Skip to content

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

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

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

Conversation

@ptweezy

@ptweezy ptweezy commented Oct 21, 2026 •

Copy link
Copy Markdown

This PR makes the AVX2 inflate decoder (decode_huffman_code_block_stateless_04) copy matches 32 bytes at a time with ymm registers instead of 16 with xmm. A match of up to 32 bytes whose distance is at least its length takes one store; a match whose distance is less than both 32 and its length still goes through small_byte_copy. The main-loop output slop grows from 274 to 290 bytes, exactly enough for the longest stores.

This applies to every x86-64 CPU with AVX2; _01 assembles to the same code as on master.

Output

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

Conflicts

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

Results

Inflate on GitHub runners, in-process A/B, two runs per runner. Each cell is master's best-of-11 MB/s and the median over runs of this PR's change in best-of-11 throughput (harness, runs 1, 2, 3). 4 KB and 1 KB isa-l L1 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, 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, cause no faults; with a slop one byte smaller, _04 faults.
  • 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>
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