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

Michael Niedermayer michaelni
Wed Mar 19 15:49:05 CET 2008


On Wed, Mar 19, 2008 at 09:35:43PM +0800, 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."
> 
> As suggested by Michael, this attribute may be nice for init/uninit
> like functions in libav*. The attached patch is a first step, applying
> this attribute to all functions that are either assigned as init or
> close functions of a AVCodec object, or called exclusively by such
> functions. I'll deal with DSP stuff later.
> 
> Please take a look to make sure that I didn't add something wrong or miss any.
> 
> Thanks!
> 
> BTW: This time I'm sure it won't break builds (again).

What effect does this patch has on binary size? It should become smaller ...

[...]

> -static int smka_decode_init(AVCodecContext *avctx)
> +static av_cold int smka_decode_init(AVCodecContext *avctx)
>  {
>      return 0;
>  }

this function isnt needed at all

rest looks ok

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Let us carefully observe those good qualities wherein our enemies excel us
and endeavor to excel them, by avoiding what is faulty, and imitating what
is excellent in them. -- Plutarch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080319/faefdc11/attachment.pgp>



More information about the ffmpeg-devel mailing list