[FFmpeg-devel] [PATCH] simplify GET_UTF8 to use ff_log2_tab
Rich Felker
dalias
Tue Dec 11 05:45:50 CET 2007
On Mon, Dec 10, 2007 at 10:13:42PM +0200, Ivan Kalvachev wrote:
> On Dec 10, 2007 12:14 AM, Rich Felker <dalias at aerifal.cx> wrote:
> > On Sun, Dec 09, 2007 at 11:09:25AM +0100, Reimar D?ffinger wrote:
> >
> > > Hello,
> > > currently GET_UTF8 calls av_log2 which is simply overkill,
> > > since we only care about the lowest 8 bits.
> > > This may be intentional since my suggestion would be problematic
> > > if GET_UTF8 should become part of the public API, since ff_log2_tab
> > > is not public.
> > > A possibility would be to at least use av_log2_16bit or better add a
> > > public av_log2_8bit.
> > > Comments?
> >
> > Counting the number of ones is useless. Instead, just left shift at
> > each iteration and check the high bit as your "loop counter".
> > Thankfully gcc even optimizes this correctly as (shl ; js) on i386,
> > even in my ancient gcc 2.95.
>
> Ever heard of "bsr" and "bsf" instructions?
> I think BitScanReverse have huge latency (i386=10+3*n, P1=72, Athlon=14),
> but it still should be faster than loop or cache miss.
You missed the point entirely. The only reason this log2 nonsense is
used is to get a number of iterations for a loop. Instead just use the
bits as a loop counter as-is, using i<<=1 instead of i-- as the
increment mechanism.
Rich
More information about the ffmpeg-devel
mailing list