From: Michal Nazarewicz <mina86@mina86.com>
To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Denys Vlasenko <dvlasenk@redhat.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
Yury Norov <yury.norov@gmail.com>, Tejun Heo <tj@kernel.org>,
Martin Kepplinger <martink@posteo.de>,
George Spelvin <linux@horizon.com>,
Ingo Molnar <mingo@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Jia He <hejianet@gmail.com>
Subject: Re: [PATCH 2/3] lib: Introduce 2 find bit api: all_is_bit_{one,zero}
Date: Fri, 20 Nov 2015 14:57:03 +0100 [thread overview]
Message-ID: <xa1tziy893kg.fsf@mina86.com> (raw)
In-Reply-To: <1447900314-5727-3-git-send-email-hejianet@gmail.com>
On Thu, Nov 19 2015, Jia He wrote:
> This patch introduces 2 lightweight bit api.
> all_bit_is_zero return 1 if the bit string is all zero.
> The addr is the start address, the size is the bit size of the bit string.
> all_bit_is_one is the opposite.
>
> Signed-off-by: Jia He <hejianet@gmail.com>
> ---
> lib/find_bit.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 50 insertions(+)
>
> diff --git a/lib/find_bit.c b/lib/find_bit.c
> index 18072ea..1d56d8d 100644
> --- 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)
Why does it return unsigned int, not bool?
> +{
> + 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++)
> + if (addr[idx])
> + return 0;
> +
> + mask = size - (idx - 1) * BITS_PER_LONG;
Uh?
> + }
> +
> + return !(*addr & BITMAP_LAST_WORD_MASK(mask));
BITMAP_LAST_WORD_MASK takes size not mask.
> +}
The whole implementation seems weird, this seems much better to me:
unsigned int all_bit_is_zero(const unsigned long *addr, unsigned size)
{
for (; size > BITS_PER_LONG; size -= BITS_PER_LONG, ++addr)
if (*addr)
return 0;
return !size || !(*addr & BITMAP_LAST_WORD_MASK(size));
}
But to be honest I’m not entirely sure this is worth the effort.
find_next_bit and find_next_zero_bit may do a little bit more work but
some architectures have specialised optimised versions which will be
lost if all_bit_is_zero and all_bit_is_one are introduced.
> +EXPORT_SYMBOL(all_bit_is_zero);
> +#endif
> +
> +#ifndef all_bit_is_one
> +/*
> + * return val: 1 means all bit is one
> + */
> +unsigned int all_bit_is_one(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++)
> + if (~addr[idx])
> + return 0;
> +
> + mask = size - (idx - 1) * BITS_PER_LONG;
> + }
> +
> + return !(~(*addr) & BITMAP_LAST_WORD_MASK(mask));
> +}
> +EXPORT_SYMBOL(all_bit_is_one);
> +#endif
> +
> #ifdef __BIG_ENDIAN
>
> /* include/linux/byteorder does not support "unsigned long" type */
> --
> 2.5.0
>
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, ミハウ “mina86” ナザレヴイツ (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>-----ooO--(_)--Ooo--
WARNING: multiple messages have this Message-ID (diff)
From: Michal Nazarewicz <mina86@mina86.com>
To: Jia He <hejianet@gmail.com>,
linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Denys Vlasenko <dvlasenk@redhat.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
Yury Norov <yury.norov@gmail.com>, Tejun Heo <tj@kernel.org>,
Martin Kepplinger <martink@posteo.de>,
George Spelvin <linux@horizon.com>,
Ingo Molnar <mingo@kernel.org>, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH 2/3] lib: Introduce 2 find bit api: all_is_bit_{one,zero}
Date: Fri, 20 Nov 2015 14:57:03 +0100 [thread overview]
Message-ID: <xa1tziy893kg.fsf@mina86.com> (raw)
Message-ID: <20151120135703.JnygqLwe474u1OPoZ4e7mlY-NEQVidqWlO2rgFd9rzE@z> (raw)
In-Reply-To: <1447900314-5727-3-git-send-email-hejianet@gmail.com>
On Thu, Nov 19 2015, Jia He wrote:
> This patch introduces 2 lightweight bit api.
> all_bit_is_zero return 1 if the bit string is all zero.
> The addr is the start address, the size is the bit size of the bit string.
> all_bit_is_one is the opposite.
>
> Signed-off-by: Jia He <hejianet@gmail.com>
> ---
> lib/find_bit.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 50 insertions(+)
>
> diff --git a/lib/find_bit.c b/lib/find_bit.c
> index 18072ea..1d56d8d 100644
> --- 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)
Why does it return unsigned int, not bool?
> +{
> + 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++)
> + if (addr[idx])
> + return 0;
> +
> + mask = size - (idx - 1) * BITS_PER_LONG;
Uh?
> + }
> +
> + return !(*addr & BITMAP_LAST_WORD_MASK(mask));
BITMAP_LAST_WORD_MASK takes size not mask.
> +}
The whole implementation seems weird, this seems much better to me:
unsigned int all_bit_is_zero(const unsigned long *addr, unsigned size)
{
for (; size > BITS_PER_LONG; size -= BITS_PER_LONG, ++addr)
if (*addr)
return 0;
return !size || !(*addr & BITMAP_LAST_WORD_MASK(size));
}
But to be honest I’m not entirely sure this is worth the effort.
find_next_bit and find_next_zero_bit may do a little bit more work but
some architectures have specialised optimised versions which will be
lost if all_bit_is_zero and all_bit_is_one are introduced.
> +EXPORT_SYMBOL(all_bit_is_zero);
> +#endif
> +
> +#ifndef all_bit_is_one
> +/*
> + * return val: 1 means all bit is one
> + */
> +unsigned int all_bit_is_one(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++)
> + if (~addr[idx])
> + return 0;
> +
> + mask = size - (idx - 1) * BITS_PER_LONG;
> + }
> +
> + return !(~(*addr) & BITMAP_LAST_WORD_MASK(mask));
> +}
> +EXPORT_SYMBOL(all_bit_is_one);
> +#endif
> +
> #ifdef __BIG_ENDIAN
>
> /* include/linux/byteorder does not support "unsigned long" type */
> --
> 2.5.0
>
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, ミハウ “mina86” ナザレヴイツ (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>-----ooO--(_)--Ooo--
WARNING: multiple messages have this Message-ID (diff)
From: Michal Nazarewicz <mina86@mina86.com>
To: Jia He <hejianet@gmail.com>,
linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Denys Vlasenko <dvlasenk@redhat.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
Yury Norov <yury.norov@gmail.com>, Tejun Heo <tj@kernel.org>,
Martin Kepplinger <martink@posteo.de>,
George Spelvin <linux@horizon.com>,
Ingo Molnar <mingo@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
Jia He <hejianet@gmail.com>
Subject: Re: [PATCH 2/3] lib: Introduce 2 find bit api: all_is_bit_{one,zero}
Date: Fri, 20 Nov 2015 14:57:03 +0100 [thread overview]
Message-ID: <xa1tziy893kg.fsf@mina86.com> (raw)
In-Reply-To: <1447900314-5727-3-git-send-email-hejianet@gmail.com>
On Thu, Nov 19 2015, Jia He wrote:
> This patch introduces 2 lightweight bit api.
> all_bit_is_zero return 1 if the bit string is all zero.
> The addr is the start address, the size is the bit size of the bit string.
> all_bit_is_one is the opposite.
>
> Signed-off-by: Jia He <hejianet@gmail.com>
> ---
> lib/find_bit.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 50 insertions(+)
>
> diff --git a/lib/find_bit.c b/lib/find_bit.c
> index 18072ea..1d56d8d 100644
> --- 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)
Why does it return unsigned int, not bool?
> +{
> + 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++)
> + if (addr[idx])
> + return 0;
> +
> + mask = size - (idx - 1) * BITS_PER_LONG;
Uh?
> + }
> +
> + return !(*addr & BITMAP_LAST_WORD_MASK(mask));
BITMAP_LAST_WORD_MASK takes size not mask.
> +}
The whole implementation seems weird, this seems much better to me:
unsigned int all_bit_is_zero(const unsigned long *addr, unsigned size)
{
for (; size > BITS_PER_LONG; size -= BITS_PER_LONG, ++addr)
if (*addr)
return 0;
return !size || !(*addr & BITMAP_LAST_WORD_MASK(size));
}
But to be honest I’m not entirely sure this is worth the effort.
find_next_bit and find_next_zero_bit may do a little bit more work but
some architectures have specialised optimised versions which will be
lost if all_bit_is_zero and all_bit_is_one are introduced.
> +EXPORT_SYMBOL(all_bit_is_zero);
> +#endif
> +
> +#ifndef all_bit_is_one
> +/*
> + * return val: 1 means all bit is one
> + */
> +unsigned int all_bit_is_one(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++)
> + if (~addr[idx])
> + return 0;
> +
> + mask = size - (idx - 1) * BITS_PER_LONG;
> + }
> +
> + return !(~(*addr) & BITMAP_LAST_WORD_MASK(mask));
> +}
> +EXPORT_SYMBOL(all_bit_is_one);
> +#endif
> +
> #ifdef __BIG_ENDIAN
>
> /* include/linux/byteorder does not support "unsigned long" type */
> --
> 2.5.0
>
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, ミハウ “mina86” ナザレヴイツ (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>-----ooO--(_)--Ooo--
next prev parent reply other threads:[~2015-11-20 13:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-19 2:31 [PATCH 0/3] Improve bitmap_empty and bitmap_full Jia He
2015-11-19 2:31 ` [PATCH 1/3] linux/bitmap: Move 2 mask macro to bitops.h Jia He
2015-11-22 19:17 ` Andy Shevchenko
2015-11-19 2:31 ` [PATCH 2/3] lib: Introduce 2 find bit api: all_is_bit_{one,zero} Jia He
2015-11-20 8:52 ` Geert Uytterhoeven
2015-11-20 13:57 ` Michal Nazarewicz [this message]
2015-11-20 13:57 ` Michal Nazarewicz
2015-11-20 13:57 ` Michal Nazarewicz
2015-11-19 2:31 ` [PATCH 3/3] linux/bitmap: Replace find_fisrt_{zero_}bit with the new lightweight api Jia He
2015-11-19 2:53 ` kbuild test robot
2015-11-19 2:53 ` kbuild test robot
2015-11-19 2:53 ` kbuild test robot
2015-11-19 3:24 ` hejianet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xa1tziy893kg.fsf@mina86.com \
--to=mina86@mina86.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=dvlasenk@redhat.com \
--cc=hejianet@gmail.com \
--cc=kyungmin.park@samsung.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@horizon.com \
--cc=linux@rasmusvillemoes.dk \
--cc=martink@posteo.de \
--cc=mingo@kernel.org \
--cc=tj@kernel.org \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.