* [PATCH] lib: bitmap_[empty,full]: remove code duplication
@ 2015-03-16 17:56 Yury Norov
2015-03-24 22:53 ` Andrew Morton
2015-03-29 2:03 ` [PATCH v2] " Yury Norov
0 siblings, 2 replies; 5+ messages in thread
From: Yury Norov @ 2015-03-16 17:56 UTC (permalink / raw)
To: linux, klimov.linux, linux, akpm; +Cc: yury.norov, linux-kernel
Function 'bitmap_empty' has it's own implementation.
But it's clearly as simple as:
"find_first_bit(src, nbits) == nbits"
The same is true for 'bitmap_full'.
Underscored versions of 'bitmap_[empty,full]' are not
needed anymore and so removed too.
Boot-tested on Core i7-2630QM.
---
include/linux/bitmap.h | 10 ++--------
lib/bitmap.c | 30 ------------------------------
2 files changed, 2 insertions(+), 38 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index dbfbf49..a56e250 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -285,18 +285,12 @@ static inline int bitmap_subset(const unsigned long *src1,
static inline int bitmap_empty(const unsigned long *src, unsigned nbits)
{
- if (small_const_nbits(nbits))
- return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
- else
- return __bitmap_empty(src, nbits);
+ return find_first_bit(src, nbits) == nbits;
}
static inline int bitmap_full(const unsigned long *src, unsigned int nbits)
{
- if (small_const_nbits(nbits))
- return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
- else
- return __bitmap_full(src, nbits);
+ return find_first_zero_bit(src, nbits) == nbits;
}
static inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
diff --git a/lib/bitmap.c b/lib/bitmap.c
index d456f4c1..64c0926 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -42,36 +42,6 @@
* for the best explanations of this ordering.
*/
-int __bitmap_empty(const unsigned long *bitmap, unsigned int bits)
-{
- unsigned int k, lim = bits/BITS_PER_LONG;
- for (k = 0; k < lim; ++k)
- if (bitmap[k])
- return 0;
-
- if (bits % BITS_PER_LONG)
- if (bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
- return 0;
-
- return 1;
-}
-EXPORT_SYMBOL(__bitmap_empty);
-
-int __bitmap_full(const unsigned long *bitmap, unsigned int bits)
-{
- unsigned int k, lim = bits/BITS_PER_LONG;
- for (k = 0; k < lim; ++k)
- if (~bitmap[k])
- return 0;
-
- if (bits % BITS_PER_LONG)
- if (~bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
- return 0;
-
- return 1;
-}
-EXPORT_SYMBOL(__bitmap_full);
-
int __bitmap_equal(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
{
--
2.1.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] lib: bitmap_[empty,full]: remove code duplication
2015-03-16 17:56 [PATCH] lib: bitmap_[empty,full]: remove code duplication Yury Norov
@ 2015-03-24 22:53 ` Andrew Morton
2015-03-29 2:03 ` [PATCH v2] " Yury Norov
1 sibling, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2015-03-24 22:53 UTC (permalink / raw)
To: Yury Norov; +Cc: linux, klimov.linux, linux, linux-kernel
On Mon, 16 Mar 2015 20:56:39 +0300 Yury Norov <yury.norov@gmail.com> wrote:
> Function 'bitmap_empty' has it's own implementation.
> But it's clearly as simple as:
> "find_first_bit(src, nbits) == nbits"
> The same is true for 'bitmap_full'.
>
> Underscored versions of 'bitmap_[empty,full]' are not
> needed anymore and so removed too.
>
> Boot-tested on Core i7-2630QM.
>
> --- a/include/linux/bitmap.h
> +++ b/include/linux/bitmap.h
> @@ -285,18 +285,12 @@ static inline int bitmap_subset(const unsigned long *src1,
>
> static inline int bitmap_empty(const unsigned long *src, unsigned nbits)
> {
> - if (small_const_nbits(nbits))
> - return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
> - else
> - return __bitmap_empty(src, nbits);
> + return find_first_bit(src, nbits) == nbits;
> }
But we lost the small_const_nbits() optimization, and that will be a
common case.
Would it be better to do
if (small_const_nbits(...))
...
else
find_first_bit(...);
?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] lib: bitmap_[empty,full]: remove code duplication
2015-03-16 17:56 [PATCH] lib: bitmap_[empty,full]: remove code duplication Yury Norov
2015-03-24 22:53 ` Andrew Morton
@ 2015-03-29 2:03 ` Yury Norov
2015-03-31 23:06 ` Andrew Morton
1 sibling, 1 reply; 5+ messages in thread
From: Yury Norov @ 2015-03-29 2:03 UTC (permalink / raw)
To: linux, klimov.linux, linux, akpm; +Cc: yury.norov, linux-kernel
Function 'bitmap_empty' has it's own implementation.
But it's clearly as simple as:
"find_first_bit(src, nbits) == nbits"
The same is true for 'bitmap_full'.
---
include/linux/bitmap.h | 8 ++++----
lib/bitmap.c | 30 ------------------------------
2 files changed, 4 insertions(+), 34 deletions(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index be4fa5d..ea17cca 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -283,16 +283,16 @@ static inline int bitmap_empty(const unsigned long *src, unsigned nbits)
{
if (small_const_nbits(nbits))
return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
- else
- return __bitmap_empty(src, nbits);
+
+ return find_first_bit(src, nbits) == nbits;
}
static inline int bitmap_full(const unsigned long *src, unsigned int nbits)
{
if (small_const_nbits(nbits))
return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
- else
- return __bitmap_full(src, nbits);
+
+ return find_first_zero_bit(src, nbits) == nbits;
}
static inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
diff --git a/lib/bitmap.c b/lib/bitmap.c
index d456f4c1..64c0926 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -42,36 +42,6 @@
* for the best explanations of this ordering.
*/
-int __bitmap_empty(const unsigned long *bitmap, unsigned int bits)
-{
- unsigned int k, lim = bits/BITS_PER_LONG;
- for (k = 0; k < lim; ++k)
- if (bitmap[k])
- return 0;
-
- if (bits % BITS_PER_LONG)
- if (bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
- return 0;
-
- return 1;
-}
-EXPORT_SYMBOL(__bitmap_empty);
-
-int __bitmap_full(const unsigned long *bitmap, unsigned int bits)
-{
- unsigned int k, lim = bits/BITS_PER_LONG;
- for (k = 0; k < lim; ++k)
- if (~bitmap[k])
- return 0;
-
- if (bits % BITS_PER_LONG)
- if (~bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
- return 0;
-
- return 1;
-}
-EXPORT_SYMBOL(__bitmap_full);
-
int __bitmap_equal(const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
{
--
2.1.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] lib: bitmap_[empty,full]: remove code duplication
2015-03-29 2:03 ` [PATCH v2] " Yury Norov
@ 2015-03-31 23:06 ` Andrew Morton
2015-04-01 3:01 ` Yury
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2015-03-31 23:06 UTC (permalink / raw)
To: Yury Norov; +Cc: linux, klimov.linux, linux, linux-kernel
On Sun, 29 Mar 2015 05:03:55 +0300 Yury Norov <yury.norov@gmail.com> wrote:
> Function 'bitmap_empty' has it's own implementation.
> But it's clearly as simple as:
> "find_first_bit(src, nbits) == nbits"
> The same is true for 'bitmap_full'.
Looks OK.
Please send a Signed-off-by: for this patch.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] lib: bitmap_[empty,full]: remove code duplication
2015-03-31 23:06 ` Andrew Morton
@ 2015-04-01 3:01 ` Yury
0 siblings, 0 replies; 5+ messages in thread
From: Yury @ 2015-04-01 3:01 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux, klimov.linux, linux, linux-kernel
On 01.04.2015 02:06, Andrew Morton wrote:
> On Sun, 29 Mar 2015 05:03:55 +0300 Yury Norov <yury.norov@gmail.com> wrote:
>
>> Function 'bitmap_empty' has it's own implementation.
>> But it's clearly as simple as:
>> "find_first_bit(src, nbits) == nbits"
>> The same is true for 'bitmap_full'.
> Looks OK.
>
> Please send a Signed-off-by: for this patch.
Hello Andrew,
Is it enough?
Signed-off-by: Yury Norov <yury.norov@gmail.com>
BR,
Yury Norov
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-04-01 3:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-16 17:56 [PATCH] lib: bitmap_[empty,full]: remove code duplication Yury Norov
2015-03-24 22:53 ` Andrew Morton
2015-03-29 2:03 ` [PATCH v2] " Yury Norov
2015-03-31 23:06 ` Andrew Morton
2015-04-01 3:01 ` Yury
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).