Skip to content

Reduce stratch space needed by ecmult_strauss_wnaf. - #899

Merged
jonasnick merged 9 commits into
bitcoin-core:masterfrom
roconnor-blockstream:no-prej
Jan 26, 2022
Merged

Reduce stratch space needed by ecmult_strauss_wnaf.#899
jonasnick merged 9 commits into
bitcoin-core:masterfrom
roconnor-blockstream:no-prej

Conversation

@roconnor-blockstream

Copy link
Copy Markdown
Contributor

No description provided.

@roconnor-blockstream
roconnor-blockstream marked this pull request as ready for review February 26, 2021 22:18
@roconnor-blockstream roconnor-blockstream changed the title WIP: Eliminate the prej array from ecmult_strauss_wnaf. Eliminate the prej array from ecmult_strauss_wnaf. Feb 26, 2021
@roconnor-blockstream roconnor-blockstream changed the title Eliminate the prej array from ecmult_strauss_wnaf. Reduce stratch space needed by ecmult_strauss_wnaf. Feb 27, 2021
@roconnor-blockstream
roconnor-blockstream force-pushed the no-prej branch 3 times, most recently from fcb614a to 4ba9971 Compare March 1, 2021 13:26
@roconnor-blockstream

ghost commented Mar 29, 2021

Copy link
Copy Markdown
Contributor Author

Address @sipa 's comments from #900.

Please review this PR first.

@roconnor-blockstream

ghost commented Apr 6, 2021

Copy link
Copy Markdown
Contributor Author

@real-or-random observes that STRAUSS_SCRATCH_OBJECTS needs to be updated.

@roconnor-blockstream

ghost commented May 12, 2021

Copy link
Copy Markdown
Contributor Author

Rebased and updated STRAUSS_SCRATCH_OBJECTS.

@roconnor-blockstream

ghost commented Aug 28, 2021

Copy link
Copy Markdown
Contributor Author

rebased.

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK, secp256k1_ecmult_strauss_wnaf indeed uses scratch space more efficiently with this change.

I ran ./bench_ecmult strauss_wnaf at both 1cd7ab2 and 9a5a87e just to make sure there's no obvious regression in running time.

Unfortunately it looks like this might have some merge conflicts with #638 depending on which gets merged first.

Comment thread src/ecmult_impl.h Outdated
* The omitted z-coordinate are implied by the final a value's z-coordinate and the zr array.
*/
static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_gej *prej, secp256k1_fe *zr, const secp256k1_gej *a) {
static void secp256k1_ecmult_odd_multiples_table(int n, secp256k1_ge *pre_a, secp256k1_fe *zr, secp256k1_gej *a) {

ghost Dec 1, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit (feel free to ignore): Instead of making a mutable, would it make sense to have an output parameter for the final z value, since that's the only part of a that gets read later?

ghost Dec 1, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have learned that returning structures is frowned upon in C.

ghost Dec 1, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I agree with you about that. What I was suggesting is to have an extra parameter to the function that's a pointer like secp256k1_fe *global_z (or maybe z_final), instead of updating a in place.

ghost Dec 3, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I'm a little tempted to take z as an input and rescale the a value by its value, but it is probably best to leave it as is.

Comment thread src/group.h Outdated
Comment thread src/ecmult_impl.h Outdated
Comment thread src/ecmult_impl.h
Comment thread src/group.h Outdated
@roconnor-blockstream
roconnor-blockstream force-pushed the no-prej branch 2 times, most recently from 80fc6f1 to ae33232 Compare December 3, 2021 23:12

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I took another look and I think I have a better understanding now. This PR looks pretty solid.

I left a few suggestions for comments / style, mostly because I thought some parts were confusing even before your PR. If you prefer I can also push them to some branch as a follow-up commit.

Comment thread src/ecmult_impl.h Outdated
Comment thread src/ecmult_impl.h
Comment thread src/group.h Outdated
Comment thread src/group_impl.h
Comment thread src/field_impl.h Outdated
@roconnor-blockstream

ghost commented Dec 8, 2021

Copy link
Copy Markdown
Contributor Author

Thanks @robot-dreams. I've taken your suggestions and made some minor adjustments to them.

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 5aea2e8 (from inspecting the range diff against ae33232)

Comment thread src/group.h Outdated
Comment thread src/group.h Outdated
@robot-dreams

ghost commented Dec 10, 2021

Copy link
Copy Markdown
Contributor

ACK b6ed302

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff and despite being an optimization, this PR simplifies a lot of things as well. Also thanks for the new comments. They're really helpful.

ACK mod nits

Comment thread src/group.h Outdated
Comment thread src/ecmult_impl.h Outdated
Comment thread src/ecmult_impl.h Outdated
Comment thread src/ecmult_impl.h Outdated
Comment thread src/ecmult_impl.h
Comment thread src/ecmult_impl.h
@roconnor-blockstream

ghost commented Jan 19, 2022

Copy link
Copy Markdown
Contributor Author

I've rearranged the code a little bit and rewritten the comments a bit.

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK b797a50

@sipa

ghost commented Jan 25, 2022

Copy link
Copy Markdown
Contributor

ACK b797a50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants