Refining C/C++ Code
3-29
Optimizing C/C++ Code
Example 3–13. FIR Filter— Optimized Form
void fir2(const int x[restrict], const int h[restrict], short y[restrict], int
n, int m, int s)
{
int i, j;
long y0, y1;
long round = 1L << (s – 1);
#pragma MUST_ITERATE (8);
for (j = 0; j < (m >> 1); j++)
{
y0 = y1 = round;
#pragma MUST_ITERATE (8);
for (i = 0; i < (n >> 1); i++)
{
y0 += _mpy (x[i + j], h[i]);
y0 += _mpyh (x[i + j], h[i]);
y1 += _mpyhl(x[i + j], h[i]);
y1 += _mpylh(x[i + j + 1], h[i]);
}
*y++ = (int)(y0 >> s);
*y++ = (int)(y1 >> s);
}
}
short x[SIZE_X], h[SIZE_H], y[SIZE_Y];
void main()
{
fir1((int *)x, (int *)h, y, n,m, s;
}