comparison snow.c @ 2221:3543987dccad libavcodec

use pointer arithmetic in mc_block(), 25% faster
author michael
date Sun, 12 Sep 2004 10:51:02 +0000
parents 713ad427a3c7
children b26474e72d6d
comparison
equal deleted inserted replaced
2220:21947e176d4d 2221:3543987dccad
1927 } 1927 }
1928 } 1928 }
1929 1929
1930 static void mc_block(uint8_t *dst, uint8_t *src, uint8_t *tmp, int stride, int b_w, int b_h, int dx, int dy){ 1930 static void mc_block(uint8_t *dst, uint8_t *src, uint8_t *tmp, int stride, int b_w, int b_h, int dx, int dy){
1931 int x, y; 1931 int x, y;
1932 START_TIMER
1932 for(y=0; y < b_h+5; y++){ 1933 for(y=0; y < b_h+5; y++){
1933 for(x=0; x < b_w; x++){ 1934 for(x=0; x < b_w; x++){
1934 int a0= src[x + y*stride]; 1935 int a0= src[x ];
1935 int a1= src[x + 1 + y*stride]; 1936 int a1= src[x + 1];
1936 int a2= src[x + 2 + y*stride]; 1937 int a2= src[x + 2];
1937 int a3= src[x + 3 + y*stride]; 1938 int a3= src[x + 3];
1938 int a4= src[x + 4 + y*stride]; 1939 int a4= src[x + 4];
1939 int a5= src[x + 5 + y*stride]; 1940 int a5= src[x + 5];
1940 // int am= 9*(a1+a2) - (a0+a3); 1941 // int am= 9*(a1+a2) - (a0+a3);
1941 int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5); 1942 int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5);
1942 // int am= 18*(a2+a3) - 2*(a1+a4); 1943 // int am= 18*(a2+a3) - 2*(a1+a4);
1943 // int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3; 1944 // int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3;
1944 // int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3; 1945 // int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3;
1945 1946
1946 // if(b_w==16) am= 8*(a1+a2); 1947 // if(b_w==16) am= 8*(a1+a2);
1947 1948
1948 if(dx<8) tmp[x + y*stride]= (32*a2*( 8-dx) + am* dx + 128)>>8; 1949 if(dx<8) tmp[x]= (32*a2*( 8-dx) + am* dx + 128)>>8;
1949 else tmp[x + y*stride]= ( am*(16-dx) + 32*a3*(dx-8) + 128)>>8; 1950 else tmp[x]= ( am*(16-dx) + 32*a3*(dx-8) + 128)>>8;
1950 1951
1951 /* if (dx< 4) tmp[x + y*stride]= (16*a1*( 4-dx) + aL* dx + 32)>>6; 1952 /* if (dx< 4) tmp[x + y*stride]= (16*a1*( 4-dx) + aL* dx + 32)>>6;
1952 else if(dx< 8) tmp[x + y*stride]= ( aL*( 8-dx) + am*(dx- 4) + 32)>>6; 1953 else if(dx< 8) tmp[x + y*stride]= ( aL*( 8-dx) + am*(dx- 4) + 32)>>6;
1953 else if(dx<12) tmp[x + y*stride]= ( am*(12-dx) + aR*(dx- 8) + 32)>>6; 1954 else if(dx<12) tmp[x + y*stride]= ( am*(12-dx) + aR*(dx- 8) + 32)>>6;
1954 else tmp[x + y*stride]= ( aR*(16-dx) + 16*a2*(dx-12) + 32)>>6;*/ 1955 else tmp[x + y*stride]= ( aR*(16-dx) + 16*a2*(dx-12) + 32)>>6;*/
1955 } 1956 }
1956 } 1957 tmp += stride;
1958 src += stride;
1959 }
1960 tmp -= (b_h+5)*stride;
1961
1957 for(y=0; y < b_h; y++){ 1962 for(y=0; y < b_h; y++){
1958 for(x=0; x < b_w; x++){ 1963 for(x=0; x < b_w; x++){
1959 int a0= tmp[x + y *stride]; 1964 int a0= tmp[x + 0*stride];
1960 int a1= tmp[x + (y + 1)*stride]; 1965 int a1= tmp[x + 1*stride];
1961 int a2= tmp[x + (y + 2)*stride]; 1966 int a2= tmp[x + 2*stride];
1962 int a3= tmp[x + (y + 3)*stride]; 1967 int a3= tmp[x + 3*stride];
1963 int a4= tmp[x + (y + 4)*stride]; 1968 int a4= tmp[x + 4*stride];
1964 int a5= tmp[x + (y + 5)*stride]; 1969 int a5= tmp[x + 5*stride];
1965 int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5); 1970 int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5);
1966 // int am= 18*(a2+a3) - 2*(a1+a4); 1971 // int am= 18*(a2+a3) - 2*(a1+a4);
1967 /* int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3; 1972 /* int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3;
1968 int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3;*/ 1973 int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3;*/
1969 1974
1970 // if(b_w==16) am= 8*(a1+a2); 1975 // if(b_w==16) am= 8*(a1+a2);
1971 1976
1972 if(dy<8) dst[x + y*stride]= (32*a2*( 8-dy) + am* dy + 128)>>8; 1977 if(dy<8) dst[x]= (32*a2*( 8-dy) + am* dy + 128)>>8;
1973 else dst[x + y*stride]= ( am*(16-dy) + 32*a3*(dy-8) + 128)>>8; 1978 else dst[x]= ( am*(16-dy) + 32*a3*(dy-8) + 128)>>8;
1974 1979
1975 /* if (dy< 4) tmp[x + y*stride]= (16*a1*( 4-dy) + aL* dy + 32)>>6; 1980 /* if (dy< 4) tmp[x + y*stride]= (16*a1*( 4-dy) + aL* dy + 32)>>6;
1976 else if(dy< 8) tmp[x + y*stride]= ( aL*( 8-dy) + am*(dy- 4) + 32)>>6; 1981 else if(dy< 8) tmp[x + y*stride]= ( aL*( 8-dy) + am*(dy- 4) + 32)>>6;
1977 else if(dy<12) tmp[x + y*stride]= ( am*(12-dy) + aR*(dy- 8) + 32)>>6; 1982 else if(dy<12) tmp[x + y*stride]= ( am*(12-dy) + aR*(dy- 8) + 32)>>6;
1978 else tmp[x + y*stride]= ( aR*(16-dy) + 16*a2*(dy-12) + 32)>>6;*/ 1983 else tmp[x + y*stride]= ( aR*(16-dy) + 16*a2*(dy-12) + 32)>>6;*/
1979 } 1984 }
1980 } 1985 dst += stride;
1986 tmp += stride;
1987 }
1988 STOP_TIMER("mc_block")
1981 } 1989 }
1982 1990
1983 #define mcb(dx,dy,b_w)\ 1991 #define mcb(dx,dy,b_w)\
1984 static void mc_block ## dx ## dy(uint8_t *dst, uint8_t *src, int stride){\ 1992 static void mc_block ## dx ## dy(uint8_t *dst, uint8_t *src, int stride){\
1985 uint8_t tmp[stride*(b_w+5)];\ 1993 uint8_t tmp[stride*(b_w+5)];\