MontgomeryField + refocused README Performance (close the smalljac gap) - #5
Merged
Conversation
MontgomeryField<P> (radix 2^64) behind the same Field trait as PrimeField: REDC multiply (no division) + binary extended-GCD inversion, const-fn-derived constants. Drop-in for the generic divisor formulas and the batched API. Verified identical to PrimeField (10k random ops @56-bit; exhaustive inversion over F_65521). At a 56-bit prime it makes g2::ramified::not_char2 ~4x faster and competitive with / faster than smalljac (scalar add 673->163, batched 348->40).
…ched Montgomery vs smalljac
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.
Re-targets to main the two changes that were stranded after #3 merged at the f4-fix commit (so
MontgomeryFieldand the README cleanup never reached main). Both belong together: the README cites the Montgomery numbers.1.
MontgomeryField<P>(feat)A second
Fieldbackend behind the same trait asPrimeField: Montgomery REDC multiply (no division) + binary extended-GCD inversion, const-fn-derived constants. Drop-in for the generic divisor formulas and the batched API. Verified identical toPrimeField(10k random add/sub/mul/neg/square/inv/div at a 56-bit prime; exhaustive inversion over F₆₅₅₂₁).2. README Performance, refocused (
docs)Replaces the stale "Apple M1" tables with, in order:
not_char2add/double,PrimeFieldvsMontgomeryField, with an explicit note that each affine op includes exactly one field inversion.MontgomeryFieldvs smalljac.Result (56-bit prime, same machine, ns/op)
PrimeFieldMontgomeryFieldWith
MontgomeryFieldthe genus-2 group law matches or beats smalljac in every mode; the gap was entirely the field layer (inversion 529 → 109 ns, smalljac 157; REDC multiply 8.2 → ~0.9 ns).Checks
cargo fmt --check,cargo +stable clippy --all-targets -- -D warnings,cargo test --release(230 + doctest),cargo bench --no-run,cargo doc -D warningsall green locally.(Supersedes the dead-end stacked #4; once this merges, the
readme-perf-cleanupandbatched-group-lawbranches can be deleted.)