Mercurial > libavutil.hg
diff internal.h @ 432:dcb08e8f3b2e libavutil
Faster ff_sqrt()
author | michael |
---|---|
date | Mon, 21 Jan 2008 13:33:18 +0000 |
parents | fa6c031f2a57 |
children | 62530c1673a0 |
line wrap: on
line diff
--- a/internal.h Thu Jan 17 08:32:31 2008 +0000 +++ b/internal.h Mon Jan 21 13:33:18 2008 +0000 @@ -178,24 +178,28 @@ # define FASTDIV(a,b) ((a)/(b)) #endif -extern const uint8_t ff_sqrt_tab[128]; +extern const uint8_t ff_sqrt_tab[256]; -static inline int ff_sqrt(int a) +static inline int av_log2_16bit(unsigned int v); + +static inline unsigned int ff_sqrt(unsigned int a) { - int ret=0; - int s, b; - - if(a<128) return ff_sqrt_tab[a]; + unsigned int b; - for(s=30; s>=0; s-=2){ - ret+=ret; - b= (1+2*ret)<<s; - if(b<=a){ - a-=b; - ret++; - } + if(a<255) return (ff_sqrt_tab[a+1]-1)>>4; + else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2; +#ifndef CONFIG_SMALL + else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1; + else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ] ; +#endif + else{ + int s= av_log2_16bit(a>>16)>>1; + unsigned int c= a>>(s+2); + b= ff_sqrt_tab[c>>(s+8)]; + b= FASTDIV(c,b) + (b<<s); } - return ret; + + return b - (a<b*b); } #if defined(ARCH_X86)