Skip to content

zstd: align the sequence decode and execute loops to 64 bytes - #1240

Merged
klauspost merged 2 commits into
klauspost:masterfrom
honeycombio:lizf.zstd-pcalign
Sep 28, 2026
Merged

klauspost merged 2 commits into
klauspost:masterfrom
honeycombio:lizf.zstd-pcalign

Conversation

@lizthegrey

@lizthegrey lizthegrey commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Aligns the zstd sequence decode and execute loops to 64 bytes, the same change #1236 made for huff0. This makes their performance independent of where the linker happens to place the functions; it does not claim a speedup.

(1) Move the asm generator to the current avo arm64 fork (fa13b9f)

zstd/_generate now uses the same honeycombio/avo pin as huff0/_generate. That fork's arm64 lowering passes PCALIGN through, and it fails generation if a label sits directly on a PCALIGN. The regenerated seqdec_amd64.s and seqdec_arm64.s are byte-identical. The newer avo requires newer golang.org/x modules, which require go 1.25.0 in _generate/go.mod.

(2) Align the sequence decode and execute loops to 64 bytes (2c2acf9)

PCALIGN $64 is placed before the main loop of each sequenceDecs_decode* / decodeSync* function and of sequenceDecs_executeSimple*: 10 functions on amd64 and 6 on arm64. It also raises each function's alignment to 64.

Tests: go test ./zstd passes on amd64 (Zen 3); the regenerated assembly matches the generator.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Performance
    • Improved alignment in the compression decoder’s processing paths, which may help decoding run more efficiently across supported processor architectures. Decoding behavior and results remain unchanged.

lizthegrey and others added 2 commits September 28, 2026 11:04
Use the same honeycombio/avo pin as huff0/_generate. The fork's arm64
lowering passes PCALIGN through, and it rejects a label placed directly on
a PCALIGN, which the amd64 assembler mishandles (golang/go#74648,
golang/go#81792). The regenerated assembly is byte-identical. The newer
avo requires newer golang.org/x modules, which require go 1.25.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Place PCALIGN $64 before the decode/decodeSync and executeSimple main
loops, which also raises each function's alignment to 64. Without it the
loop heads land wherever the linker places the function, and the same
code measured about ±2% apart between builds that differed only in what
came before it. The padding runs once per call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 72aa839d-6feb-4610-a77c-aeb66acc2a5b

📥 Commits

Reviewing files that changed from the base of the PR and between 0533a67 and 2c2acf9.

⛔ Files ignored due to path filters (1)
  • zstd/_generate/go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • zstd/_generate/gen.go
  • zstd/_generate/go.mod
  • zstd/seqdec_amd64.s
  • zstd/seqdec_arm64.s

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The generator adds optional 64-byte alignment around prefetch and decode-loop boundaries. AMD64 and arm64 assembly routines add alignment directives at decoder and execution loop boundaries. Generator module settings and indirect dependencies also change.

Changes

Decoder loop alignment

Layer / File(s) Summary
Generator loop alignment
zstd/_generate/gen.go, zstd/_generate/go.mod
The generator can align after prefetch work and before the decode-loop head. Its Go directive, indirect dependencies, and avo replacement revision are updated.
Decoder loop alignment
zstd/seqdec_amd64.s, zstd/seqdec_arm64.s
Sequence decoder and synchronous decoder routines add 64-byte alignment directives at loop boundaries.
Execution loop alignment
zstd/seqdec_amd64.s, zstd/seqdec_arm64.s
Simple AMD64 executor routines and arm64 execution routines add 64-byte alignment directives at main-loop boundaries.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to 2c2ac

No actionable merge risk is established in the reviewed changes; the alignment is consistent between the generator and checked-in assembly. Proceed with normal project checks.

Architecture Summary

Architecture risk: 🔵 Low · up to 2c2ac

The change affects 1 system.

Changed systems: zstd

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — zstd (service) was modified; 4 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in zstd/_generate/gen.go: The generated decode loop now emits 64-byte alignment before its loop-head label.
  • observed — Modified behavior in zstd/_generate/gen.go: The local prefetch helper declaration now accepts an alignAfter boolean in addition to the sequence offset.
  • observed — Modified behavior in zstd/_generate/gen.go: The prefetch helper’s comment and signature now specify optional alignment after its work, at the skip-label location.
  • observed — Modified behavior in zstd/_generate/gen.go: When alignAfter is true, the helper emits 64-byte alignment before the skip label. Prefetch priming enables this for its final entry, aligning that skip target and the main-loop head; the main-loop prefetch passes false. Previously, the helper had no alignment option and neither call site requested alignment.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: aligning the zstd sequence decode and execute loops to 64 bytes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@klauspost
klauspost merged commit 179d9a2 into klauspost:master Sep 28, 2026
29 checks passed
@lizthegrey
lizthegrey deleted the lizf.zstd-pcalign branch September 28, 2026 20:22
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.

2 participants