Received: from eggs.gnu.org ([2001:4830:134:3::10]:46784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bk65Y-0002Ib-9P for qemu-devel@nongnu.org; Wed, 14 Sep 2016 05:02:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bk65U-0007nq-6Z for qemu-devel@nongnu.org; Wed, 14 Sep 2016 05:02:40 -0400 Sender: Paolo Bonzini References: <1457185628-23304-1-git-send-email-richard.weiyang@gmail.com> From: Paolo Bonzini Message-ID: <7028e33b-fe71-098b-71d9-7e31ae71c6ec@redhat.com> Date: Wed, 14 Sep 2016 11:01:31 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1251 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Tokarev , Wei Yang , corentincj@iksaif.net Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org 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 >> --- >> 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); >> > > >