comparison internal.h @ 432:dcb08e8f3b2e libavutil

Faster ff_sqrt()
author michael
date Mon, 21 Jan 2008 13:33:18 +0000
parents fa6c031f2a57
children 62530c1673a0
comparison
equal deleted inserted replaced
431:fa6c031f2a57 432:dcb08e8f3b2e
176 # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32)) 176 # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32))
177 #else 177 #else
178 # define FASTDIV(a,b) ((a)/(b)) 178 # define FASTDIV(a,b) ((a)/(b))
179 #endif 179 #endif
180 180
181 extern const uint8_t ff_sqrt_tab[128]; 181 extern const uint8_t ff_sqrt_tab[256];
182 182
183 static inline int ff_sqrt(int a) 183 static inline int av_log2_16bit(unsigned int v);
184 { 184
185 int ret=0; 185 static inline unsigned int ff_sqrt(unsigned int a)
186 int s, b; 186 {
187 187 unsigned int b;
188 if(a<128) return ff_sqrt_tab[a]; 188
189 189 if(a<255) return (ff_sqrt_tab[a+1]-1)>>4;
190 for(s=30; s>=0; s-=2){ 190 else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2;
191 ret+=ret; 191 #ifndef CONFIG_SMALL
192 b= (1+2*ret)<<s; 192 else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1;
193 if(b<=a){ 193 else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ] ;
194 a-=b; 194 #endif
195 ret++; 195 else{
196 } 196 int s= av_log2_16bit(a>>16)>>1;
197 unsigned int c= a>>(s+2);
198 b= ff_sqrt_tab[c>>(s+8)];
199 b= FASTDIV(c,b) + (b<<s);
197 } 200 }
198 return ret; 201
202 return b - (a<b*b);
199 } 203 }
200 204
201 #if defined(ARCH_X86) 205 #if defined(ARCH_X86)
202 #define MASK_ABS(mask, level)\ 206 #define MASK_ABS(mask, level)\
203 asm volatile(\ 207 asm volatile(\