[FFmpeg-devel] [PATCH] Faster ff_sqrt()

Michael Niedermayer michaelni
Mon Jan 14 00:58:51 CET 2008


On Sun, Jan 13, 2008 at 09:14:10PM +0100, Michael Niedermayer wrote:
> On Sun, Jan 13, 2008 at 08:49:17PM +0100, Michael Niedermayer wrote:
[...]
> next one, just reordering the if() to make smaller values faster and some
> cosmetics
> 
> static inline unsigned int sqrt3(unsigned int a)
> {
>     unsigned int b;
> 
>     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 if(a<(1<<16)   ) b=sqrt_tab[ a    >>8 ]   ;
>     else{
>         int s= av_log2(a)>>1;
>         b= sqrt_tab[a>>(2*s-6)];
>         b= (FASTDIV(a,b)>>(s-6)) + (b<<(s-8));
>     }
> 
>     return b - (a<b*b);
> }

another minor revission (just av_log2 -> av_log2_16bit)

static inline unsigned int sqrt3(unsigned int a)
{
    unsigned int b;

    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 if(a<(1<<16)   ) b= sqrt_tab[ a    >>8 ]   ;
    else{
        int s= av_log2_16bit(a>>16)>>1;
        b= sqrt_tab[a>>(2*s+10)];
        b= (FASTDIV(a,b)>>(s+2)) + (b<<s);
    }

    return b - (a<b*b);
}

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No snowflake in an avalanche ever feels responsible. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080114/a016514a/attachment.pgp>



More information about the ffmpeg-devel mailing list