Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization of the non native arithmetics for pseudo-Mersenne primes. #160

Closed
DDT92 opened this issue Jan 11, 2022 · 0 comments · Fixed by #164
Closed

Optimization of the non native arithmetics for pseudo-Mersenne primes. #160

DDT92 opened this issue Jan 11, 2022 · 0 comments · Fixed by #164
Assignees
Labels
enhancement New feature or request optimization Performance improvement for the current codebase

Comments

@DDT92
Copy link

DDT92 commented Jan 11, 2022

For pseudo-Mersenne primes, i.e., primes of the form p = 2^n - c with c negligible compared to 2^n, we have that, for any decomposition x = x_hi * 2^n + x_lo, then x is equivalent to x_hi * c + x_lo modulo p. Note that we do not need that the decomposition is "normal", i.e. x_lo < 2^n, so it works for a NonNativeFieldMulResultGadget, which has oversized limbs.

We can save many constraints in the following parts of the computation:

  • allocation of k in the reduce function, due to the fact that x_hi * c + x_lo is much smaller than x;
  • product k * p, which requires - since k fits in a limb- num_limbs linear constraints and not anymore num_limbs^2.
  • group_and_check_equality: we have less groups.
    I would expect 40% less constraints for multiplication + reduction.

It would be more natural to remove the distinction between NonNativeFieldGadget and NonNativeFieldMulResult, as suggested by @UlrichHaboeck75 in his issue about refactoring non-native field gadgets, before implementing the pseudo-Mersenne reduction.
It would be better also to move to a representation of the non native gadget as a pair (limbs, limbs_max) instead of (limbs,num_adds) which we have now, as explained in my comment to @UlrichHaboeck75 issue.

For more details look at our google doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request optimization Performance improvement for the current codebase
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants