[FFmpeg-devel] [RFC] "Likely" and "Unlikely" macros

Måns Rullgård mans
Tue Oct 7 23:54:25 CEST 2008

"Jason Garrett-Glaser" <darkshikari at gmail.com> writes:

> On Tue, Oct 7, 2008 at 2:07 PM, Ramiro Polla <ramiro.polla at gmail.com> wrote:
>> On Tue, Oct 7, 2008 at 6:03 PM, Jason Garrett-Glaser
>> <darkshikari at gmail.com> wrote:
>>> The following macros seem to provide great benefit in some critical
>>> code sections, such as decode_cabac_residual, where I've shaved off a
>>> few clocks experimenting with them:
>>> #define likely(x) __builtin_expect((x),1)
>>> #define unlikely(x) __builtin_expect((x),0)
>>> This is probably due to gcc knowing which side of each if
>>> statement to inline.
>>> Is there any objection to using these in various critical code
>>> sections in ffmpeg?
>> http://article.gmane.org/gmane.comp.video.ffmpeg.devel/65056
>> I just don't know the internals enough to try and shave cycles out of
>> critical sections =)
> Indeed, it seems I wasn't the first to consider this.
> I'll return with a patch in a bit, and let Michael decide where the
> macros should go.

You should add a proper prefix (ff_ or av_) to the names, and define
them conditionally.  I don't know when they first appeared in gcc,
probably some time during 3.x.

M?ns Rullg?rd
mans at mansr.com

More information about the ffmpeg-devel mailing list