ref: 9743bf38ca3b51d722e5033518bf00a8be5d8829
parent: 60c316b4197609b75b85e5ae7225972e1df6f431
author: Gregory Maxwell <[email protected]>
date: Thu Nov 4 16:45:09 EDT 2010
Switch iteration over channels to the do{}while(); construct in order to inform the compiler that the these loops execute at least once. (This results in more intelligent output from the clang static analysis tool and should also produce faster code on at least some architectures.)
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -70,8 +70,7 @@
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
N = M*m->shortMdctSize;
- for (c=0;c<C;c++)
- {
+ c=0; do {
for (i=0;i<end;i++)
{
int j;
@@ -98,7 +97,7 @@
}
/*printf ("%f ", bank[i+c*m->nbEBands]);*/
}
- }
+ } while (++c<C);
/*printf ("\n");*/
}
@@ -109,8 +108,7 @@
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
N = M*m->shortMdctSize;
- for (c=0;c<C;c++)
- {
+ c=0; do {
i=0; do {
celt_word16 g;
int j,shift;
@@ -122,7 +120,7 @@
X[j+c*N] = MULT16_16_Q15(VSHR32(freq[j+c*N],shift-1),g);
} while (++j<M*eBands[i+1]);
} while (++i<end);
- }
+ } while (++c<C);
}
#else /* FIXED_POINT */
@@ -133,8 +131,7 @@
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
N = M*m->shortMdctSize;
- for (c=0;c<C;c++)
- {
+ c=0; do {
for (i=0;i<end;i++)
{
int j;
@@ -144,7 +141,7 @@
bank[i+c*m->nbEBands] = celt_sqrt(sum);
/*printf ("%f ", bank[i+c*m->nbEBands]);*/
}
- }
+ } while (++c<C);
/*printf ("\n");*/
}
@@ -155,8 +152,7 @@
const celt_int16 *eBands = m->eBands;
const int C = CHANNELS(_C);
N = M*m->shortMdctSize;
- for (c=0;c<C;c++)
- {
+ c=0; do {
for (i=0;i<end;i++)
{
int j;
@@ -164,7 +160,7 @@
for (j=M*eBands[i];j<M*eBands[i+1];j++)
X[j+c*N] = freq[j+c*N]*g;
}
- }
+ } while (++c<C);
}
#endif /* FIXED_POINT */
@@ -177,8 +173,7 @@
const int C = CHANNELS(_C);
N = M*m->shortMdctSize;
celt_assert2(C<=2, "denormalise_bands() not implemented for >2 channels");
- for (c=0;c<C;c++)
- {
+ c=0; do {
celt_sig * restrict f;
const celt_norm * restrict x;
f = freq+c*N;
@@ -196,7 +191,7 @@
}
for (i=M*eBands[m->nbEBands];i<N;i++)
*f++ = 0;
- }
+ } while (++c<C);
}
static void intensity_stereo(const CELTMode *m, celt_norm *X, celt_norm *Y, const celt_ener *bank, int bandID, int N)
@@ -299,8 +294,7 @@
if (M*(eBands[end]-eBands[end-1]) <= 8)
return 0;
- for (c=0;c<C;c++)
- {
+ c=0; do {
for (i=0;i<end;i++)
{
int j, N, tmp=0;
@@ -327,7 +321,7 @@
sum += tmp*256;
nbBands++;
}
- }
+ } while (++c<C);
sum /= nbBands;
/* Recursive averaging */
sum = (sum+*average)>>1;
@@ -386,12 +380,11 @@
float g;
if (bandE0[i]<10 || (C==2 && bandE0[i+m->nbEBands]<1))
continue;
- for (c=0;c<C;c++)
- {
+ c=0; do {
g = bandE[i+c*m->nbEBands]/(1e-15+bandE0[i+c*m->nbEBands]);
for (j=M*m->eBands[i];j<M*m->eBands[i+1];j++)
MSE[i] += (g*X[j+c*N]-X0[j+c*N])*(g*X[j+c*N]-X0[j+c*N]);
- }
+ } while (++c<C);
MSECount[i]+=C;
}
nbMSEBands = m->nbEBands;
@@ -509,8 +502,7 @@
{
int c;
celt_norm *x = X;
- for (c=0;c<1+stereo;c++)
- {
+ c=0; do {
int sign=0;
if (*remaining_bits>=1<<BITRES)
{
@@ -527,7 +519,7 @@
if (resynth)
x[0] = sign ? -NORM_SCALING : NORM_SCALING;
x = Y;
- }
+ } while (++c<1+stereo);
if (lowband_out)
lowband_out[0] = SHR16(X[0],4);
return;
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -274,8 +274,7 @@
B = shortBlocks;
}
ALLOC(tmp, N, celt_word32);
- for (c=0;c<C;c++)
- {
+ c=0; do {
for (b=0;b<B;b++)
{
int j;
@@ -284,7 +283,7 @@
for (j=0;j<N;j++)
out[(j*B+b)+c*N*B] = tmp[j];
}
- }
+ } while (++c<C);
RESTORE_STACK;
}
}
@@ -299,8 +298,7 @@
const int C = CHANNELS(_C);
const int N = mode->shortMdctSize<<LM;
const int overlap = OVERLAP(mode);
- for (c=0;c<C;c++)
- {
+ c=0; do {
int j;
VARDECL(celt_word32, x);
VARDECL(celt_word32, tmp);
@@ -335,7 +333,7 @@
for (j=0;j<overlap;j++)
overlap_mem[c][j] = x[N+j];
RESTORE_STACK;
- }
+ } while (++c<C);
}
static void deemphasis(celt_sig *in[], celt_word16 *pcm, int N, int _C, const celt_word16 *coef, celt_sig *mem)
@@ -342,8 +340,7 @@
{
const int C = CHANNELS(_C);
int c;
- for (c=0;c<C;c++)
- {
+ c=0; do {
int j;
celt_sig * restrict x;
celt_word16 * restrict y;
@@ -361,7 +358,7 @@
y+=C;
}
mem[c] = m;
- }
+ } while (++c<C);
}
#ifdef ENABLE_POSTFILTER
@@ -629,13 +626,12 @@
#if 0
float diff=0;
int c;
- for (c=0;c<C;c++)
- {
+ c=0; do {
for (i=0;i<nbEBands-1;i++)
{
diff += bandLogE[i+c*nbEBands]*(i-.5*nbEBands);
}
- }
+ } while (++c<0);
diff /= C*(nbEBands-1);
/*printf("%f\n", diff);*/
if (diff > 4)
@@ -737,8 +733,7 @@
pre[0] = _pre;
pre[1] = _pre + (N+COMBFILTER_MAXPERIOD);
- for (c=0;c<C;c++)
- {
+ c=0; do {
const celt_word16 * restrict pcmp = pcm+c;
celt_sig * restrict inp = in+c*(N+st->overlap)+st->overlap;
@@ -754,7 +749,7 @@
}
CELT_COPY(pre[c], prefilter_mem+c*COMBFILTER_MAXPERIOD, COMBFILTER_MAXPERIOD);
CELT_COPY(pre[c]+COMBFILTER_MAXPERIOD, in+c*(N+st->overlap)+st->overlap, N);
- }
+ } while (++c<C);
#ifdef ENABLE_POSTFILTER
{
@@ -804,8 +799,7 @@
ec_enc_bit_prob(enc, 0, 32768);
#endif /* ENABLE_POSTFILTER */
- for (c=0;c<C;c++)
- {
+ c=0; do {
CELT_COPY(in+c*(N+st->overlap), st->in_mem+c*(st->overlap), st->overlap);
#ifdef ENABLE_POSTFILTER
comb_filter(in+c*(N+st->overlap)+st->overlap, pre[c]+COMBFILTER_MAXPERIOD,
@@ -822,7 +816,7 @@
CELT_MOVE(prefilter_mem+c*COMBFILTER_MAXPERIOD+COMBFILTER_MAXPERIOD-N, pre[c]+COMBFILTER_MAXPERIOD, N);
}
#endif /* ENABLE_POSTFILTER */
- }
+ } while (++c<C);
RESTORE_STACK;
}
@@ -1018,9 +1012,10 @@
#ifdef MEASURE_NORM_MSE
float X0[3000];
float bandE0[60];
- for (c=0;c<C;c++)
+ c=0; do
for (i=0;i<N;i++)
X0[i+c*N] = X[i+c*N];
+ while (++c<C);
for (i=0;i<C*st->mode->nbEBands;i++)
bandE0[i] = bandE[i];
#endif
@@ -1050,30 +1045,32 @@
if (C==2)
CELT_MOVE(st->syn_mem[1], st->syn_mem[1]+N, MAX_PERIOD);
- for (c=0;c<C;c++)
+ c=0; do
for (i=0;i<M*st->mode->eBands[st->start];i++)
freq[c*N+i] = 0;
- for (c=0;c<C;c++)
+ while (++c<C);
+ c=0; do
for (i=M*st->mode->eBands[st->end];i<N;i++)
freq[c*N+i] = 0;
+ while (++c<C);
out_mem[0] = st->syn_mem[0]+MAX_PERIOD;
if (C==2)
out_mem[1] = st->syn_mem[1]+MAX_PERIOD;
- for (c=0;c<C;c++)
+ c=0; do
overlap_mem[c] = _overlap_mem + c*st->overlap;
+ while (++c<C);
compute_inv_mdcts(st->mode, shortBlocks, freq, out_mem, overlap_mem, C, LM);
#ifdef ENABLE_POSTFILTER
- for (c=0;c<C;c++)
- {
+ c=0; do {
comb_filter(out_mem[c], out_mem[c], st->prefilter_period, st->prefilter_period, st->overlap, C,
st->prefilter_gain, st->prefilter_gain, NULL, 0);
comb_filter(out_mem[c]+st->overlap, out_mem[c]+st->overlap, st->prefilter_period, pitch_index, N-st->overlap, C,
st->prefilter_gain, gain1, st->mode->window, st->mode->overlap);
- }
+ } while (++c<C);
#endif /* ENABLE_POSTFILTER */
deemphasis(out_mem, (celt_word16*)pcm, N, C, st->mode->preemph, st->preemph_memD);
@@ -1368,12 +1365,11 @@
celt_word16 *lpc;
SAVE_STACK;
- for (c=0;c<C;c++)
- {
+ c=0; do {
decode_mem[c] = st->_decode_mem + c*(DECODE_BUFFER_SIZE+st->overlap);
out_mem[c] = decode_mem[c]+DECODE_BUFFER_SIZE-MAX_PERIOD;
overlap_mem[c] = decode_mem[c]+DECODE_BUFFER_SIZE;
- }
+ } while (++c<C);
lpc = (celt_word16*)(st->_decode_mem+(DECODE_BUFFER_SIZE+st->overlap)*C);
len = N+st->mode->overlap;
@@ -1402,8 +1398,7 @@
fade = 0;
}
- for (c=0;c<C;c++)
- {
+ c=0; do {
/* FIXME: This is more memory than necessary */
celt_word32 e[2*MAX_PERIOD];
celt_word16 exc[2*MAX_PERIOD];
@@ -1532,7 +1527,7 @@
#endif /* ENABLE_POSTFILTER */
for (i=0;i<overlap;i++)
out_mem[c][MAX_PERIOD+i] = e[i];
- }
+ } while (++c<C);
{
celt_word32 *out_syn[2];
@@ -1597,12 +1592,11 @@
return CELT_BAD_ARG;
M=1<<LM;
- for (c=0;c<C;c++)
- {
+ c=0; do {
decode_mem[c] = st->_decode_mem + c*(DECODE_BUFFER_SIZE+st->overlap);
out_mem[c] = decode_mem[c]+DECODE_BUFFER_SIZE-MAX_PERIOD;
overlap_mem[c] = decode_mem[c]+DECODE_BUFFER_SIZE;
- }
+ } while (++c<C);
lpc = (celt_word16*)(st->_decode_mem+(DECODE_BUFFER_SIZE+st->overlap)*C);
oldBandE = lpc+C*LPC_ORDER;
@@ -1615,12 +1609,14 @@
ALLOC(freq, C*N, celt_sig); /**< Interleaved signal MDCTs */
ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */
ALLOC(bandE, st->mode->nbEBands*C, celt_ener);
- for (c=0;c<C;c++)
+ c=0; do
for (i=0;i<M*st->mode->eBands[st->start];i++)
X[c*N+i] = 0;
- for (c=0;c<C;c++)
+ while (++c<C);
+ c=0; do
for (i=M*st->mode->eBands[effEnd];i<N;i++)
X[c*N+i] = 0;
+ while (++c<C);
if (data == NULL)
{
@@ -1731,12 +1727,14 @@
if (C==2)
CELT_MOVE(decode_mem[1], decode_mem[1]+N, DECODE_BUFFER_SIZE-N);
- for (c=0;c<C;c++)
+ c=0; do
for (i=0;i<M*st->mode->eBands[st->start];i++)
freq[c*N+i] = 0;
- for (c=0;c<C;c++)
+ while (++c<C);
+ c=0; do
for (i=M*st->mode->eBands[effEnd];i<N;i++)
freq[c*N+i] = 0;
+ while (++c<C);
out_syn[0] = out_mem[0]+MAX_PERIOD-N;
if (C==2)
@@ -1746,13 +1744,12 @@
compute_inv_mdcts(st->mode, shortBlocks, freq, out_syn, overlap_mem, C, LM);
#ifdef ENABLE_POSTFILTER
- for (c=0;c<C;c++)
- {
+ c=0; do {
comb_filter(out_syn[c], out_syn[c], st->postfilter_period, st->postfilter_period, st->overlap, C,
st->postfilter_gain, st->postfilter_gain, NULL, 0);
comb_filter(out_syn[c]+st->overlap, out_syn[c]+st->overlap, st->postfilter_period, postfilter_pitch, N-st->overlap, C,
st->postfilter_gain, postfilter_gain, st->mode->window, st->mode->overlap);
- }
+ } while (++c<C);
st->postfilter_period = postfilter_pitch;
st->postfilter_gain = postfilter_gain;
#endif /* ENABLE_POSTFILTER */
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -74,14 +74,13 @@
{
int c, i;
celt_word32 dist = 0;
- for (c=0;c<C;c++)
- {
+ c=0; do {
for (i=start;i<end;i++)
{
celt_word16 d = SHR16(SUB16(eBands[i+c*len], oldEBands[i+c*len]),2);
dist = MAC16_16(dist, d,d);
}
- }
+ } while (++c<C);
return SHR32(dist,2*DB_SHIFT-4) > 2*C*(end-start);
}