lkml.org 
[lkml]   [2014]   [Nov]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v3] bitops: Fix shift overflow in GENMASK macros

On 11/05/2014 05:44 PM, Peter Zijlstra wrote:
> On Wed, Nov 05, 2014 at 04:47:14PM +0100, Maxime Coquelin wrote:
>> On 11/05/2014 12:10 PM, Rasmus Villemoes wrote:
>>> On Tue, Nov 04 2014, Maxime COQUELIN <maxime.coquelin@st.com> wrote:
>>>
>>>> -#define GENMASK(h, l) (((U32_C(1) << ((h) - (l) + 1)) - 1) << (l))
>>>> -#define GENMASK_ULL(h, l) (((U64_C(1) << ((h) - (l) + 1)) - 1) << (l))
>>>> +#define GENMASK(h, l) \
>>>> + ((~0UL >> (BITS_PER_LONG - ((h) - (l) + 1))) << (l))
>>>> +
>>>> +#define GENMASK_ULL(h, l) \
>>>> + ((~0ULL >> (BITS_PER_LONG_LONG - ((h) - (l) + 1))) << (l))
>>> Slightly bikeshedding here, but may I suggest spelling it
>>>
>>> (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
>>>
>>> ? This will ensure the arguments are expanded once each, and will, IMHO,
>>> DTRT if/when l > h (namely, yield 0).
>> That's a good point.
>>
>> Peter, what is your view?
> I'm fine with that, feel free to post another version and I'll replace
> v3.

Thanks Peter, v4 just sent.

Regards,
Maxime


\
 
 \ /
  Last update: 2014-11-06 11:21    [W:0.049 / U:0.288 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site