[FFmpeg-devel] [PATCH] Add "cold" attribute to init/uninit functions in libavcodec

Ramiro Polla ramiro
Wed Mar 19 15:12:44 CET 2008


Hello,

Zuxy Meng wrote:
> Hi,
> 
> GCC 4.3.0 adds a new attributes called "cold":
> 
> "The cold attribute is used to inform the compiler that a function is
> unlikely executed. The function is optimized for size rather than
> speed and on many targets it is placed into special subsection of the
> text section so all cold functions appears close together improving
> code locality of non-cold parts of program. The paths leading to call
> of cold functions within code are marked as unlikely by the branch
> prediction mechanism. It is thus useful to mark functions used to
> handle unlikely conditions, such as perror, as cold to improve
> optimization of hot functions that do call marked functions in rare
> occasions.
> 
> "When profile feedback is available, via -fprofile-use, hot(sic)
> functions are automatically detected and this attribute is ignored.
> 
> "The hot(ditto) attribute is not implemented in GCC versions earlier than 4.3."

While you're at it, why don't you take a look at the (un)likely macros 
the linux kernel uses?
It's stuff like:
(under gcc)
#define likely(x)       __builtin_expect(!!(x), 1)
#define unlikely(x)     __builtin_expect(!!(x), 0)

that could be used in some speed critical places where we know more than 
gcc about the probability of a condition.

Is this welcome in FFmpeg?

Ramiro Polla




More information about the ffmpeg-devel mailing list