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

Måns Rullgård mans
Mon Dec 10 22:09:37 CET 2007


"Ivan Kalvachev" <ikalvachev at gmail.com> writes:

> 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.

What the hell is wrong with that architecture?  On ARM, the CLZ (count
leading zeros) instruction takes all of ONE cycle.  I believe MIPS is
similar.

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list