History

find: micro-optimize for_each_{set,clear}_bit()

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().

Yury Norov committed 5 years ago

Commit 7516be91 parent bc9d6631 file · +2 −2Browse files

Unified · Split

include/linux/find.h+2−2
@@ -280,7 +280,7 @@ unsigned long find_next_bit_le(const void *addr, unsigned · 279 unmodified lines
280#endif280#endif
281 281
282#define for_each_set_bit(bit, addr, size) \282#define for_each_set_bit(bit, addr, size) \
283 for ((bit) = find_first_bit((addr), (size)); \283 for ((bit) = find_next_bit((addr), (size), 0); \
284 (bit) < (size); \284 (bit) < (size); \
285 (bit) = find_next_bit((addr), (size), (bit) + 1))285 (bit) = find_next_bit((addr), (size), (bit) + 1))
286 286
@@ -291,7 +291,7 @@ unsigned long find_next_bit_le(const void *addr, unsigned · 4 unmodified lines
291 (bit) = find_next_bit((addr), (size), (bit) + 1))291 (bit) = find_next_bit((addr), (size), (bit) + 1))
292 292
293#define for_each_clear_bit(bit, addr, size) \293#define for_each_clear_bit(bit, addr, size) \
294 for ((bit) = find_first_zero_bit((addr), (size)); \294 for ((bit) = find_next_zero_bit((addr), (size), 0); \
295 (bit) < (size); \295 (bit) < (size); \
296 (bit) = find_next_zero_bit((addr), (size), (bit) + 1))296 (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
297 297

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t