-
Notifications
You must be signed in to change notification settings - Fork 115
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
Hadar/b const mult #723
Hadar/b const mult #723
Conversation
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.
some questions and optimizations
@@ -25,6 +25,11 @@ namespace bls12_377 { | |||
static constexpr point_field_t weierstrass_b = {0x00000001, 0x00000000, 0x00000000, 0x00000000, | |||
0x00000000, 0x00000000, 0x00000000, 0x00000000, | |||
0x00000000, 0x00000000, 0x00000000, 0x00000000}; | |||
static constexpr point_field_t weierstrass_3b = {0x00000003, 0x00000000, 0x00000000, 0x00000000, |
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.
do we really need that extra definition?
using constexpr in the code does not yield the same performance?
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.
it probably will, i can try
if constexpr (Gen::is_b_u32) { | ||
r = mul_unsigned<Field{Gen::weierstrass_3b}.limbs_storage.limbs[0], Field>(xs); | ||
if constexpr (Gen::is_b_neg) | ||
return neg(r); |
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 think it will be more efficient to write here another multiplication by neg(b) which can be calculated in constexpr
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 don't understand.. xs is known only at runtime, this cannot be calculated in constexpr
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.
according to your code, the neg(r) is calculated in runtime
you can write instead of "return neg(r)"
return mul_unsigned<neg(Field{Gen::weierstrass_3b}.limbs_storage.limbs[0], Field)>(xs);
that way the neg operation will be calculated at compile time
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.
that will ruin the whole point of the optimization... 3b is stored in absolute value because it's small that way
if constexpr (Gen::is_b_u32_g2_re) { | ||
r = FF::template mul_unsigned<FF{Gen::weierstrass_3b_g2_re}.limbs_storage.limbs[0], FF>(xs); | ||
if constexpr (Gen::is_b_neg_g2_re) | ||
return FF::neg(r); |
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 think it will be more efficient to write here another multiplication by neg(b) which can be calculated in constexpr
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.
same here
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.
Agree with miki that we should compute weistrass_3b at compile time instead. Other than that LGTM
. |
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.
V
This PR optimizes the multiplication by the constant 3b in the EC addition.
It seems to significantly improve the CPU MSM performance and the CUDA MSM performance a tiny bit.