* [Qemu-devel] [PATCH] bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK
@ 2016-03-05 13:47 Wei Yang
2016-09-14 7:33 ` Michael Tokarev
2016-09-29 16:11 ` Michael Tokarev
0 siblings, 2 replies; 5+ messages in thread
From: Wei Yang @ 2016-03-05 13:47 UTC (permalink / raw)
To: corentincj; +Cc: qemu-trivial, qemu-devel, Wei Yang
According to linux kernel commit <89c1e79eb30> ("linux/bitmap.h: improve
BITMAP_{LAST,FIRST}_WORD_MASK"), these two macro could be improved.
This patch takes this change and also move them all in header file.
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
include/qemu/bitmap.h | 7 ++-----
util/bitmap.c | 2 --
2 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
index 0e33fa5..864982d 100644
--- a/include/qemu/bitmap.h
+++ b/include/qemu/bitmap.h
@@ -58,11 +58,8 @@
* find_next_bit(addr, nbits, bit) Position next set bit in *addr >= bit
*/
-#define BITMAP_LAST_WORD_MASK(nbits) \
- ( \
- ((nbits) % BITS_PER_LONG) ? \
- (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \
- )
+#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
+#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
#define DECLARE_BITMAP(name,bits) \
unsigned long name[BITS_TO_LONGS(bits)]
diff --git a/util/bitmap.c b/util/bitmap.c
index 40aadfb..43ed011 100644
--- a/util/bitmap.c
+++ b/util/bitmap.c
@@ -157,8 +157,6 @@ int slow_bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
return result != 0;
}
-#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
-
void bitmap_set(unsigned long *map, long start, long nr)
{
unsigned long *p = map + BIT_WORD(start);
--
2.5.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK
2016-03-05 13:47 [Qemu-devel] [PATCH] bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK Wei Yang
@ 2016-09-14 7:33 ` Michael Tokarev
2016-09-14 9:01 ` Paolo Bonzini
2016-09-29 16:11 ` Michael Tokarev
1 sibling, 1 reply; 5+ messages in thread
From: Michael Tokarev @ 2016-09-14 7:33 UTC (permalink / raw)
To: Wei Yang, corentincj; +Cc: qemu-trivial, qemu-devel
Is this (quite old) patch still relevant?
Thanks,
/mjt
05.03.2016 16:47, Wei Yang wrote:
> According to linux kernel commit <89c1e79eb30> ("linux/bitmap.h: improve
> BITMAP_{LAST,FIRST}_WORD_MASK"), these two macro could be improved.
>
> This patch takes this change and also move them all in header file.
>
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> ---
> include/qemu/bitmap.h | 7 ++-----
> util/bitmap.c | 2 --
> 2 files changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
> index 0e33fa5..864982d 100644
> --- a/include/qemu/bitmap.h
> +++ b/include/qemu/bitmap.h
> @@ -58,11 +58,8 @@
> * find_next_bit(addr, nbits, bit) Position next set bit in *addr >= bit
> */
>
> -#define BITMAP_LAST_WORD_MASK(nbits) \
> - ( \
> - ((nbits) % BITS_PER_LONG) ? \
> - (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \
> - )
> +#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
> +#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
>
> #define DECLARE_BITMAP(name,bits) \
> unsigned long name[BITS_TO_LONGS(bits)]
> diff --git a/util/bitmap.c b/util/bitmap.c
> index 40aadfb..43ed011 100644
> --- a/util/bitmap.c
> +++ b/util/bitmap.c
> @@ -157,8 +157,6 @@ int slow_bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
> return result != 0;
> }
>
> -#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
> -
> void bitmap_set(unsigned long *map, long start, long nr)
> {
> unsigned long *p = map + BIT_WORD(start);
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK
2016-09-14 7:33 ` Michael Tokarev
@ 2016-09-14 9:01 ` Paolo Bonzini
0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2016-09-14 9:01 UTC (permalink / raw)
To: Michael Tokarev, Wei Yang, corentincj; +Cc: qemu-trivial, qemu-devel
On 14/09/2016 09:33, Michael Tokarev wrote:
> Is this (quite old) patch still relevant?
Yes, I think it's a nice cleanup. The interesting bit is that it
expands nbits exactly once.
Paolo
> Thanks,
>
> /mjt
>
> 05.03.2016 16:47, Wei Yang wrote:
>> According to linux kernel commit <89c1e79eb30> ("linux/bitmap.h: improve
>> BITMAP_{LAST,FIRST}_WORD_MASK"), these two macro could be improved.
>>
>> This patch takes this change and also move them all in header file.
>>
>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>> ---
>> include/qemu/bitmap.h | 7 ++-----
>> util/bitmap.c | 2 --
>> 2 files changed, 2 insertions(+), 7 deletions(-)
>>
>> diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
>> index 0e33fa5..864982d 100644
>> --- a/include/qemu/bitmap.h
>> +++ b/include/qemu/bitmap.h
>> @@ -58,11 +58,8 @@
>> * find_next_bit(addr, nbits, bit) Position next set bit in *addr
>> >= bit
>> */
>>
>> -#define
>> BITMAP_LAST_WORD_MASK(nbits) \
>> -
>> ( \
>> - ((nbits) % BITS_PER_LONG)
>> ? \
>> - (1UL<<((nbits) % BITS_PER_LONG))-1 :
>> ~0UL \
>> - )
>> +#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) &
>> (BITS_PER_LONG - 1)))
>> +#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) &
>> (BITS_PER_LONG - 1)))
>>
>> #define DECLARE_BITMAP(name,bits) \
>> unsigned long name[BITS_TO_LONGS(bits)]
>> diff --git a/util/bitmap.c b/util/bitmap.c
>> index 40aadfb..43ed011 100644
>> --- a/util/bitmap.c
>> +++ b/util/bitmap.c
>> @@ -157,8 +157,6 @@ int slow_bitmap_andnot(unsigned long *dst, const
>> unsigned long *bitmap1,
>> return result != 0;
>> }
>>
>> -#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) %
>> BITS_PER_LONG))
>> -
>> void bitmap_set(unsigned long *map, long start, long nr)
>> {
>> unsigned long *p = map + BIT_WORD(start);
>>
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK
2016-03-05 13:47 [Qemu-devel] [PATCH] bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK Wei Yang
2016-09-14 7:33 ` Michael Tokarev
@ 2016-09-29 16:11 ` Michael Tokarev
2016-09-29 22:47 ` Wei Yang
1 sibling, 1 reply; 5+ messages in thread
From: Michael Tokarev @ 2016-09-29 16:11 UTC (permalink / raw)
To: Wei Yang, corentincj; +Cc: qemu-trivial, qemu-devel
05.03.2016 16:47, Wei Yang wrote:
> According to linux kernel commit <89c1e79eb30> ("linux/bitmap.h: improve
> BITMAP_{LAST,FIRST}_WORD_MASK"), these two macro could be improved.
>
> This patch takes this change and also move them all in header file.
Applied to -trivial, thank you!
/mjt
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK
2016-09-29 16:11 ` Michael Tokarev
@ 2016-09-29 22:47 ` Wei Yang
0 siblings, 0 replies; 5+ messages in thread
From: Wei Yang @ 2016-09-29 22:47 UTC (permalink / raw)
To: Michael Tokarev; +Cc: Wei Yang, corentincj, qemu-trivial, qemu-devel
On Thu, Sep 29, 2016 at 07:11:39PM +0300, Michael Tokarev wrote:
>05.03.2016 16:47, Wei Yang wrote:
>>According to linux kernel commit <89c1e79eb30> ("linux/bitmap.h: improve
>>BITMAP_{LAST,FIRST}_WORD_MASK"), these two macro could be improved.
>>
>>This patch takes this change and also move them all in header file.
>
>Applied to -trivial, thank you!
>
Thanks :-) Have a good day~
>/mjt
--
Wei Yang
Help you, Help me
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-09-29 22:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-05 13:47 [Qemu-devel] [PATCH] bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK Wei Yang
2016-09-14 7:33 ` Michael Tokarev
2016-09-14 9:01 ` Paolo Bonzini
2016-09-29 16:11 ` Michael Tokarev
2016-09-29 22:47 ` Wei Yang
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.