perf: optimize range checks for small number of small field ops#1699
Merged
perf: optimize range checks for small number of small field ops#1699
Conversation
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.
Description
Additionally, sets MulNoReduce as default when calling
Field.Mulon small field parameter.Fixes #1698
Type of change
How has this been tested?
How has this been benchmarked?
Checklist:
golangci-lintdoes not output errors locallyNote
Medium Risk
Changes
Field.Mulsemantics for single-limb emulated fields by defaulting to non-reducing multiplication, which can affect callers that assumedMulalways reduced (now must useMulModfor that guarantee). Adds stateful range-check deduplication and a threshold-triggered switch in range-checking behavior, which impacts constraint generation and overflow handling in hot paths.Overview
Optimizes emulated-field range checks and small-field multiplication. Range checks now go through a new
Field.rangeCheckhelper that deduplicates checks per limb (tracking the widest enforced bit-width) and counts how many checks have been emitted.For small-field emulation, range checking switches only after
thresholdForInexactOverflowchecks to a base-length (16-bit) range checker, andsmallAdditionalOverflow()now returns non-zero only after that threshold to keep overflow accounting consistent.Field.Mulnow defaults toMulNoReducewhenuseSmallFieldOptimization()is enabled, falling back to reducing multiplication only when overflow would exceed limits; callers needing guaranteed modular reduction should useMulMod. Tests/benchmarks are adjusted accordingly (bench compile loop guard + suppressns/op, and malicious-hint circuit usesMulMod).Written by Cursor Bugbot for commit c994745. This will update automatically on new commits. Configure here.