shithub: opus

Download patch

ref: a56c34f3816ece0cd46338c04af97cd715da9bc0
parent: 25aeed74f17bd0c99f549e91e117e3dd1d908099
author: Jean-Marc Valin <[email protected]>
date: Wed Mar 26 10:36:07 EDT 2008

optimisations: faster handling of the zero for compute_band_energies() and
normalise_bands(). Also, another bunch of restrict qualifiers -- mainly
to tell the compiler there's no aliasing between the array bounds and the
data.

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -94,14 +94,14 @@
             maxval = MAX32(maxval, ABS32(X[j*C+c]));
          if (maxval > 0)
          {
-            int shift = celt_zlog2(maxval)-10;
+            int shift = celt_ilog2(maxval)-10;
             for (j=B*eBands[i];j<B*eBands[i+1];j++)
                sum += VSHR32(X[j*C+c],shift)*VSHR32(X[j*C+c],shift);
             /* We're adding one here to make damn sure we never end up with a pitch vector that's
                larger than unity norm */
-            bank[i*C+c] = 1+VSHR32(EXTEND32(celt_sqrt(sum)),-shift);
+            bank[i*C+c] = EPSILON+VSHR32(EXTEND32(celt_sqrt(sum)),-shift);
          } else {
-            bank[i*C+c] = 0;
+            bank[i*C+c] = EPSILON;
          }
          /*printf ("%f ", bank[i*C+c]);*/
       }
@@ -110,7 +110,7 @@
 }
 
 /* Normalise each band such that the energy is one. */
-void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bank)
+void normalise_bands(const CELTMode *m, const celt_sig_t * restrict freq, celt_norm_t * restrict X, const celt_ener_t *bank)
 {
    int i, c, B, C;
    const celt_int16_t *eBands = m->eBands;
@@ -125,10 +125,7 @@
          celt_word16_t E;
          shift = celt_zlog2(bank[i*C+c])-13;
          E = VSHR32(bank[i*C+c], shift);
-         if (E>0)
-            g = EXTRACT16(celt_rcp(SHR32(MULT16_16(E,sqrtC_1[C-1]),11)));
-         else
-            g = 0;
+         g = EXTRACT16(celt_rcp(SHR32(MULT16_16(E,sqrtC_1[C-1]),11)));
          for (j=B*eBands[i];j<B*eBands[i+1];j++)
             X[j*C+c] = MULT16_16_Q14(VSHR32(freq[j*C+c],shift),g);
       }
@@ -137,7 +134,7 @@
       X[i] = 0;
 }
 
-void renormalise_bands(const CELTMode *m, celt_norm_t *X)
+void renormalise_bands(const CELTMode *m, celt_norm_t * restrict X)
 {
    int i;
    VARDECL(celt_ener_t, tmpE);
@@ -175,7 +172,7 @@
 }
 
 /* Normalise each band such that the energy is one. */
-void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bank)
+void normalise_bands(const CELTMode *m, const celt_sig_t * restrict freq, celt_norm_t * restrict X, const celt_ener_t *bank)
 {
    int i, c, B, C;
    const celt_int16_t *eBands = m->eBands;
@@ -195,7 +192,7 @@
       X[i] = 0;
 }
 
