From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDbfc-0006HL-IX for qemu-devel@nongnu.org; Thu, 16 Jun 2016 14:05:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDbfY-00038i-Ra for qemu-devel@nongnu.org; Thu, 16 Jun 2016 14:05:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51022) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDbfY-00038d-IG for qemu-devel@nongnu.org; Thu, 16 Jun 2016 14:05:32 -0400 References: <1466097133-5489-1-git-send-email-dgilbert@redhat.com> <1466097133-5489-2-git-send-email-dgilbert@redhat.com> From: Paolo Bonzini Message-ID: Date: Thu, 16 Jun 2016 20:05:03 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/5] BIT_RANGE convenience macro List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , "Dr. David Alan Gilbert (git)" Cc: QEMU Developers , Andrea Arcangeli , Eduardo Habkost On 16/06/2016 20:01, Peter Maydell wrote: >> diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h >> index 755fdd1..e411688 100644 >> --- a/include/qemu/bitops.h >> +++ b/include/qemu/bitops.h >> @@ -23,6 +23,9 @@ >> #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) >> #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) >> #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) >> +/* e.g. BIT_RANGE(15, 0) -> 0xff00 */ >> +#define BIT_RANGE(hb, lb) ((2ull << (hb)) - (1ull << (lb))) > > Isn't this undefined behaviour if the hb is 63? No, these are unsigned values so there's no undefined behavior. > I prefer a "start, length" macro to "position, position", > because this matches what we already have for the deposit > and extract functions in this header. That's fine too, albeit in the case of this patch the code would be uglier. Also, if you want a "start, length" mask you could always deposit -1 into 0... Paolo