lkml.org 
[lkml]   [2022]   [Aug]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 1/5] bitops: Introduce find_next_andnot_bit()
Date
On 16/08/22 15:13, Yury Norov wrote:
> On Tue, Aug 16, 2022 at 07:07:23PM +0100, Valentin Schneider wrote:
>> @@ -59,7 +63,9 @@ unsigned long _find_next_bit(const unsigned long *addr1,
>>
>> tmp = addr1[start / BITS_PER_LONG];
>> if (addr2)
>> - tmp &= addr2[start / BITS_PER_LONG];
>> + tmp &= negate ?
>> + ~addr2[start / BITS_PER_LONG] :
>> + addr2[start / BITS_PER_LONG];
>> tmp ^= invert;
>> }
>
> So it flips addr2 bits twice - first with new 'negate', and second
> with the existing 'invert'. There is no such combination in the
> existing code, but the pattern looks ugly, particularly because we use
> different inverting approaches. Because of that, and because XOR trick
> generates better code, I'd suggest something like this:
>
> tmp = addr1[start / BITS_PER_LONG] ^ invert1;
> if (addr2)
> tmp &= addr2[start / BITS_PER_LONG] ^ invert2;

That does look much better, and also gets rid of the ternary. Thanks!

\
 
 \ /
  Last update: 2022-08-17 12:11    [W:0.063 / U:0.732 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site