util: move MapIntoRange() for reuse in fuzz tests #23760

pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:reuse_mapintorange changing 3 files +31 −45
  1. fanquake commented at 12:57 PM on December 13, 2021: member

    No description provided.

  2. MarcoFalke added the label Refactoring on Dec 13, 2021
  3. sipa commented at 4:10 PM on December 13, 2021: member

    This technique is actually used in a few other places in the codebase, though this is the only one that does it for 64-bit inputs and ranges; at least in cache::compute_hashes in cuckoocache.h and FastMod in common/bloom.cpp. It's also used in bench/nanobench.h, but I think that file is intended to stay dependencyless.

    Perhaps it would make sense to have specific functions for both (e.g. FastRange32, FastRange64) and put them in an integer util file or so?

  4. jamesob commented at 4:41 PM on December 13, 2021: member

    Code review ACK https://github.com/bitcoin/bitcoin/pull/23760/commits/a8dc99f21cafaa8d37ea16bf9441872d5d653e09

    Mergeable as it stands IMO, but what @sipa's saying probably makes sense too.

  5. shaavan commented at 10:07 AM on December 14, 2021: contributor

    Concept ACK

    Moving the MapIntoRange allows both src/blockfilter.cpp and src/test/fuzz/golomb_rice.cpp to access the function while removing unnecessary duplicated code.

    The one small thing that bugs me is using static keywords with the utility function. To be honest, I could not clearly understand the reasoning behind using (or not using) the static keyword with a utility function. Still, I had not seen many src/util functions with a static keyword in its definition.

    P.s.: I tried to comprehend the reasoning of static keyword, but I could not find a good reference for it. And I considered it is better to ask rather than to give an uninformed ACK.

  6. MarcoFalke commented at 10:25 AM on December 14, 2021: member

    I think using static in a header file is a way to embed the compiled function into every object file that uses it (as opposed to putting it into one object only and then linking that)?

  7. shaavan commented at 1:05 PM on December 15, 2021: contributor

    embed the compiled function into every object file that uses it

    So wouldn't it increase the memory used at runtime by the application? Is the speed boost provided by using static worth increasing memory usage?

  8. sipa commented at 2:01 PM on December 15, 2021: member

    Using static here means that indeed, every compilation unit gets its own copy of the function. But, on the other hand, it means it doesn't need to be emitted either if all call-sites can be inlined (because static functions are only accessible from within their own compilation unit; if there are no explicit calls left, the function doesn't need to be emitted), which is almost certainly the case. So the practical effect is really that it appears 0 times in the overall compilation output rather than 1 time.

  9. MarcoFalke commented at 2:05 PM on December 15, 2021: member

    I guess changing static to inline here wouldn't change the binary, but clarify the intent a bit more?

  10. sipa commented at 2:08 PM on December 15, 2021: member

    It could change the binary. Marking it inline but not static means the compiler still has to emit it. -ffunction-sections and -Wl,--gc-sections will let the linker remove it, though.

    I think it should be both inline and static.

  11. shaavan commented at 7:09 AM on December 16, 2021: contributor

    I think it should be both inline and static.

    As far as I understand the usage of static and inline, I think it's best to go with this solution.

  12. util: move MapIntoRange() for reuse in fuzz tests df2307cdc3
  13. fanquake force-pushed on Dec 23, 2021
  14. fanquake commented at 7:26 AM on December 23, 2021: member

    I think it should be both inline and static.

    Updated to be static inline.

  15. MarcoFalke commented at 7:28 AM on December 23, 2021: member

    See also the feedback here: #23760 (comment)

  16. fanquake commented at 7:29 AM on December 23, 2021: member

    See also the feedback here: #23760 (comment)

    Going to leave that for now. Happy for someone else to follow up.

  17. shaavan approved
  18. shaavan commented at 11:41 AM on December 23, 2021: contributor

    ACK df2307cdc3d08233d17beb9a50c144baaef1f44e

    Changes since my last review:

    • static -> static inline

    The rationale for the change is discussed above, with which I agree.

    Going to leave that for now. Happy for someone else to follow up.

    #23760 (comment) seems interesting. Let me try working upon it, and give an update as soon as possible.

  19. MarcoFalke merged this on Jan 6, 2022
  20. MarcoFalke closed this on Jan 6, 2022

  21. sipa commented at 5:00 PM on January 6, 2022: member

    Going to leave that for now. Happy for someone else to follow up.

    See #23994.

  22. sidhujag referenced this in commit 837b427fe2 on Jan 6, 2022
  23. PastaPastaPasta referenced this in commit dfbcaf77a3 on Jul 17, 2022
  24. PastaPastaPasta referenced this in commit 4c1e9afc55 on Aug 30, 2022
  25. bitcoin locked this on Jan 6, 2023
  26. fanquake deleted the branch on Sep 14, 2023

github-metadata-mirror

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

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