I want to create a bitmask for the most right continuous range of set bits. For example 01010110 -> 00000110. Is (x & ~(x + (x & -x))) the best way to do that or is there a better solution? #followerpower
-
-
Replying to @oe1cxw
Bit scan instructions, obviously, if it doesn't need to be portable. Other than that, maybe http://webpages.charter.net/tlikens/tech/bitmaps/bit_popcnt.html … could be a source of inspiration?
1 reply 0 retweets 2 likes -
Replying to @andreasdotorg
Can you give an example for how to implement that more efficiently using bit scan instructions? I can't seem to be able to build something more efficient. (Even if I assume ctz(0)/clz(0) to be defined.)
1 reply 0 retweets 0 likes -
Replying to @oe1cxw
CTZ/shift right/inverse/CTZ. Not sure if this is more efficient, but maybe worth looking into.
2 replies 0 retweets 2 likes
That's what I tried. The best implementation using this scheme I came up with is this, which I do not think is more efficient, and it does not work for x=-1 if ctz(0) is undefined. http://svn.clifford.at/handicraft/2018/cbmc/lastblock.c …pic.twitter.com/rZj7zfEUzc
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.