Skip to content

Commit 8f6f19d

Browse files
YuryNorovtorvalds
authored andcommitted
lib: move find_last_bit to lib/find_next_bit.c
Currently all 'find_*_bit' family is located in lib/find_next_bit.c, except 'find_last_bit', which is in lib/find_last_bit.c. It seems, there's no major benefit to have it separated. Signed-off-by: Yury Norov <yury.norov@gmail.com> Reviewed-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Reviewed-by: George Spelvin <linux@horizon.com> Cc: Alexey Klimov <klimov.linux@gmail.com> Cc: David S. Miller <davem@davemloft.net> Cc: Daniel Borkmann <dborkman@redhat.com> Cc: Hannes Frederic Sowa <hannes@stressinduktion.org> Cc: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Mark Salter <msalter@redhat.com> Cc: AKASHI Takahiro <takahiro.akashi@linaro.org> Cc: Thomas Graf <tgraf@suug.ch> Cc: Valentin Rothberg <valentinrothberg@gmail.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2c57a0e commit 8f6f19d

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ obj-y += lockref.o
2525
obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
2626
bust_spinlocks.o kasprintf.o bitmap.o scatterlist.o \
2727
gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \
28-
bsearch.o find_last_bit.o find_next_bit.o llist.o memweight.o kfifo.o \
28+
bsearch.o find_next_bit.o llist.o memweight.o kfifo.o \
2929
percpu-refcount.o percpu_ida.o rhashtable.o reciprocal_div.o
3030
obj-y += string_helpers.o
3131
obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o

lib/find_next_bit.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
/* find_next_bit.c: fallback find next bit implementation
1+
/* bit search implementation
22
*
33
* Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
44
* Written by David Howells (dhowells@redhat.com)
55
*
6+
* Copyright (C) 2008 IBM Corporation
7+
* 'find_last_bit' is written by Rusty Russell <rusty@rustcorp.com.au>
8+
* (Inspired by David Howell's find_next_bit implementation)
9+
*
610
* Rewritten by Yury Norov <yury.norov@gmail.com> to decrease
711
* size and improve performance, 2015.
812
*
@@ -13,6 +17,7 @@
1317
*/
1418

1519
#include <linux/bitops.h>
20+
#include <linux/bitmap.h>
1621
#include <linux/export.h>
1722
#include <linux/kernel.h>
1823

@@ -106,6 +111,26 @@ unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size)
106111
EXPORT_SYMBOL(find_first_zero_bit);
107112
#endif
108113

114+
#ifndef find_last_bit
115+
unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
116+
{
117+
if (size) {
118+
unsigned long val = BITMAP_LAST_WORD_MASK(size);
119+
unsigned long idx = (size-1) / BITS_PER_LONG;
120+
121+
do {
122+
val &= addr[idx];
123+
if (val)
124+
return idx * BITS_PER_LONG + __fls(val);
125+
126+
val = ~0ul;
127+
} while (idx--);
128+
}
129+
return size;
130+
}
131+
EXPORT_SYMBOL(find_last_bit);
132+
#endif
133+
109134
#ifdef __BIG_ENDIAN
110135

111136
/* include/linux/byteorder does not support "unsigned long" type */

0 commit comments

Comments
 (0)