Re: [PATCH] slab.h: Avoid using & for logical and of booleans

From: Vlastimil Babka
Date: Fri Nov 09 2018 - 03:12:19 EST


On 11/7/18 11:41 AM, David Laight wrote:
> From: Vlastimil Babka
>> Sent: 06 November 2018 12:51
>>
>> On 11/6/18 12:07 PM, David Laight wrote:
>>> From: Vlastimil Babka [mailto:vbabka@xxxxxxx]
>>> 0000000000000020 <f1>:
>>> 20: 40 f6 c7 11 test $0x11,%dil
>>> 24: 75 03 jne 29 <f1+0x9>
>>> 26: 31 c0 xor %eax,%eax
>>> 28: c3 retq
>>> 29: 83 e7 01 and $0x1,%edi
>>> 2c: 83 ff 01 cmp $0x1,%edi
>>> 2f: 19 c0 sbb %eax,%eax
>>> 31: 83 c0 02 add $0x2,%eax
>>> 34: c3 retq
>>>
>>> The jne will be predicted not taken and the retq predicted.
>>> So this might only be 1 clock in the normal case.
>>
>> I think this is the winner. It's also a single branch and not two,
>> because the compiler could figure out some of the "clever arithmetics"
>> itself. Care to send a full patch?
>
> I've not got a suitable source tree lurking.
> So someone else would need to do it.
> I'll waive any copyright that could plausibly be assigned to the above!

There we go. This is to replace the current fix by Bart (sorry) which seems
to add an extra IMUL. Apparently current mainline is spamming anyone running
sparse with lots of warning, so it should be merged soon.

----8<----