Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 93678
b: refs/heads/master
c: 3a48305
h: refs/heads/master
v: v3
  • Loading branch information
Alexander van Heukelum authored and Ingo Molnar committed Apr 26, 2008
1 parent 3561f11 commit b08fd0f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2aba6925fdb96428d1129a61b1233597a03a387b
refs/heads/master: 3a48305028aa38afba93fc05066c71a6ee668ad8
29 changes: 29 additions & 0 deletions trunk/include/linux/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ extern unsigned long __find_first_bit(const unsigned long *addr,
static __always_inline unsigned long
find_first_bit(const unsigned long *addr, unsigned long size)
{
/* Avoid a function call if the bitmap size is a constant */
/* and not bigger than BITS_PER_LONG. */

/* insert a sentinel so that __ffs returns size if there */
/* are no set bits in the bitmap */
if (__builtin_constant_p(size) && (size < BITS_PER_LONG))
return __ffs((*addr) | (1ul << size));

/* the result of __ffs(0) is undefined, so it needs to be */
/* handled separately */
if (__builtin_constant_p(size) && (size == BITS_PER_LONG))
return ((*addr) == 0) ? BITS_PER_LONG : __ffs(*addr);

/* size is not constant or too big */
return __find_first_bit(addr, size);
}

Expand All @@ -143,6 +157,21 @@ extern unsigned long __find_first_zero_bit(const unsigned long *addr,
static __always_inline unsigned long
find_first_zero_bit(const unsigned long *addr, unsigned long size)
{
/* Avoid a function call if the bitmap size is a constant */
/* and not bigger than BITS_PER_LONG. */

/* insert a sentinel so that __ffs returns size if there */
/* are no set bits in the bitmap */
if (__builtin_constant_p(size) && (size < BITS_PER_LONG)) {
return __ffs(~(*addr) | (1ul << size));
}

/* the result of __ffs(0) is undefined, so it needs to be */
/* handled separately */
if (__builtin_constant_p(size) && (size == BITS_PER_LONG))
return (~(*addr) == 0) ? BITS_PER_LONG : __ffs(~(*addr));

/* size is not constant or too big */
return __find_first_zero_bit(addr, size);
}
#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
Expand Down

0 comments on commit b08fd0f

Please sign in to comment.