Refining C/C++ Code
3-33
Optimizing C/C++ Code
In Example 3–17, the dot product example has been rewritten for c64xx. This
demonstrates how it is possible to perform doubleword nonaligned memory
reads on a dot product that always executes a multiple of 4 times.
Example 3–17. Int Dot Product with Nonaligned Doubleword Reads
int dotp4(const short *restrict a, const short *restrict b, unsigned int N)
{
int i, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
for (i = 0; i < N; i+=4)
{
sum1 += _mpy (_lo(memd8((void *)&a[i])), _lo(_memd8((void *)&b[i])));
sum2 += _mpyh(_lo(memd8((void *)&a[i])), _lo(_memd8((void *)&b[i])));
sum3 += _mpy (_hi(memd8((void *)&a[i])), _hi(_memd8((void *)&b[i])));
sum4 += _mpyh(_hi(memd8((void *)&a[i])), _hi(_memd8((void *)&b[i])));
}
return sum1 + sum2 + sum3 + sum4;