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

Re: Unlikely and likely() functions....



On 1/5/06, charan raj <c.charan@xxxxxxxxx> wrote:
>
> I am new to this mailing list .....
>
> i just came across this  unlikely() and likely() function in kernel code (
> eg  .. unlikely() is used in fork.c )  , i don;t have any idea
> about what the above 2 functions does ......
>
> can anybody plz explain what the two functions all about .....
from info gcc:

,----
|  -- Built-in Function: long __builtin_expect (long EXP, long C)
|      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.
`----

kind regards
anupam
ž®w¥ì‰ëzZ^iÈh¶«•æ¦èºÛax¸§»®w¥·!Š÷¡¶Úþf¢–yeŠ{±¢¸?‘êçzYÞÁž³ñ@Bm§ÿäz¹Þw°n'¬¢¸?}ª¿