Optimize output modular reductions in fft_small nmod_poly_mul#2635
Merged
fredrik-johansson merged 2 commits intoflintlib:mainfrom Apr 13, 2026
Merged
Optimize output modular reductions in fft_small nmod_poly_mul#2635fredrik-johansson merged 2 commits intoflintlib:mainfrom
fredrik-johansson merged 2 commits intoflintlib:mainfrom
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.
Optimize the final output reductions mod$n$ in the $\mathbb{Z}$ have between 50 and 150 bits). Followup to #2634 which did the single prime case. The 4 CRT prime case could be done too, but this only affects multiplications so large that one gets only about a 2% speedup, which I'm not going to bother with here.
fft_smallbasednmod_polymultiplication when there are 2 or 3 CRT primes (i.e. coefficients in the product overIn essence, we replace use of the slow macros
NMOD2_RED2andNMOD_RED3with the faster algorithms discussed in #2597. I'm doing this ad hoc infft_smallfor now to test things before rolling this out to othernmodmodules. The main complication is that one needs different precomputations with some case distinctions.In the 2 CRT prime case, we get 3% additional speedup using
__uint128_tfor the CRT step instead of the generic macros. (Ideally we'd do the CRT and modular reduction directly in the SIMD representation, but that looks very tricky to implement.)Speedup ratios for
nmod_poly_mul:Speedup when squaring (slightly higher, as relatively more time is spent on output reconstruction):
In summary,