[FFmpeg-devel] [PATCH] Faster ff_sqrt()
Vitor Sessak
vitor1001
Sun Jan 13 21:21:35 CET 2008
Hi
Michael Niedermayer wrote:
> On Sun, Jan 13, 2008 at 08:13:00PM +0100, Michael Niedermayer wrote:
>> On Sun, Jan 13, 2008 at 05:50:52PM +0100, Vitor Sessak wrote:
[...]
>> for a less idiotic and simpler variant i wrote a few years ago see
>> http://guru.multimedia.cx/fast-integer-square-root/
>>
>> if anyone can simplify this further that would be welcome :)
>
> noone? well heres a simpler variant, though possibly slower (didnt benchmark)
>
> static inline unsigned int sqrt4(unsigned int a)
> {
> unsigned int b;
>
> if(a<(1<<16)){
> if(a<(1<<10)-3) b=sqrt_tab[(a+ 3)>>2 ]>>3;
> else{
> if(a<(1<<14)-28) b=sqrt_tab[(a+28)>>6 ]>>1;
> else b=sqrt_tab[ a >>8 ];
> }
> }else{
> int s= (av_log2(a)-12)>>1;
> b= sqrt_tab[a>>(2*s+6)];
> b= (FASTDIV(a,b)>>s) + (b<<(s-2));
> }
>
> if(a<b*b) b--;
>
> return b;
> }
>
It is indeed simpler and slightly faster than the patch I proposed...
-Vitor
More information about the ffmpeg-devel
mailing list