← Back to Pull requests

simd/adler32: Add SIMD Adler-32 with AVX2 and NEON kernels #28

Closed
unknown closed this pull request without merging on Dec 02, 2026 23:29 UTC
View on GitHub
unknown unknown commented on Dec 02, 2026 14:38 UTC
Author

Computing zlib checksums with hash/adler32 takes a measurable share of the time spent reading and writing packfiles and loose objects. This adds a simd module whose adler32 package has the same API as hash/adler32 and returns identical results, using vectorised kernels. Like hash/adler32, the hash returned by New also marshals, restores and clones its state, in the same format, so state saved by either package restores in the other.

The kernels:

  • amd64: an AVX2 kernel, chosen at run time when the CPU supports it.

  • arm64: a NEON kernel. AdvSIMD is mandatory on arm64, so no feature check is needed.

  • Everything else, including amd64 without AVX2 and purego builds, uses a portable Go implementation.
  • A zlib implementation that uses it follows in a stacked PR.

    Benchmarks

    Against hash/adler32, measured in CI and locally:

    | Platform | 64 B | 4 KiB and larger |
    | --- | --- | --- |
    | amd64, AVX2 (EPYC, Xeon 6975P, Xeon 8370C) | 2.1–2.6x faster | 11–16x faster |
    | arm64, Neoverse | 12.8 ns vs 24.5 ns | ~24 GiB/s vs 2.7 GiB/s |
    | arm64, Apple M2 | 13.5 ns vs 20.5 ns | 45–48 GiB/s |

    Testing

  • The kernels are tested against a scalar reference implementation at every length and alignment around block and chunk boundaries, including inputs that drive the accumulators to their maximum.

  • With the simd_asmtest build tag, which make test sets, the NEON kernel is also called through a harness that fills every general-purpose and vector register with garbage first.

  • Fuzz targets compare the results with hash/adler32 across split writes and arbitrary starting states. Long-running fuzzing will be added to OSS-Fuzz.

  • Golden vectors come from the RFC 1321 test strings.

  • Hash state saved by this package restores in hash/adler32, and the other way round.
  • CI and Makefile

    test.yml now also runs on ubuntu-24.04-arm and macos-latest, so the NEON kernel runs on Neoverse and Apple silicon. It gains two jobs:

  • benchmark runs on pull requests and manual dispatch and compares results against the base branch with benchstat. The results go to the step summary.

  • fuzz runs every fuzz target for 30 seconds, with the corpus cached between runs.
  • New make targets: bench, bench-compare (runs BASE and the working tree in turns, then compares them with benchstat) and fuzz. Tests and lint now build with the simd_asmtest tag.

    Licensing

    The portable implementation is derived from Go's hash/adler32 and carries Go's BSD licence notice. The SIMD kernels are new code. Their structure follows Chromium zlib's adler32_simd.c, which the assembly comments credit.

    Generated with Claude Code

    Diff: 334 lines (+250 / -84) across 4 files Reviewer: pjbgf Review duration: 530m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 334 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.348
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #28"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.7% · Safe to merge
    16.7%
    Repository