Remove “except in benchmarks” exception for fp math #689

pull laanwj wants to merge 1 commits into bitcoin-core:master from laanwj:2019_11_bench_uint64 changing 2 files +63 −21
  1. laanwj commented at 2:56 pm on November 5, 2019: member

    Convert bench.h to fixed-point math, removing all use of float math from the repository:

    • Use 64-bit integer microsecond timestamps
    • Use decimal fixed-point math for formatting numbers

    It turned out to be a little trickier than I expected because of formatting and rounding. But, output should be the same before and after.

    I used the following to test the number formatting: https://gist.github.com/laanwj/f971bfbe018e39c19677a21ff954d0c7

  2. laanwj force-pushed on Nov 5, 2019
  3. laanwj force-pushed on Nov 5, 2019
  4. laanwj force-pushed on Nov 5, 2019
  5. real-or-random approved
  6. real-or-random commented at 0:24 am on November 6, 2019: contributor
    ACK 8a7dea11927606f15c36e4fe6ea8c47334af98a3 I’ve read the code in detail and I’ve tested it. I haven’t explicitly tested the formatting function with known/hardcoded inputs.
  7. real-or-random commented at 0:27 am on November 6, 2019: contributor
    Nice! Now I don’t want to work on the related #680 because I may end up removing parts of your excellent formatting function…
  8. laanwj commented at 9:26 am on November 6, 2019: member

    I searched around a bit and it doesn’t seem there’s currently any way to tell the compiler (gcc or otherwise) to fail on any use on floating point. So we can’t easily check this policy in the CI. Not that it matters, it’s a relatively small project and changes here are well-reviewed.

    Nice! Now I don’t want to work on the related #680 because I may end up removing parts of your excellent formatting function…

    Haha yes I leave the “how to show the benchmark” part up to you. I think there’s different preferences in that regard.

    I made that it’s straightforward to split up in a “how many decimals to show” and generic “format fixed-point with n decimals” part.

  9. apoelstra commented at 6:26 pm on November 6, 2019: contributor
    FWIW the output of git grep 'double ' is only two lines, both of which are comments. And git grep float is empty. We could just have CI check this :P
  10. gmaxwell commented at 0:48 am on November 7, 2019: contributor
    Very nice. One thing that wasn’t clear to me was what is protecting overflow in the fixed point scaling?
  11. laanwj commented at 8:54 am on November 7, 2019: member

    Very nice. One thing that wasn’t clear to me was what is protecting overflow in the fixed point scaling?

    You mean this part?

    0    printf("%s: min ", name);
    1    print_number(min * FP_MULT / iter);
    2    printf("us / avg ");
    3    print_number(((sum * FP_MULT) / count) / iter);
    4    printf("us / max ");
    5    print_number(max * FP_MULT / iter)
    

    The value is in microseconds and is multiplied with 1e6, so if my computation is correct ((1<<63)/1e6/1e6) it takes 9.2 megasecond (~1/3th year) until an overflow can happen. Do you think anyone is going to wait that long for a benchmark?

    It would definitely be possible to add overflow checks here but it seemed overkill.

  12. gmaxwell commented at 7:53 pm on November 7, 2019: contributor
    Indeed, that seems more than adequate. I should have done the math!
  13. laanwj commented at 11:44 am on November 25, 2019: member
    Anything left to do here?
  14. real-or-random commented at 11:25 am on November 26, 2019: contributor

    I think there’s nothing left do to here.

    But can we get a second (untested) ACK here? @gmaxwell You apparently looked at it, do you mind ACKing it?

  15. gmaxwell commented at 7:47 pm on December 9, 2019: contributor
    ACK
  16. Convert bench.h to fixed-point math
    - Use 64-bit integer microsecond timestamps
    - Use fixed-point math for formatting numbers
    
    Then, remove "except in benchmarks" exception from `README.md`.
    bde2a32286
  17. in src/bench.h:9 in 8a7dea1192 outdated
    8@@ -9,41 +9,82 @@
    9 
    


    real-or-random commented at 11:42 am on December 11, 2019:
    0
    1#include <stdint.h>
    

    This currently builds fine because util.h is included in every bench_ program. But that’s somewhat fragile.


    laanwj commented at 6:05 pm on December 12, 2019:
    thanks, added commit
  18. laanwj force-pushed on Dec 13, 2019
  19. real-or-random commented at 11:23 am on December 13, 2019: contributor
    ACK bde2a32286c697dd1056aa3eb1ea2a5353f0bede I’ve read the code in detail and I’ve tested it. I haven’t explicitly tested the formatting function with known/hardcoded inputs.
  20. real-or-random referenced this in commit d644dda5c9 on Dec 13, 2019
  21. real-or-random merged this on Dec 13, 2019
  22. real-or-random closed this on Dec 13, 2019

  23. sipa cross-referenced this on Jun 9, 2020 from issue Update libsecp256k1 subtree by sipa
  24. fanquake referenced this in commit 8c97780db8 on Jun 13, 2020
  25. sidhujag referenced this in commit 8a3a072968 on Jun 13, 2020
  26. ComputerCraftr referenced this in commit b98f1c6e6c on Jun 16, 2020
  27. UdjinM6 referenced this in commit 9d36ba6570 on Aug 10, 2021
  28. 5tefan referenced this in commit 8ded2caa74 on Aug 12, 2021
  29. gades referenced this in commit d855cc511d on May 8, 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: 2024-11-22 20:15 UTC

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