Hacker News new | ask | show | jobs
by wmu 1636 days 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. :)
1 comments

I 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);
  }
Thanks, that's a really elegant approach.