News for hackers. Stuff that matters.
Re:EABitTricks.h by strbean on Monday December 19, 2022 @02:00PM (#34056116)
> 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)
Re:EABitTricks.h by danbruc on Monday December 19, 2022 @02:37PM (#34056580)
I 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.