shithub: opus

Download patch

ref: d7291d243050d86097c9cd63c4bc42e1cd6b8455
parent: 7aa9d8c7ae491259f4094877facca36934058dd7
author: Jean-Marc Valin <[email protected]>
date: Mon Apr 21 03:53:40 EDT 2008

Further simplifications to comb2pulses() to remove all conditional branches.

--- a/libcelt/cwrs.c
+++ b/libcelt/cwrs.c
@@ -269,15 +269,12 @@
   _x: The combination with elements sorted in ascending order. _x[_m] = -1
   _s: The associated sign bits.*/
 void comb2pulse(int _n,int _m,int * restrict _y,const int *_x,const int *_s){
-  int j;
   int k;
-  int n;
+  const int signs[2]={1,-1};
   CELT_MEMSET(_y, 0, _n);
-  for(k=j=0;k<_m;k+=n){
-     /* _x[_m] = -1 so we won't overflow */
-    for(n=1;_x[k+n]==_x[k];n++);
-    _y[_x[k]]=_s[k]?-n:n;
-  }
+  k=0; do {
+    _y[_x[k]]+=signs[_s[k]];
+  } while (++k<_m);
 }
 
 /*Converts a pulse vector vector _y of length _n into a combination of _m unit
@@ -371,7 +368,7 @@
    VARDECL(int, signs);
    SAVE_STACK;
 
-   ALLOC(comb, K+1, int);
+   ALLOC(comb, K, int);
    ALLOC(signs, K, int);
    /* Simple heuristic to figure out whether it fits in 32 bits */
    if((N+4)*(K+4)<250 || (celt_ilog2(N)+1)*K<31)
@@ -380,7 +377,6 @@
    } else {
       decode_comb64(N, K, comb, signs, dec);
    }
-   comb[K] = -1;
    comb2pulse(N, K, _y, comb, signs);
    RESTORE_STACK;
 }
--- a/tests/cwrs32-test.c
+++ b/tests/cwrs32-test.c
@@ -12,7 +12,7 @@
   int n;
   for(n=2;n<=NMAX;n++){
     int m;
-    for(m=0;m<=MMAX;m++){
+    for(m=1;m<=MMAX;m++){
       celt_uint32_t uu[NMAX];
       celt_uint32_t inc;
       celt_uint32_t nc;
@@ -22,7 +22,7 @@
       if(inc<1)inc=1;
       for(i=0;i<nc;i+=inc){
         celt_uint32_t u[NMAX];
-        int           x[MMAX+1];
+        int           x[MMAX];
         int           s[MMAX];
         int           x2[MMAX];
         int           s2[MMAX];
@@ -40,7 +40,6 @@
           fprintf(stderr,"Combination-index mismatch.\n");
           return 1;
         }
-        x[m] = -1;
         comb2pulse(n,m,y,x,s);
         /*for(j=0;j<n;j++)printf(" %c%i",y[j]?y[j]<0?'-':'+':' ',abs(y[j]));
         printf("\n");*/
--- a/tests/cwrs64-test.c
+++ b/tests/cwrs64-test.c
@@ -13,7 +13,7 @@
   int n;
   for(n=2;n<=NMAX;n+=3){
     int m;
-    for(m=0;m<=MMAX;m++){
+    for(m=1;m<=MMAX;m++){
       celt_uint64_t uu[NMAX];
       celt_uint64_t inc;
       celt_uint64_t nc;
@@ -25,7 +25,7 @@
       /*printf("%d/%d: %llu",n,m, nc);*/
       for(i=0;i<nc;i+=inc){
         celt_uint64_t u[NMAX];
-        int           x[MMAX+1];
+        int           x[MMAX];
         int           s[MMAX];
         int           x2[MMAX];
         int           s2[MMAX];
@@ -43,7 +43,6 @@
           fprintf(stderr,"Combination-index mismatch.\n");
           return 1;
         }
-        x[m] = -1;
         comb2pulse(n,m,y,x,s);
         /*for(j=0;j<n;j++)printf(" %c%i",y[j]?y[j]<0?'-':'+':' ',abs(y[j]));
         printf("\n");*/