[FFmpeg-devel] [PATCH] simplify GET_UTF8 to use ff_log2_tab

Rich Felker dalias
Sun Dec 9 23:14:23 CET 2007


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.

For an implementation based on this and much more optimal than the
current one in ffmpeg, read my libc sources,

http://svn.mplayerhq.hu/libc/trunk/stdc/mbc/__mbrtowc.c

(It looks a lot more complex than it is because it maintains state
across calls and supports resuming mid-character. If you eliminate
this it becomes rather trivial. In either case it's near-optimal.)

Rich




More information about the ffmpeg-devel mailing list