Skip to content

Commit

Permalink
find: micro-optimize for_each_{set,clear}_bit()
Browse files Browse the repository at this point in the history
The macros iterate thru all set/clear bits in a bitmap. They search a
first bit using find_first_bit(), and the rest bits using find_next_bit().

Since find_next_bit() is called shortly after find_first_bit(), we can
save few lines of I-cache by not using find_first_bit().

Signed-off-by: Yury Norov <[email protected]>
Tested-by: Wolfram Sang <[email protected]>
  • Loading branch information
YuryNorov committed Jan 15, 2022
1 parent bc9d663 commit 7516be9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/linux/find.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ unsigned long find_next_bit_le(const void *addr, unsigned
#endif

#define for_each_set_bit(bit, addr, size) \
for ((bit) = find_first_bit((addr), (size)); \
for ((bit) = find_next_bit((addr), (size), 0); \
(bit) < (size); \
(bit) = find_next_bit((addr), (size), (bit) + 1))

Expand All @@ -291,7 +291,7 @@ unsigned long find_next_bit_le(const void *addr, unsigned
(bit) = find_next_bit((addr), (size), (bit) + 1))

#define for_each_clear_bit(bit, addr, size) \
for ((bit) = find_first_zero_bit((addr), (size)); \
for ((bit) = find_next_zero_bit((addr), (size), 0); \
(bit) < (size); \
(bit) = find_next_zero_bit((addr), (size), (bit) + 1))

Expand Down

0 comments on commit 7516be9

Please sign in to comment.