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
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.)
-
-
CTZ/shift right/inverse/CTZ. Not sure if this is more efficient, but maybe worth looking into.
-
That doesn’t give a mask. You’ll still need to clear the other bits of the res2, for example, shifting it left by XLEN-res4 and then right by XLEN-res1. All of which takes five more instructions.
End of conversation
New conversation -
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.