[FFmpeg-devel] [PATCH] Optimisations for av_log2 and integer clip functions

Måns Rullgård mans
Wed Jan 13 23:10:30 CET 2010


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

>> +#define av_log2 av_log2
>> +static inline av_const int av_log2(unsigned int v)
>> +{
>> + ? ?return v? 31 - __builtin_clz(v) : 0;
>> +}
>> +
>> +#ifndef av_log2_16bit
>> +#define av_log2_16bit av_log2
>> +#endif
>
> Won't ^31 be faster?  "31 - X" requires an extra mov on x86.

Maybe.  The subtraction might play nicer with the way it's used in
e.g. golomb.h.  I'd be surprised if gcc could figure out such bit
magic by itself.

> Also, __builtin_clz/ctz maps to bsr/bsf, which are extraordinarily
> slow on Athlons.

Fabulous.  So what shall we do?  List the CPUs with good clz support
in configure like we do with cmov et al?

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



More information about the ffmpeg-devel mailing list