lib/find_bit: introduce FIND_FIRST_BIT() macro
authorYury Norov <yury.norov@gmail.com>
Thu, 15 Sep 2022 02:07:27 +0000 (19:07 -0700)
committerYury Norov <yury.norov@gmail.com>
Wed, 21 Sep 2022 19:15:53 +0000 (12:15 -0700)
commit58414bbb58a8b49af20e3accae56f6f8344b2424
treee18acc7bcec118a162e967d177887ae4e4d80211
parent6f9c07be9d020489326098801f0661f754c7c865
lib/find_bit: introduce FIND_FIRST_BIT() macro

Now that we have many flavors of find_first_bit(), and expect even more,
it's better to have one macro that generates optimal code for all and makes
maintaining of slightly different functions simpler.

The logic common to all versions is moved to the new macro, and all the
flavors are generated by providing an FETCH macro-parameter, like
in this example:

  #define FIND_FIRST_BIT(FETCH, MUNGE, size) ...

  find_first_ornot_and_bit(addr1, addr2, addr3, size)
  {
        return FIND_FIRST_BIT(addr1[idx] | ~addr2[idx] & addr3[idx], /* nop */, size);
  }

The FETCH may be of any complexity, as soon as it only refers
the bitmap(s) and an iterator idx.

MUNGE is here to support _le code generation for BE builds. May be
empty.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
Signed-off-by: Yury Norov <yury.norov@gmail.com>
lib/find_bit.c