Repository navigation
perf(decoding): four-stream literals in a machine word, asm loop on 32-bit x86 - #681
Conversation
On a 32-bit target the four-stream Huffman loop carried each stream in a u64: every symbol shifted a register pair and every reload read eight bytes into two registers, on a machine with seven of them. - Each stream's state, pending bits and sentinel now live in a word of the pointer's width, as upstream zstd's four-stream loops keep a stream in a size_t. A 32-bit word takes two symbols per stream between reloads at table widths 8 to 11, as upstream's 32-bit loop does, and reloads four bytes. - The word's window ends where the reader's eight-byte window ends, so the bits consumed carry over unchanged and the input budget and the writeback for the drain are the same on both widths. - 64-bit targets keep a u64 and the same loop. Part of #678
The drain keeps the decoder state in a u64; a 32-bit burst word is widened when the burst hands it back. Part of #678
With a 32-bit word per stream the Rust loop still did not fit seven registers: the compiler kept some streams' words on the stack, so every symbol of those streams loaded the word, shifted it and stored it back, a store-to-load wait on the chain each symbol depends on. The reload's bit count also guarded the zero case with a conditional move although the sentinel keeps the word nonzero. - On 32-bit x86 with a 10- or 11-bit table each batch runs in an assembly loop: the four words in ebx, edx, esi and edi, the table in ebp, the entry in ecx; input and output pointers and the bound live on the stack and are read off the chains. Two symbols per stream an iteration, as upstream zstd's 32-bit loop decodes. - The Rust loop counts the reload's bits on a nonzero word, a bare bsf on x86. Output is unchanged. 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:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The short-stream bail-out and the two- and three-symbol burst arms can only run with a 32-bit word: a 64-bit word gives five or more symbols per burst and needs no window skip. Gate them on the pointer width so the 64-bit loop keeps exactly its earlier arms instead of carrying unreachable ones. Part of #678
|
@coderabbitai review |
Action performed
|
## 🤖 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
Changes
u64on 64-bit targets,u32on 32-bit, with the safe burst length and the input window derived from its width. Two or three symbols per stream between reloads on 32-bit.bsf, no zero guard), since the sentinel bit keeps it nonzero.Testing
--profile bench), against the Rust loop on a 32-bit word: L1 -12%, L3 -6%, L14 -7%, L16 -4% in two of three rounds. Against libzstd on the same host: 1.07x faster at L1, 1.02x at L3, 1.03x at L14, parity at L16.Part of #678
Summary by CodeRabbit