Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1273869
| From | Geert Uytterhoeven <geert@linux-m68k.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 2/3] lib: Introduce 2 find bit api: all_is_bit_{one,zero} |
| Date | 2015-11-20 10:00 +0100 |
| Message-ID | <qwPHZ-4To-41@gated-at.bofh.it> (permalink) |
| References | <qwniF-3dU-3@gated-at.bofh.it> <qwniF-3dU-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Thu, Nov 19, 2015 at 3:31 AM, Jia He <hejianet@gmail.com> wrote:
> --- a/lib/find_bit.c
> +++ b/lib/find_bit.c
> @@ -131,6 +131,56 @@ unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
> EXPORT_SYMBOL(find_last_bit);
> #endif
>
> +#ifndef all_bit_is_zero
> +/*
> + * return val: 1 means all bit is zero
> + */
> +unsigned int all_bit_is_zero(const unsigned long *addr, unsigned size)
> +{
> + unsigned long idx;
> + unsigned long mask = size;
> +
> + if (unlikely(size == 0))
> + return 1;
> +
> + if (size > BITS_PER_LONG) {
> + for (idx = 0; idx * BITS_PER_LONG < size; idx++)
Please move the multiplication (yes, a shift) out of the loop. Not all CPUs
have barrel shifters.
> + if (addr[idx])
> + return 0;
> +
> + mask = size - (idx - 1) * BITS_PER_LONG;
> + }
> +
> + return !(*addr & BITMAP_LAST_WORD_MASK(mask));
> +}
> +EXPORT_SYMBOL(all_bit_is_zero);
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 2/3] lib: Introduce 2 find bit api: all_is_bit_{one,zero} Jia He <hejianet@gmail.com> - 2015-11-19 03:40 +0100
Re: [PATCH 2/3] lib: Introduce 2 find bit api: all_is_bit_{one,zero} Geert Uytterhoeven <geert@linux-m68k.org> - 2015-11-20 10:00 +0100
Re: [PATCH 2/3] lib: Introduce 2 find bit api: all_is_bit_{one,zero} Michal Nazarewicz <mina86@mina86.com> - 2015-11-20 15:00 +0100
csiph-web