All of lore.kernel.org
 help / color / mirror / Atom feed
* Re Likely and Unlikely Macro
@ 2011-10-10  6:19 Asutosh Das
  2011-10-10  7:29 ` bob
  2011-10-10 15:52 ` Mulyadi Santosa
  0 siblings, 2 replies; 5+ messages in thread
From: Asutosh Das @ 2011-10-10  6:19 UTC (permalink / raw)
  To: kernelnewbies

Hi
In lxr, I saw the likely and unlikely macro defined as (compiler.h)

#  define likely(x)     (__builtin_constant_p(x) ? !!(x) :
__branch_check__(x, 1))
 116# endif
 117# ifndef unlikely
 118#  define unlikely(x)   (__builtin_constant_p(x) ? !!(x) :
__branch_check__(x, 0))
 119# endif
 120
..... some other defines

#else
 146# define likely(x)      __builtin_expect(!!(x), 1)
 147# define unlikely(x)    __builtin_expect(!!(x), 0)
 148#endif

I cannot understand the intention behind !!(x).
Please can you let me know why !!(x) is required here.

TIA
--
~/asd

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re Likely and Unlikely Macro
  2011-10-10  6:19 Re Likely and Unlikely Macro Asutosh Das
@ 2011-10-10  7:29 ` bob
  2011-10-10 15:52 ` Mulyadi Santosa
  1 sibling, 0 replies; 5+ messages in thread
From: bob @ 2011-10-10  7:29 UTC (permalink / raw)
  To: kernelnewbies

It's a shorter way of casting a pointer to an integer with boolean
values. 

On Mon, Oct 10, 2011 at 11:49:54AM +0530, Asutosh Das wrote:
> Hi
> In lxr, I saw the likely and unlikely macro defined as (compiler.h)
> 
> #  define likely(x)     (__builtin_constant_p(x) ? !!(x) :
> __branch_check__(x, 1))
>  116# endif
>  117# ifndef unlikely
>  118#  define unlikely(x)   (__builtin_constant_p(x) ? !!(x) :
> __branch_check__(x, 0))
>  119# endif
>  120
> ..... some other defines
> 
> #else
>  146# define likely(x)      __builtin_expect(!!(x), 1)
>  147# define unlikely(x)    __builtin_expect(!!(x), 0)
>  148#endif
> 
> I cannot understand the intention behind !!(x).
> Please can you let me know why !!(x) is required here.
> 
> TIA
> --
> ~/asd
> 
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re Likely and Unlikely Macro
  2011-10-10  6:19 Re Likely and Unlikely Macro Asutosh Das
  2011-10-10  7:29 ` bob
@ 2011-10-10 15:52 ` Mulyadi Santosa
  2011-10-11  4:18   ` Asutosh Das
  1 sibling, 1 reply; 5+ messages in thread
From: Mulyadi Santosa @ 2011-10-10 15:52 UTC (permalink / raw)
  To: kernelnewbies

Hi :)

On Mon, Oct 10, 2011 at 13:19, Asutosh Das <das.asutosh@gmail.com> wrote:
> I cannot understand the intention behind !!(x).
> Please can you let me know why !!(x) is required here.

Assume x is 100, so !x is 0, right? Further !!x is ! ( !x), correct?
Then we have ! (0) which is 1.

Thus, it's quick practical way to make any value to be just 0 or 1,
"true" or "false"

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re Likely and Unlikely Macro
  2011-10-10 15:52 ` Mulyadi Santosa
@ 2011-10-11  4:18   ` Asutosh Das
  2011-10-12  4:36     ` pankaj singh
  0 siblings, 1 reply; 5+ messages in thread
From: Asutosh Das @ 2011-10-11  4:18 UTC (permalink / raw)
  To: kernelnewbies

Gottcha ... Thanks guys :)

On 10 October 2011 21:22, Mulyadi Santosa <mulyadi.santosa@gmail.com> wrote:
> Hi :)
>
> On Mon, Oct 10, 2011 at 13:19, Asutosh Das <das.asutosh@gmail.com> wrote:
>> I cannot understand the intention behind !!(x).
>> Please can you let me know why !!(x) is required here.
>
> Assume x is 100, so !x is 0, right? Further !!x is ! ( !x), correct?
> Then we have ! (0) which is 1.
>
> Thus, it's quick practical way to make any value to be just 0 or 1,
> "true" or "false"
>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>



-- 
Thank you,
Warm Regards,
Asutosh Das
# (91) 9049 000 969

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re Likely and Unlikely Macro
  2011-10-11  4:18   ` Asutosh Das
@ 2011-10-12  4:36     ` pankaj singh
  0 siblings, 0 replies; 5+ messages in thread
From: pankaj singh @ 2011-10-12  4:36 UTC (permalink / raw)
  To: kernelnewbies

Hi,

likely and unlikely macros are used to help branch prediction, which
in turn improve performance.
so the branch which is unlikely will not be predicted at the execution time.

one can refer to : Intel manual 248966

Thanks,
~Pankaj Singh

On Tue, Oct 11, 2011 at 9:48 AM, Asutosh Das <das.asutosh@gmail.com> wrote:
> Gottcha ... Thanks guys :)
>
> On 10 October 2011 21:22, Mulyadi Santosa <mulyadi.santosa@gmail.com> wrote:
>> Hi :)
>>
>> On Mon, Oct 10, 2011 at 13:19, Asutosh Das <das.asutosh@gmail.com> wrote:
>>> I cannot understand the intention behind !!(x).
>>> Please can you let me know why !!(x) is required here.
>>
>> Assume x is 100, so !x is 0, right? Further !!x is ! ( !x), correct?
>> Then we have ! (0) which is 1.
>>
>> Thus, it's quick practical way to make any value to be just 0 or 1,
>> "true" or "false"
>>
>> --
>> regards,
>>
>> Mulyadi Santosa
>> Freelance Linux trainer and consultant
>>
>> blog: the-hydra.blogspot.com
>> training: mulyaditraining.blogspot.com
>>
>
>
>
> --
> Thank you,
> Warm Regards,
> Asutosh Das
> # (91) 9049 000 969
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



-- 
Pankaj SIngh
Phone No: 9921865080

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-10-12  4:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-10  6:19 Re Likely and Unlikely Macro Asutosh Das
2011-10-10  7:29 ` bob
2011-10-10 15:52 ` Mulyadi Santosa
2011-10-11  4:18   ` Asutosh Das
2011-10-12  4:36     ` pankaj singh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.