qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/5] BIT_RANGE convenience macro


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH 1/5] BIT_RANGE convenience macro
Date: Thu, 16 Jun 2016 20:05:03 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0


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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]