diff options
| author | Matthew Wilcox <[email protected]> | 2017-02-24 23:00:58 +0000 |
|---|---|---|
| committer | Linus Torvalds <[email protected]> | 2017-02-25 01:46:57 +0000 |
| commit | e4afd2e5567fc5d59988025f7528f9b4794d86a5 (patch) | |
| tree | d00cf7c2409d3fdeb4dbb81ec04d6cb9c0e7965d /tools/lib/find_bit.c | |
| parent | lib: add module support to atomic64 tests (diff) | |
| download | kernel-e4afd2e5567fc5d59988025f7528f9b4794d86a5.tar.gz kernel-e4afd2e5567fc5d59988025f7528f9b4794d86a5.zip | |
lib/find_bit.c: micro-optimise find_next_*_bit
This saves 32 bytes on my x86-64 build, mostly due to alignment
considerations and sharing more code between find_next_bit and
find_next_zero_bit, but it does save a couple of instructions.
There's really two parts to this commit:
- First, the first half of the test: (!nbits || start >= nbits) is
trivially a subset of the second half, since nbits and start are both
unsigned
- Second, while looking at the disassembly, I noticed that GCC was
predicting the branch taken. Since this is a failure case, it's
clearly the less likely of the two branches, so add an unlikely() to
override GCC's heuristics.
[[email protected]: v2]
Link: http://lkml.kernel.org/r/[email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Matthew Wilcox <[email protected]>
Acked-by: Yury Norov <[email protected]>
Acked-by: Rasmus Villemoes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Diffstat (limited to 'tools/lib/find_bit.c')
| -rw-r--r-- | tools/lib/find_bit.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/lib/find_bit.c b/tools/lib/find_bit.c index 6d8b8f22cf55..42c15f906aac 100644 --- a/tools/lib/find_bit.c +++ b/tools/lib/find_bit.c @@ -34,7 +34,7 @@ static unsigned long _find_next_bit(const unsigned long *addr, { unsigned long tmp; - if (!nbits || start >= nbits) + if (unlikely(start >= nbits)) return nbits; tmp = addr[start / BITS_PER_LONG] ^ invert; |
