-
Notifications
You must be signed in to change notification settings - Fork 570
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
Add fast iterated point doubling #4221
Conversation
63940fd
to
fa72be4
Compare
constexpr Self dbl_n(size_t n) const { | ||
// TODO it is possible to optimize this by carrying over values from | ||
// the previous iteration into the next | ||
if constexpr(Self::A_is_minus_3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case you want to express this as a good-old function overload, I think you could do this:
constexpr Self dbl_n(size_t n const)
requires(Self::A_is_minus_3)
{
// ...
}
constexpr Self dbl_n(size_t n const)
requires(!Self::A_is_minus_3)
{
// ...
}
... to avoid the if constexpr
spanning the entirety of the function. No strong opinion on what is more idiomatic from my side. But, I generally think, the less indentation the better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect in the future this will expand to cover other types of curves (A == 0 and/or generic A) in which case the single function will be cleaner.
auto nx = x(); | ||
auto ny = y(); | ||
auto nz = z(); | ||
ny = ny.mul2(); | ||
auto w = nz.square().square(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to early-return on n == 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really in practice - we call this with n
derived from window sizes so n
is always > 0
Improves ECDH performance for curves with A == -3 by 5-9%
7bc856d
to
b5a922f
Compare
Improves ECDH performance for curves with A == -3 by 5-9%
#4027