4 ms·
> I currently have no good idea how to make it work without a condition. Would this work? Or not worth computing both values each time? x = ((mask == 0) *
by strbean 4y ago
> I currently have no good idea how to make it work without a condition.
Would this work? Or not worth computing both values each time?
x = ((mask == 0) * x <<< popcount(x)) & ((mask != 0) * x ^ mask)
- danbruc 4y agoI have no idea if this would be worth doing. One could also use a conditional move like CMOV on x86 if available on the target architecture to avoid a jump. On the one hand I have the gut feeling that there should be a nice trick to do this, on the other hand this seems to either require a population count dependent shift or rotation or reversing the word, which also has no really simple trick as far as I know and is usually done with a logarithmic number of shifts.