-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Use C++20 function std::popcount #4389
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.
Looks OK, modulo the MacOS compilation issues, and I like that it uses std
instead of intrinsics or hand-rolled code. I think someone with MacOS can check if newer versions of XCode support std::popcount
and if so, whether it makes sense to upgrade the CI.
One option might be to leave the popcnt16
function in place for now (perhaps inlining it in the header file?) as a thin wrapper around std::popcount
for non MacOS platforms, and a call to __builtin_popcount
for MacOS.
OK i can makethe change |
CI has reported failures; please review them. |
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.
This change is required to compile on macOS: HowardHinnant@ab5e386
Explanation: The expression isBranch_ | (1 << m)
promotes to int
which is then sent to std::popcount
. But popcount
has a constraint that its argument be an unsigned integral type. Adding the u
suffix makes the expression unsigned
.
@a-noni-mousse please review the comments above. |
e03b62a
to
23b140d
Compare
I have fixed the comments from Hooward and Nic. |
@a-noni-mousse for future reference - there's no need to force push, as this PR will be squashed when it is merged. Keeping historical commits may help reviewers to more easily see how the PR has changed over 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.
Looks fine.
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'm getting several errors on a non-unity build that look like this:
In file included from /Users/howardhinnant/Development/rippled/src/ripple/app/consensus/RCLConsensus.cpp:20:
In file included from /Users/howardhinnant/Development/rippled/src/ripple/app/consensus/RCLConsensus.h:23:
In file included from /Users/howardhinnant/Development/rippled/src/ripple/app/consensus/RCLCensorshipDetector.h:24:
In file included from /Users/howardhinnant/Development/rippled/src/ripple/shamap/SHAMap.h:30:
/Users/howardhinnant/Development/rippled/src/ripple/shamap/SHAMapInnerNode.h:213:12: error: use of undeclared identifier 'popcnt16'
return popcnt16(isBranch_);
^
Not positive, but I suspect we're looking at a cyclic include dependency which is preventing the declaration of popcnt16
appearing before its use.
Ah I edit the code on the github and that's what I get! Thank you i will fix this @HowardHinnant |
Suggested commit message for squashed commit:
@manojsdoshi - be sure to squash this PR when merging, as requested above. |
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability Signed-off-by: Manoj Doshi <mdoshi@ripple.com>
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability Signed-off-by: Manoj Doshi <mdoshi@ripple.com>
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability Signed-off-by: Manoj Doshi <mdoshi@ripple.com>
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability Signed-off-by: Manoj Doshi <mdoshi@ripple.com>
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability Signed-off-by: Manoj Doshi <mdoshi@ripple.com>
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability Signed-off-by: Manoj Doshi <mdoshi@ripple.com>
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability Signed-off-by: Manoj Doshi <mdoshi@ripple.com>
- Replace custom popcnt16 implementation with std::popcount from C++20 - Maintain compatibility with older compilers and MacOS by providing a conditional compilation fallback to __builtin_popcount and a lookup table method - Move and inline related functions within SHAMapInnerNode for performance and readability Signed-off-by: Manoj Doshi <mdoshi@ripple.com>
High Level Overview of Change
Remove the custom code and special compiler functions and use C++20 function
std::popcount
and makeinline
for optimization of the code. The changed code is good when compiled and produces same or even better assembly code which you can see on the compiler explorerContext of Change
Type of Change