Rewrite 5x52 normalize method to be faster #24

pull peterdettman wants to merge 1 commits into bitcoin-core:master from peterdettman:faster-64bit-normalize changing 1 files +33 −35
  1. peterdettman commented at 8:37 AM on June 2, 2014: contributor

    No description provided.

  2. sipa commented at 9:21 AM on June 2, 2014: contributor

    Nice, this gives an actual measurable speedup for verification a few %.

    I'm convinced that it's correct, but it took me a while. Some comments could help (which is equally true for the previous implementation, though...).

    In the first block, you reduce a2^256 + b to a \ 0x1000003D1 + b, with b < 2^256. That results in at most 2^256 + (<2^64).

    In the second block, you set x to (n >= 2^256 - 0x1000003D1), add x * 0x1000003D1, know that it overflows if x == 1, and remove 2^256 by masking t4. You could add an assert (x == t4 >> 48) before the masking, I think, as the adding of 0x1000003D1 and subtraction of 2^256 should always happen both or neither.

  3. Rewrite 5x52 normalize method to be faster 9037707720
  4. peterdettman commented at 12:17 PM on June 3, 2014: contributor

    Yes, I think you described it pretty well! I've squashed in some comments now, and added a couple of asserts as suggested.

  5. sipa commented at 1:50 PM on June 3, 2014: contributor

    ACK

  6. sipa merged this on Jun 3, 2014
  7. sipa closed this on Jun 3, 2014

  8. sipa referenced this in commit b110f84bbb on Jun 3, 2014
  9. peterdettman cross-referenced this on Jun 22, 2014 from issue Test demonstrating discrepancy in sqr output by peterdettman
  10. peterdettman deleted the branch on Jun 22, 2014
  11. tecnovert referenced this in commit eca632d585 on Apr 18, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me