Skip to content

refactor: use more defines in assembly fine to make files less verbose#789

Merged
gbotrel merged 2 commits intomasterfrom
refactor/lessarm
Jan 7, 2026
Merged

refactor: use more defines in assembly fine to make files less verbose#789
gbotrel merged 2 commits intomasterfrom
refactor/lessarm

Conversation

@gbotrel
Copy link
Copy Markdown
Collaborator

@gbotrel gbotrel commented Jan 7, 2026

No algorithmic changes, just refactor code generation to produce more defines and not output thousands of repetitive assembly.


Note

Refactors assembly to reduce repetition without changing algorithms or behavior.

  • Introduces FROMMONT_STEP macro to implement the repeated Montgomery fromMont inner loop in field/asm/element_4w/element_4w_amd64.s, element_5w, element_6w, element_10w, and element_12w
  • Replaces thousands of inlined instructions with macro invocations (multiple FROMMONT_STEP() calls) in each backend
  • No changes to mul/reduce logic; only structural DRYing of fromMont paths
  • Updates generated hash comments in ecc/*/*/element_amd64.s to trigger recompilation; includes remain the same

Written by Cursor Bugbot for commit d6b3b4c. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings January 7, 2026 00:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 refactors the code generation for assembly files to use macros/defines, significantly reducing verbosity in generated assembly code. The change converts repetitive Montgomery reduction loops into reusable macro definitions without altering any underlying algorithms.

Key Changes

  • Introduced FROMMONT_STEP() macros in amd64 assembly generation to replace hundreds of lines of repetitive Montgomery reduction code
  • Refactored ARM64 Poseidon2 code generator to use f.Define() for modular arithmetic operations (ADD_MOD, SUB_MOD, DOUBLE_MOD, etc.)
  • Updated hash values across all elliptic curve implementations to trigger recompilation

Reviewed changes

Copilot reviewed 25 out of 27 changed files in this pull request and generated no comments.

File Description
internal/generator/field/asm/amd64/element_frommont.go Wraps Montgomery reduction step in a Define macro, called NbWords times instead of inlining
internal/generator/field/asm/arm64/element_vec_F31_poseidon2.go Converts inline functions to Define macros for modular operations, matrix multiplication, improving code generation
field/asm/element_*w/element_*w_amd64.s Generated assembly now uses FROMMONT_STEP() macro repeated N times instead of inlined code blocks
ecc/*/fr/element_amd64.s and ecc/*/fp/element_amd64.s Updated hash values to force Go compiler recompilation after assembly changes

@gbotrel gbotrel merged commit 9c7daa1 into master Jan 7, 2026
20 checks passed
@gbotrel gbotrel deleted the refactor/lessarm branch January 7, 2026 00:27
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