Skip to content

igzip: look up the x86 inflate distance code before the refill - #456

Open
ptweezy wants to merge 1 commit into
intel:masterfrom
ptweezy:igzip-x86-inflate-dist-lookup
Open

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

Conversation

@ptweezy

@ptweezy ptweezy commented Oct 21, 2026 •

Copy link
Copy Markdown

The x86 inflate main loop takes the next lit/len index from read_in before the input refill, but the distance index after it, so the distance lookup waits for the refill. This PR takes the distance index before the refill too.

This is safe: read_in_length can be as low as 9 there, but the last refill loaded all 64 bits of read_in, and at most 48 have been consumed since (15 + 13 for a distance code and its extra bits, 15 + 5 for a lit/len code and its extra bits), so the low 10 bits already hold the right stream bits.

Both x86-64 decoders change: decode_huffman_code_block_stateless_01 (SSE4.2) and _04 (AVX2). Output does not change.

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% or less.

CPU (runners) Silesia, zlib -6 64 KB slices, isa-l L1
Zen 3 EPYC 7763 (4) 850, +6.2% 686, +4.6%
Zen 4 EPYC 9V74 (6) 988, +5.4% 806, +4.0%
Zen 5 EPYC 9V45 (6) 1131, +3.5% 930, +2.5%
Ice Lake Xeon 8370C (1) 819, +2.4% 647, +1.0%
Emerald Rapids Xeon 8573C (5) 829, +3.3% 706, +2.3%
Granite Rapids Xeon 6973P-C (2) 944, +3.3% 769, +1.8%

Testing

  • make check passes with _04, with _01 forced, and natively on Windows (mingw-w64), where callee-saved registers stay intact over 2.2 million win64 calls per decoder.
  • 150,000 valid and corrupted streams, stateless and stateful, give master's state and output with both decoders.
  • In an instrumented build, the early index equals the post-refill one for all of about 97 million length symbols (read_in_length down to 9).

The main loop of decode_huffman_code_block_stateless_01 and _04 takes
the index of the next distance lookup from read_in after the refill,
so the lookup waits for the refill. Take the index before the refill,
as the loop already does for the next lit/len lookup.

read_in_length can be as low as 9 at that point, but the last refill
loaded all 64 bits of read_in and at most 48 of them have been consumed
since: 15 + 13 for a distance code and its extra bits, and 15 + 5 for
a lit/len code and its extra bits. The low 16 bits of read_in already
hold the stream bits that the refill would put there, so the 10-bit
index, and with it the output, does not change.

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 2.4% to 6.2%
faster on the Silesia files compressed by zlib -6, and 1.0% to 4.6%
faster on 64 KB pieces of them compressed at isa-l level 1.

Signed-off-by: Parker Loflin <parker@cronstable.dev>
@ptweezy
ptweezy force-pushed the igzip-x86-inflate-dist-lookup branch from 4b9be0c to be6d806 Compare October 21, 2026 21:27
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