Repository navigation
perf(decoding): four-stream literal loop in assembly - #679
Conversation
The four-stream Huffman burst could not keep its streams in registers: the symbol store writes a high byte register, which pins the table entry to rax-rdx, so the allocator put the output pointers on the stack and reloaded them on every symbol, and three Rust layouts of the loop left its time unchanged. - The burst carries each stream as an input and an output pointer and works out once per batch how many iterations pass both the output and the input budget, upstream's olimit shape, so the loop tests one pointer. - On x86_64 with BMI2 and a 10- or 11-bit table each batch runs in an assembly loop of upstream's shape (huf_decompress_amd64.S): outputs in registers without a REX prefix, streams 1-3's input pointers in memory and stepped in a register, four instructions a symbol. - CpuKernel gains HAS_BMI2 for the tiers that guarantee it. Output is unchanged. Decoding z000033 at level 3 runs 711K fewer instructions a frame, close to libzstd's count; the literal stage's cycles fall by about 3%, below the wall-clock noise of an A/B on Broadwell. Part of #678
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 84e75118c1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
- The assembly loop addresses its slots as eight-byte words, which the x32 ABI (x86_64 with four-byte pointers) does not have: there the slot array is 20 bytes and the loop would read past it and combine two pointers into one. The loop and HAS_BMI2 are now built only for 64-bit pointers; x32 takes the Rust loop. No x32 target is built or run anywhere, so no test can go red for it; the gate is checked by compilation. - A test decodes 4-stream literal sections with 10- and 11-bit tables, the widths the assembly loop takes, on every tier the running CPU supports and holds each to the scalar tier byte for byte. Part of #678
## 🤖 New release * `structured-zstd`: 0.4.2 -> 0.4.3 <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [0.4.3](v0.4.2...v0.4.3) - 2026-11-21 ### Performance - *(encoding)* fewer memcpy calls on small dictionary frames ([#691](#691)) - *(encoding)* cheaper dictionary frames at negative levels ([#687](#687)) - *(encoding)* optimal-parser workspace in upstream's shape ([#686](#686)) - *(decoding)* sequence loop common path in assembly on x86_64 ([#683](#683)) - *(decoding)* set sequence table counters in one pass ([#682](#682)) - *(decoding)* four-stream literals in a machine word, asm loop on 32-bit x86 ([#681](#681)) - *(decoding)* four-stream literal loop in assembly ([#679](#679)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). Co-authored-by: sw-release-bot[bot] <255865126+sw-release-bot[bot]@users.noreply.github.com>
Summary
decompress / decodecorpus-z000033cells.Changes
run_4stream_burst_loopcarries each stream as an input and an output pointer, and computes once per batch how many iterations pass both the output and the input budget (upstream'solimit), so the loop body tests one pointer. The batch admits exactly the iterations the per-iteration gates did.burst_batch_asm: five symbols per stream an iteration, four instructions a symbol. The symbol store writes a high byte register, so the output pointers sit in registers without a REX prefix; streams 1-3 keep their input pointers in memory, read into a register before each reload.CpuKernel::HAS_BMI2(x86_64 with 64-bit pointers) marks the tiers that guarantee BMI2.Testing
Tests, clippy and formatting pass on x86_64 (AVX2 host) and aarch64; output is unchanged. A test decodes 10- and 11-bit literal sections on every tier the running CPU supports against the scalar tier.
Part of #678
Summary by CodeRabbit