comparison common.h @ 609:153a7ffd289b libavcodec

faster ff_sqrt()
author michaelni
date Thu, 22 Aug 2002 19:41:39 +0000
parents 0b706debf55d
children 85b071dfc7e3
comparison
equal deleted inserted replaced
608:98e39397636b 609:153a7ffd289b
899 else 899 else
900 return a; 900 return a;
901 } 901 }
902 902
903 /* math */ 903 /* math */
904 extern const UINT8 ff_sqrt_tab[128];
905
904 int ff_gcd(int a, int b); 906 int ff_gcd(int a, int b);
905 907
906 static inline int ff_sqrt(int a) 908 static inline int ff_sqrt(int a)
907 { 909 {
908 int ret=0; 910 int ret=0;
909 int s; 911 int s;
910 int ret_sq=0; 912 int ret_sq=0;
911 913
914 if(a<128) return ff_sqrt_tab[a];
915
912 for(s=15; s>=0; s--){ 916 for(s=15; s>=0; s--){
913 int b= ret_sq + (1<<(s*2)) + (ret<<s)*2; 917 int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
914 if(b<=a){ 918 if(b<=a){
915 ret_sq=b; 919 ret_sq=b;
916 ret+= 1<<s; 920 ret+= 1<<s;