Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1272939
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | xinhui <xinhui@linux.vnet.ibm.com> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v2 2/3] lib: Introduce 2 bit ops api: all_is_bit_{one,zero} |
| Date | Thu, 19 Nov 2015 09:50:02 +0100 |
| Message-ID | <qwt4J-6WM-13@gated-at.bofh.it> (permalink) |
| References | <qwrcB-5Lq-3@gated-at.bofh.it> <qwrcC-5Lq-13@gated-at.bofh.it> |
| X-Original-To | Jia He <hejianet@gmail.com>, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org |
| X-Ibm-Helo | d23dlp02.au.ibm.com |
| X-Ibm-Mailfrom | xinhui@linux.vnet.ibm.com |
| X-Ibm-Rcptto | linux-arch@vger.kernel.org;linux-kernel@vger.kernel.org |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Tm-As-Mml | disable |
| X-Content-Scanned | Fidelis XPS MAILER |
| X-Cbid | 15111908-0025-0000-0000-0000027764F4 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 89 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Andrew Morton <akpm@linux-foundation.org>, Rasmus Villemoes <linux@rasmusvillemoes.dk>, Denys Vlasenko <dvlasenk@redhat.com>, Kyungmin Park <kyungmin.park@samsung.com>, Michal Nazarewicz <mina86@mina86.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> |
| X-Original-Date | Thu, 19 Nov 2015 16:40:52 +0800 |
| X-Original-Message-ID | <564D8B14.9030509@linux.vnet.ibm.com> |
| X-Original-References | <1447915724-29709-1-git-send-email-hejianet@gmail.com> <1447915724-29709-3-git-send-email-hejianet@gmail.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1272939 |
Show key headers only | View raw
hi, jia
Nice patch. But I have one minor question. see inline comments.
On 2015/11/19 14:48, 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)
> +{
Seems better that size should be type of "unsigned long". Otherwise I'm afraid when we compare idx * BITS_PER_LONG with size, there might be overflow issue.
> + 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_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)
> +{
this argc of size should be type of "unsigned long", too.
thanks
xinhui
> + 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 */
>
--
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 v2 0/3] Improve bitmap_empty and bitmap_full Jia He <hejianet@gmail.com> - 2015-11-19 07:50 +0100
[PATCH v2 2/3] lib: Introduce 2 bit ops api: all_is_bit_{one,zero} Jia He <hejianet@gmail.com> - 2015-11-19 07:50 +0100
Re: [PATCH v2 2/3] lib: Introduce 2 bit ops api: all_is_bit_{one,zero} xinhui <xinhui@linux.vnet.ibm.com> - 2015-11-19 09:50 +0100
Re: [PATCH v2 2/3] lib: Introduce 2 bit ops api: all_is_bit_{one,zero} hejianet <hejianet@gmail.com> - 2015-11-19 10:00 +0100
Re: [PATCH v2 2/3] lib: Introduce 2 bit ops api: all_is_bit_{one,zero} yalin wang <yalin.wang2010@gmail.com> - 2015-11-19 10:00 +0100
Re: [PATCH v2 0/3] Improve bitmap_empty and bitmap_full Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-11-19 10:10 +0100
csiph-web