-void renormalise_bands(const CELTMode *m, celt_norm_t *X)
+void renormalise_bands(const CELTMode *m, celt_norm_t * restrict X)
 {
    VARDECL(celt_ener_t, tmpE);
    SAVE_STACK;
@@ -207,7 +204,7 @@
 #endif
 
 /* De-normalise the energy to produce the synthesis from the unit-energy bands */
-void denormalise_bands(const CELTMode *m, const celt_norm_t *X, celt_sig_t *freq, const celt_ener_t *bank)
+void denormalise_bands(const CELTMode *m, const celt_norm_t * restrict X, celt_sig_t * restrict freq, const celt_ener_t *bank)
 {
    int i, c, B, C;
    const celt_int16_t *eBands = m->eBands;
@@ -291,7 +288,8 @@
 {
    int i, j, B, bits;
    const celt_int16_t *eBands = m->eBands;
-   VARDECL(celt_norm_t, norm);
+   celt_norm_t * restrict norm;
+   VARDECL(celt_norm_t, _norm);
    VARDECL(int, pulses);
    VARDECL(int, offsets);
    SAVE_STACK;
@@ -298,9 +296,10 @@
 
    B = m->nbMdctBlocks*m->nbChannels;
    
-   ALLOC(norm, B*eBands[m->nbEBands+1], celt_norm_t);
+   ALLOC(_norm, B*eBands[m->nbEBands+1], celt_norm_t);
    ALLOC(pulses, m->nbEBands, int);
    ALLOC(offsets, m->nbEBands, int);
+   norm = _norm;
 
    for (i=0;i<m->nbEBands;i++)
       offsets[i] = 0;
@@ -351,7 +350,8 @@
 {
    int i, j, B, bits;
    const celt_int16_t *eBands = m->eBands;
-   VARDECL(celt_norm_t, norm);
+   celt_norm_t * restrict norm;
+   VARDECL(celt_norm_t, _norm);
    VARDECL(int, pulses);
    VARDECL(int, offsets);
    SAVE_STACK;
@@ -358,9 +358,10 @@
 
    B = m->nbMdctBlocks*m->nbChannels;
    
-   ALLOC(norm, B*eBands[m->nbEBands+1], celt_norm_t);
+   ALLOC(_norm, B*eBands[m->nbEBands+1], celt_norm_t);
    ALLOC(pulses, m->nbEBands, int);
    ALLOC(offsets, m->nbEBands, int);
+   norm = _norm;
 
    for (i=0;i<m->nbEBands;i++)
       offsets[i] = 0;
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -56,9 +56,9 @@
  * @param X Spectrum (returned normalised)
  * @param bands Square root of the energy for each band
  */
-void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bands);
+void normalise_bands(const CELTMode *m, const celt_sig_t * restrict freq, celt_norm_t * restrict X, const celt_ener_t *bands);
 
-void renormalise_bands(const CELTMode *m, celt_norm_t *X);
+void renormalise_bands(const CELTMode *m, celt_norm_t * restrict X);
 
 /** Denormalise each band of X to restore full amplitude
  * @param m Mode data 
@@ -65,7 +65,7 @@
  * @param X Spectrum (returned de-normalised)
  * @param bands Square root of the energy for each band
  */
-void denormalise_bands(const CELTMode *m, const celt_norm_t *X, celt_sig_t *freq, const celt_ener_t *bands);
+void denormalise_bands(const CELTMode *m, const celt_norm_t * restrict X, celt_sig_t * restrict freq, const celt_ener_t *bands);
 
 /** Compute the pitch predictor gain for each pitch band
  * @param m Mode data 
@@ -76,7 +76,7 @@
  */
 void compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm_t *P, celt_pgain_t *gains);
 
-void pitch_quant_bands(const CELTMode *m, celt_norm_t *P, const celt_pgain_t *gains);
+void pitch_quant_bands(const CELTMode *m, celt_norm_t * restrict P, const celt_pgain_t * restrict gains);
 
 /** Quantisation/encoding of the residual spectrum
  * @param m Mode data 
@@ -86,7 +86,7 @@
  * @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
  * @param enc Entropy encoder
  */
-void quant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, celt_mask_t *W, int total_bits, ec_enc *enc);
+void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, celt_mask_t *W, int total_bits, ec_enc *enc);
 
 /** Decoding of the residual spectrum
  * @param m Mode data 
@@ -95,7 +95,7 @@
  * @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
  * @param dec Entropy decoder
 */
-void unquant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, int total_bits, ec_dec *dec);
+void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, int total_bits, ec_dec *dec);
 
 void stereo_mix(const CELTMode *m, celt_norm_t *X, const celt_ener_t *bank, int dir);