Re: Use and misuse of __builtin_expect

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

 



On 8/26/19 3:59 PM, Denis Efremov wrote:
> Hi,
> 
> Is it correct to use __builtin_expect these 2 ways?
> 
> #define likely(x)	__builtin_expect(!!(x), 1)
> #define unlikely(x)	__builtin_expect(!!(x), 0)
> 
> 1) Negation before likely/unlikely.
>    if (!unlikely(cond)) { ... }
>    if (!likely(cond)) { ... }
> 
> I've replaced all !unlikely to likely and vice versa in the Linux
> and obtained different binary results:
> 

Ah, this is incorrect. It's wrong to replace !unlikely to likely
and vice versa. The negation could not be dropped. It's possible
to replace !likely(x) with unlikely(!x).

> 
> 2) As a part of the condition.
>    if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) { ... }
>    if (unlikely(info->thread_notes == 0) || unlikely(view->regsets[0].core_note_type != NT_PRSTATUS)) { ... }
>    if (*s && unlikely(!d_can_lookup(root)) { ... }
> 
> Thanks,
> Denis
> 




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux