Skip to content

perf: fastpath for Poseidon2 arm64 accelerator IV≠0 - #877

Open
Tabaie wants to merge 1 commit into
masterfrom
perf/amd64-poseidon2-nonzero-iv
Open

perf: fastpath for Poseidon2 arm64 accelerator IV≠0#877
Tabaie wants to merge 1 commit into
masterfrom
perf/amd64-poseidon2-nonzero-iv

Conversation

@Tabaie

@Tabaie Tabaie commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Unlocks optimizations where constant-length hashes may omit the initial incorporation of an initialization vector without compromising collision resistance.

Case                         Median time
------------------------------------------
Zero-IV baseline (HEAD)      174.8 µs
Zero-IV current              172.2 µs
Non-zero-IV accelerated      175.9 µs
Non-zero-IV generic          1.49 ms

Non-zero-IV speedup: ~8.5×

Note

Medium Risk
Changes Poseidon2 compression output for non-nil state on arm64 if the new state load layout or register fix (nbSteps vs state pointer) is wrong; correctness should be validated against the generic path.

Overview
Enables the ARM64 NEON column-compression kernel when Compressx16ColumnsWithState supplies a non-zero initial state, instead of always falling back to pure Go on arm64 whenever state != nil.

The Go dispatcher now passes an optional state pointer into permutation16x16xN_columns_arm64 (same pattern as the existing AVX-512 columns kernel). The assembly loads per-batch initial capacity coordinates from column-major state[pos*16+lane] when the pointer is non-nil, and still zero-initializes when it is nil (zero-IV / Compressx16Columns behavior).

Stub signatures, codegen templates, and the ARM64 generator were updated so regenerated .s files match; a benchmark compares accelerated vs generic Compressx16ColumnsWithState at colSize=512.

Reviewed by Cursor Bugbot for commit 8a928eb. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
@Tabaie
Tabaie requested review from gbotrel and a lite review from Copilot August 25, 2026 22:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables the ARM64 NEON Poseidon2 “columns” accelerator to handle Compressx16ColumnsWithState with a non-nil initial state (IV ≠ 0), avoiding a fallback to the pure-Go implementation and significantly improving performance for non-zero-IV workloads.

Changes:

  • Extend the ARM64 columns-kernel ABI to accept an optional state *fr.Element pointer and plumb it through the Go dispatcher and templates.
  • Update the ARM64 assembly generator and regenerated .s output to conditionally load the initial capacity state when provided (or zero-initialize when nil).
  • Add a benchmark to compare accelerated vs generic Compressx16ColumnsWithState at colSize=512.

Reviewed changes

Copilot reviewed 7 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/generator/field/template/poseidon2/poseidon2.purego.go.tmpl Updates pure-Go stub signature for the ARM64 columns kernel to include state.
internal/generator/field/template/poseidon2/poseidon2.go.tmpl Removes the arm64+state fast-path disable and passes an optional state pointer into the ARM64 kernel.
internal/generator/field/template/poseidon2/poseidon2.arm64.go.tmpl Updates ARM64 assembly declaration signature to include state.
internal/generator/field/template/poseidon2/poseidon2.amd64.go.tmpl Updates amd64-side stub signature for the ARM64 columns kernel to include state.
internal/generator/field/asm/arm64/element_vec_F31_poseidon2.go Updates ARM64 codegen to accept/load an optional state pointer and adjust arg sizing.
field/koalabear/poseidon2/poseidon2.go Enables ARM64 accelerated path for non-nil state by passing statePtr into the ARM64 kernel.
field/koalabear/poseidon2/poseidon2_purego.go Updates pure-Go stub signature for permutation16x16xN_columns_arm64 to include state.
field/koalabear/poseidon2/poseidon2_bench_test.go Adds a benchmark for accelerated vs generic Compressx16ColumnsWithState at colSize=512.
field/koalabear/poseidon2/poseidon2_arm64.s Regenerated ARM64 assembly: new arg frame size and conditional state load logic.
field/koalabear/poseidon2/poseidon2_arm64.go Updates ARM64 function declaration to include state.
field/koalabear/poseidon2/poseidon2_amd64.go Updates amd64 stub signature for the ARM64 columns kernel to include state.
Files not reviewed (4)
  • field/koalabear/poseidon2/poseidon2.go: Generated file
  • field/koalabear/poseidon2/poseidon2_amd64.go: Generated file
  • field/koalabear/poseidon2/poseidon2_arm64.go: Generated file
  • field/koalabear/poseidon2/poseidon2_purego.go: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +24 to +27
}
} else {
h.disableAVX512()
}
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