optimisation: Removed a bunch of conditional branches from comb2pulse()

This commit is contained in:
Jean-Marc Valin 2008-04-18 16:46:39 +10:00
parent abdfc38837
commit e6ce0c6a22
5 changed files with 14 additions and 10 deletions

View file

@ -266,18 +266,18 @@ celt_uint64_t icwrs64(int _n,int _m,const int *_x,const int *_s,
/*Converts a combination _x of _m unit pulses with associated sign bits _s into /*Converts a combination _x of _m unit pulses with associated sign bits _s into
a pulse vector _y of length _n. a pulse vector _y of length _n.
_y: Returns the vector of pulses. _y: Returns the vector of pulses.
_x: The combination with elements sorted in ascending order. _x: The combination with elements sorted in ascending order. _x[_m] = -1
_s: The associated sign bits.*/ _s: The associated sign bits.*/
void comb2pulse(int _n,int _m,int *_y,const int *_x,const int *_s){ void comb2pulse(int _n,int _m,int * restrict _y,const int *_x,const int *_s){
int j; int j;
int k; int k;
int n; int n;
CELT_MEMSET(_y, 0, _n);
for(k=j=0;k<_m;k+=n){ for(k=j=0;k<_m;k+=n){
for(n=1;k+n<_m&&_x[k+n]==_x[k];n++); /* _x[_m] = -1 so we won't overflow */
while(j<_x[k])_y[j++]=0; for(n=1;_x[k+n]==_x[k];n++);
_y[j++]=_s[k]?-n:n; _y[_x[k]]=_s[k]?-n:n;
} }
while(j<_n)_y[j++]=0;
} }
/*Converts a pulse vector vector _y of length _n into a combination of _m unit /*Converts a pulse vector vector _y of length _n into a combination of _m unit
@ -370,7 +370,7 @@ void decode_pulses(int *_y, int N, int K, ec_dec *dec)
VARDECL(int, signs); VARDECL(int, signs);
SAVE_STACK; SAVE_STACK;
ALLOC(comb, K, int); ALLOC(comb, K+1, int);
ALLOC(signs, K, int); ALLOC(signs, K, int);
/* Simple heuristic to figure out whether it fits in 32 bits */ /* Simple heuristic to figure out whether it fits in 32 bits */
if((N+4)*(K+4)<250 || (celt_ilog2(N)+1)*K<31) if((N+4)*(K+4)<250 || (celt_ilog2(N)+1)*K<31)
@ -379,6 +379,7 @@ void decode_pulses(int *_y, int N, int K, ec_dec *dec)
} else { } else {
decode_comb64(N, K, comb, signs, dec); decode_comb64(N, K, comb, signs, dec);
} }
comb[K] = -1;
comb2pulse(N, K, _y, comb, signs); comb2pulse(N, K, _y, comb, signs);
RESTORE_STACK; RESTORE_STACK;
} }

View file

@ -57,7 +57,7 @@ celt_uint64_t icwrs64(int _n,int _m,const int *_x,const int *_s,
celt_uint64_t *_u); celt_uint64_t *_u);
void comb2pulse(int _n,int _m,int *_y,const int *_x,const int *_s); void comb2pulse(int _n,int _m,int * restrict _y,const int *_x,const int *_s);
void pulse2comb(int _n,int _m,int *_x,int *_s,const int *_y); void pulse2comb(int _n,int _m,int *_x,int *_s,const int *_y);

View file

@ -168,6 +168,7 @@ void find_spectral_pitch(kiss_fftr_cfg fft, const struct PsyDecay *decay, const
celt_word16_t Xr, Xi, n; celt_word16_t Xr, Xi, n;
/* weight = 1/sqrt(curve) */ /* weight = 1/sqrt(curve) */
n = celt_rsqrt(EPSILON+curve[i]); n = celt_rsqrt(EPSILON+curve[i]);
/*n = SHR32(32767,(celt_ilog2(EPSILON+curve[i])>>1));*/
/* Pre-multiply X by n, so we can keep everything in 16 bits */ /* Pre-multiply X by n, so we can keep everything in 16 bits */
Xr = EXTRACT16(SHR32(MULT16_16(n, X[2*i ]),3)); Xr = EXTRACT16(SHR32(MULT16_16(n, X[2*i ]),3));
Xi = EXTRACT16(SHR32(MULT16_16(n, X[2*i+1]),3)); Xi = EXTRACT16(SHR32(MULT16_16(n, X[2*i+1]),3));

View file

@ -22,7 +22,7 @@ int main(int _argc,char **_argv){
if(inc<1)inc=1; if(inc<1)inc=1;
for(i=0;i<nc;i+=inc){ for(i=0;i<nc;i+=inc){
celt_uint32_t u[NMAX]; celt_uint32_t u[NMAX];
int x[MMAX]; int x[MMAX+1];
int s[MMAX]; int s[MMAX];
int x2[MMAX]; int x2[MMAX];
int s2[MMAX]; int s2[MMAX];
@ -40,6 +40,7 @@ int main(int _argc,char **_argv){
fprintf(stderr,"Combination-index mismatch.\n"); fprintf(stderr,"Combination-index mismatch.\n");
return 1; return 1;
} }
x[m] = -1;
comb2pulse(n,m,y,x,s); comb2pulse(n,m,y,x,s);
/*for(j=0;j<n;j++)printf(" %c%i",y[j]?y[j]<0?'-':'+':' ',abs(y[j])); /*for(j=0;j<n;j++)printf(" %c%i",y[j]?y[j]<0?'-':'+':' ',abs(y[j]));
printf("\n");*/ printf("\n");*/

View file

@ -25,7 +25,7 @@ int main(int _argc,char **_argv){
/*printf("%d/%d: %llu",n,m, nc);*/ /*printf("%d/%d: %llu",n,m, nc);*/
for(i=0;i<nc;i+=inc){ for(i=0;i<nc;i+=inc){
celt_uint64_t u[NMAX]; celt_uint64_t u[NMAX];
int x[MMAX]; int x[MMAX+1];
int s[MMAX]; int s[MMAX];
int x2[MMAX]; int x2[MMAX];
int s2[MMAX]; int s2[MMAX];
@ -43,6 +43,7 @@ int main(int _argc,char **_argv){
fprintf(stderr,"Combination-index mismatch.\n"); fprintf(stderr,"Combination-index mismatch.\n");
return 1; return 1;
} }
x[m] = -1;
comb2pulse(n,m,y,x,s); comb2pulse(n,m,y,x,s);
/*for(j=0;j<n;j++)printf(" %c%i",y[j]?y[j]<0?'-':'+':' ',abs(y[j])); /*for(j=0;j<n;j++)printf(" %c%i",y[j]?y[j]<0?'-':'+':' ',abs(y[j]));
printf("\n");*/ printf("\n");*/