All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: Wei Wang <wei.w.wang@intel.com>
Cc: qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com,
	mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/2] bitmap.h: add comments to BITMAP_LAST_WORD_MASK
Date: Mon, 30 Jul 2018 15:19:30 +0200	[thread overview]
Message-ID: <87zhy8kgil.fsf@trasno.org> (raw)
In-Reply-To: <5B5EC604.4020301@intel.com> (Wei Wang's message of "Mon, 30 Jul 2018 16:02:12 +0800")

Wei Wang <wei.w.wang@intel.com> wrote:
> On 07/30/2018 03:13 PM, Wei Wang wrote:
>> This macro was ported from Linux and we've reached an aggreement there
>> that the corner case "nbits = 0" is not applicable to this macro, because
>> when "nbits = 0", which means no bits to mask, this macro is expected to
>> return 0, instead of 0xffffffff. This patch simply adds a comment above
>> the macro as a note to users about the corner case.
>>
>> Signed-off-by: Wei Wang <wei.w.wang@intel.com>
>> CC: Dr. David Alan Gilbert <dgilbert@redhat.com>
>> CC: Juan Quintela <quintela@redhat.com>
>> CC: Peter Xu <peterx@redhat.com>
>> ---
>>   include/qemu/bitmap.h | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
>> index 509eedd..f53c640 100644
>> --- a/include/qemu/bitmap.h
>> +++ b/include/qemu/bitmap.h
>> @@ -60,6 +60,7 @@
>>    */
>>     #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) &
>> (BITS_PER_LONG - 1)))
>> +/* "nbits = 0" is not applicable to this macro. Callers should avoid that. */
>>   #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
>>     #define DECLARE_BITMAP(name,bits)                  \
>
> A better fix would be to directly change the macro to:  nbits ? (~0UL
>>> (-(nbits) & (BITS_PER_LONG - 1))) : 0,
> so that we don't need to fix other callers like bitmap_full,
> bitmap_intersects.
>
> So just post this out for a discussion whether it's preferred to just
> adding note comments as we did for linux or fixing the macro directly.
>
> Best,
> Wei

On one hand:
a - we have copied it form linux, we don't want to diverge
On the other hand:
b - it is much easier to use if we change the macro

So, it is a tought one.

I slightly preffer b), but will not object to a either.  As you are the
one doing the patch, your choice.

Later, Juan.

  reply	other threads:[~2018-07-30 13:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-30  7:13 [Qemu-devel] [PATCH 0/2] bitmap: some fixes Wei Wang
2018-07-30  7:13 ` [Qemu-devel] [PATCH 1/2] bitmap.h: add comments to BITMAP_LAST_WORD_MASK Wei Wang
2018-07-30  8:02   ` Wei Wang
2018-07-30 13:19     ` Juan Quintela [this message]
2018-07-31  9:06       ` Wei Wang
2018-07-30  7:13 ` [Qemu-devel] [PATCH 2/2] bitmap: fix bitmap_count_one Wei Wang

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=87zhy8kgil.fsf@trasno.org \
    --to=quintela@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=mst@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wei.w.wang@intel.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.