[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: likely/unlikely macro.
Thank you for your reply.
So, for example, the expression "if (likely(prev != next))" is same as "if
((prev != next) == 1)", isn't it?
Then, unlikely is opposite of that.
Now the things came to be clearer, thanks.
And I'm sorry for my HTML mail. I didn't notice that because I used my
provider's html mail site to send the mail from remote with http access.
I'll care it next time.
Thanks,
Shinpei Kato
On Thu, 04 Dec 2003 11:15:51 +0300
"Ruslan U. Zakirov" <cubic@wildgate.miee.ru> wrote:
> > shinny@j02.itscom.net wrote:
>
> >Hi,
> >
> >How may I ask for your help?
> >Now I'm studying the linux scheduler(sched.c).
> >And I'm wondering what likey()/unlikely macros mean.
> >I could find they're defined in linux/compiler.h as follows.
> >
> >/*
> > * Generic compiler-dependent macros required for kernel
> > * build go below this comment. Actual compiler/compiler version
> > * specific implementations come from the above header files
> > */
> >
> >#define likely(x) __builtin_expect(!!(x), 1)
> >#define unlikely(x) __builtin_expect(!!(x), 0)
> >
> >And I could find __builtin_expect()'s definition only in linux/compiler-gcc2.h as a follow.
> >I don't know what's going if __GNUC_MINOR__ is over 96, though...
> >
> >#if __GNUC_MINOR__ < 96
> ># define __builtin_expect(x, expected_value) (x)
> >#endif
> >
> >As a result, although it seems likely() and unlikely() do nothing, is my expectation correct?
> >If there are other references about this, please let me know.
> >
> >
> Hello.
> As I've understand gcc after 96 introduced new feature which helps
> programmer suggest
> to compiler wishful execution branch of code. Compiler use this build in
> for optimizing.
> Gcc docs:
> long *__builtin_expect*/ /(/long /exp/, long /c)/ / Built-in Function
>
> You may use |__builtin_expect| to provide the compiler with branch
> prediction information. In general, you should prefer to use actual
> profile feedback for this (|-fprofile-arcs|), as programmers are
> notoriously bad at predicting how their programs actually perform.
> However, there are applications in which this data is hard to collect.
>
> The return value is the value of exp, which should be an integral
> expression. The value of c must be a compile-time constant. The
> semantics of the built-in are that it is expected that exp == c. For
> example:
>
> if (__builtin_expect (x, 0))
> foo ();
>
>
> would indicate that we do not expect to call |foo|, since we expect |x|
> to be zero. Since you are limited to integral expressions for exp, you
> should use constructions such as
>
> if (__builtin_expect (ptr != NULL, 1))
> error ();
>
>
> when testing pointer or floating-point values.
>
> Good luck. Ruslan.
> PS: Don't send html letters in future.
>
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive: http://mail.nl.linux.org/kernelnewbies/
> FAQ: http://kernelnewbies.org/faq/
>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/