Merged
Conversation
| @@ -155,8 +155,9 @@ template<typename T> | |||
| inline int halide_popcount(T a) { | |||
| int bits_set = 0; | |||
| while (a != 0) { | |||
Contributor
There was a problem hiding this comment.
FWIW, ~all modern compilers should have popcount as an intrinsic -- see popcount64 in Util.cpp, maybe we should just adapt that here
9debc3f to
158bf84
Compare
158bf84 to
9391f17
Compare
Contributor
|
What's the story on this, ready to land? |
vksnk
approved these changes
Jan 24, 2023
|
|
||
| template<typename T> | ||
| inline int halide_popcount(T a) { | ||
| inline int halide_popcount_fallback(T a) { |
Member
There was a problem hiding this comment.
I would leave a link to the source for this algorithm for the reference (found this one https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan, for example).
| bits_set += a & 1; | ||
| a >>= 1; | ||
| bits_set += 1; | ||
| // NOTE(aelphy): remove least significant zeros and the first met one |
Member
There was a problem hiding this comment.
I would just make it a regular comment (i.e. remove NOTE(aelphy) part).
Contributor
|
Where does this PR stand? |
ardier
pushed a commit
to ardier/Halide-mutation
that referenced
this pull request
Mar 3, 2024
* Improved halide_popcount * reused popcount64 from Utils.cpp in CodeGen_C * Fixed comment for popcount
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a slightly more efficient version of a popcount, which has as many iterations as many ones are in the binary representation.