perf: fastpath for Poseidon2 arm64 accelerator IV≠0 - #877
Open
Tabaie wants to merge 1 commit into
Open
Conversation
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
Contributor
There was a problem hiding this comment.
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.Elementpointer and plumb it through the Go dispatcher and templates. - Update the ARM64 assembly generator and regenerated
.soutput to conditionally load the initial capacity state when provided (or zero-initialize when nil). - Add a benchmark to compare accelerated vs generic
Compressx16ColumnsWithStateatcolSize=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() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unlocks optimizations where constant-length hashes may omit the initial incorporation of an initialization vector without compromising collision resistance.
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
Compressx16ColumnsWithStatesupplies a non-zero initial state, instead of always falling back to pure Go on arm64 wheneverstate != nil.The Go dispatcher now passes an optional
statepointer intopermutation16x16xN_columns_arm64(same pattern as the existing AVX-512 columns kernel). The assembly loads per-batch initial capacity coordinates from column-majorstate[pos*16+lane]when the pointer is non-nil, and still zero-initializes when it is nil (zero-IV /Compressx16Columnsbehavior).Stub signatures, codegen templates, and the ARM64 generator were updated so regenerated
.sfiles match; a benchmark compares accelerated vs genericCompressx16ColumnsWithStateatcolSize=512.Reviewed by Cursor Bugbot for commit 8a928eb. Bugbot is set up for automated code reviews on this repo. Configure here.