4 ms·
Author here. I cannot use BSR, because have to execute code for all bits, regardless their value. The range is: the last bit to the first with value 1. It's a n
by wmu 5y ago
Author here. I cannot use BSR, because have to execute code for all bits, regardless their value. The range is: the last bit to the first with value 1. It's a non-obvious iteration schema. :)
- tzs 5y agoI took that into account, although it may not have been clear because I tried to describe it in words rather than code. What I was suggesting was something like this (in pseudocode): int previous_leftmost = 64; while (mask != 0) { leftmost = find_leftmost(mask); mask ^= 1u << leftmost; while (--previous_leftmost > leftmost) func_false(previous_leftmost); func_true(leftmost); }
- wmu 5y agoThanks, that's a really elegant approach.