Commit ab2e3cc
zstd: Add arm64 decoder asm (#1160)
* zstd: add arm64 asm implementation of fseDecoder.buildDtable
arm64 previously fell through to the pure-Go fse_decoder_generic.go because
the decoder asm is avo-generated and avo has no arm64 backend. This adds a
hand-written scalar arm64 port of buildDtable, mirroring the avo-generated
fse_decoder_amd64.s and the pure-Go reference. The kernel is serial bitfield
work (no SIMD), so it needs no NEON/SVE and builds on the stock go1.x
assembler.
Correctness is covered by a differential test against an in-tree copy of the
generic algorithm over the three RFC predefined distributions, plus the full
existing decode suite (which runs on macos-latest/arm64 in CI).
darwin/arm64 (M4, go1.26), asm vs -tags noasm; the bench's table reset is
identical on both sides so the delta is the buildDtable work:
litLength ~166 vs ~201 ns/op (+18%)
offset ~118 vs ~141 ns/op (+16%)
matchLength ~175 vs ~210 ns/op (+17%)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* zstd: add avo-generated arm64 asm sequence decoder
Generates the full non-BMI2 zstd sequence decoder for arm64 by lowering the
existing amd64 avo program (_generate/gen.go) through a new arm64 backend in
avo (a post-pass.Compile lowering printer; see mmcloughlin/avo#486). No asm is
hand-written: `go generate` now emits both seqdec_amd64.s and seqdec_arm64.s
from the same IR, so they cannot drift, and CI's generate+git-diff job enforces
it.
- seqdec_arm64.s: generated (6 non-BMI2 functions: decode/_56, executeSimple/
_safe, decodeSync/_safe).
- seqdec_arm64.go: shim mirroring seqdec_amd64.go (context structs, noescape
decls, dispatch) without the BMI2 paths.
- seqdec_generic.go: build tag now excludes arm64.
Scalar only — no NEON/SVE (one VLD1/VST1 pair for a 16-byte MOVUPS copy);
builds on go1.26. Full zstd decode suite passes on arm64. On Apple M4,
BenchmarkDecoder_DecodeAll is ~1.5x faster than the pure-Go fallback on
sequence-heavy input (kppkn: 469 vs 304 MB/s).
Regeneration requires the avo arm64 backend (mmcloughlin/avo#486) via a local
replace directive in _generate/go.mod (not committed).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* zstd: generate arm64 fse decoder via avo + pin avo fork
Switches fse_decoder_arm64.s from the hand-written bootstrap to the
avo-generated lowering, so the entire arm64 zstd decoder (fse table build
+ sequence decoder) is produced from the existing, unmodified amd64 avo
generators via the arm64 lowering printer (mmcloughlin/avo#486). Supersedes
the hand-written fse PR #1159.
Pins the printer through a replace to the honeycombio/avo fork (which keeps
the github.com/mmcloughlin/avo module path, so the replace resolves) until
the printer merges upstream and is released, at which point the replace is
dropped for a normal require.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* zstd: asmfmt-style formatting for generated arm64 asm
Regenerate the arm64 decoder with the updated avo arm64 printer, which now
aligns operands to a common column and emits a blank line before labels —
matching avo's amd64 (goasm) output. asmfmt reports zero non-comment
differences on the arm64 files (the same standalone-comment indentation
residual goasm produces on amd64). Repins the avo fork to the printer commit.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* zstd: address review — dedup shims, -arch generation, asm-vs-nonasm fuzz
Responds to maintainer review on the arm64 decoder PR:
- Deduplicate the asm Go wrappers: shared seqdec_asm.go holds the context
structs, error codes and the decode/decodeSync/executeSimple bodies; each
arch keeps only its //go:noescape decls and a small dispatch helper (amd64
selects the BMI2 / 56-bit / safe variant, arm64 the 56-bit / safe variant).
The fse Go wrapper is identical across arches and collapses into one
fse_decoder_asm.go (per-arch fse_decoder_{amd64,arm64}.go removed).
- Generate both architectures via avo's new -arch flag: one
`go run gen.go -out ../seqdec.s -arch amd64,arm64` writes seqdec_amd64.s and
seqdec_arm64.s from a single compile, so neither file's header references the
other architecture.
- FuzzDecodeAll now cross-checks the assembly decoder against a non-assembly
path (BMI2 disabled on amd64) for byte-identical output; run with -tags=noasm
over the shared corpus to cover assembly-vs-generic on arm64.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* ci: run build matrix and zstd fuzzers on linux arm64
Adds ubuntu-24.04-arm to the build matrix (vet/test/noasm/race across Go
versions on Linux arm64) and gives the fuzz-zstd job an OS matrix so the zstd
decode fuzzers also run on arm64 — exercising the new arm64 decoder assembly
directly in CI, as requested in review.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* zstd: defer BMI2 restore in FuzzDecodeAll asm/non-asm comparison
Use the defer cpuinfo.DisableBMI2()() idiom so BMI2 is re-enabled on every exit
path (panic/return), matching FuzzDecAllNoBMI2. Addresses review feedback.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Klaus Post <klauspost@gmail.com>1 parent bb2723d commit ab2e3cc
18 files changed
Lines changed: 3462 additions & 343 deletions
File tree
- .github/workflows
- zstd
- _generate
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
| |||
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
21 | | - | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
| |||
0 commit comments