[Ffmpeg-devel] privatizing FifoBuffer into libavutil -- take II

Rich Felker dalias
Thu Sep 21 03:38:16 CEST 2006


On Wed, Sep 20, 2006 at 06:16:31PM -0700, Roman Shaposhnick wrote:
> Hi
> 
> On Wed, 2006-09-20 at 11:07 +0200, Michael Niedermayer wrote:
> > >   Amazingly enough IT IS! In fact almost 2x times faster. Michael, how
> > > did you know ? Your version even contains the dreaded 'if' but it is
> > > still faster. 'idiv' is pretty inexpensive on Xeon so the only possible
> > > explanation I could come up with would be -- your code reduces register
> > > pressure as well. 
> > 
> > % is slow, if() is only slow if the "truthness" is unpredictable which
> > i guessed isnt the case here
> > a if(1) or a if((i++)&1) or such are very fast on modern cpus
> 
>   Yeap. Seems to be the case. I used to be pretty scared of if()'s but
> it seems that I have to reevaluate my attitude towards them.

IMO division and heavy memory access are the only operations that
should be considered "slower than conditional". Your attitude is
mostly right, it's just that division is very slow. :)

BTW this should be even faster:

ptr = f->rptr + offs;
ptr-= (f->end - f->buffer) & (s->end - ptr - 1 >> 8*sizeof(ptrdiff_t)-1);

Hopefully I didn't mess it up..

Rich





More information about the ffmpeg-devel mailing list