Dot Product - Texas Instruments TMS320C6000 Programmer's Manual

Hide thumbs Also See for TMS320C6000:
Table of Contents

Advertisement

Example 8–3. Dot Product
int dot_prod(const short *restrict a, const short *restrict b, int len)
{
int i;
int sum = 0;
for (i = 0; i < len; i++)
sum += b[i] * a[i];
return sum;
}
Example 8–4. Vector Complex Multiply
void vec_cx_mpy(const short *restrict a, const short *restrict b,
short *restrict c)
{
int j;
for (i = j = 0; i < len; i++, j += 2)
{
/* Real components are at even offsets, and imaginary components
are at odd offsets within each array. */
c[j+0] = (a[j+0] * b[j+0] – a[j+1] * b[j+1]) >> 16;
c[j+1] = (a[j+0] * b[j+1] + a[j+1] * b[j+0]) >> 16;
}
}
Although pure vector algorithms exist, most applications do not consist purely
of vector operations as simple as the one shown above. More commonly, an
algorithm will have portions, which behave as a vector algorithm, and portions
which do not. These portions of the code are addressed by other packed-data
processing techniques.
The second form of packed data optimization involves combining multiple op-
erations on packed data into a single, larger operation referred to here as a
macro operation. This can be very similar to vectorization, but the key differ-
ence is that there is significant mathematical interaction between adjacent ele-
ments. Simple examples include dot product operations and complex multi-
plies, as shown in Example 8–3 and Example 8–4.
The data flow for the dot product is shown in Figure 8–9. Notice how this is sim-
ilar to the vector sum in how the array elements are brought in, but different
in how the final result is tabulated.
Packed-Data Processing on the 'C64x
'C64x Programming Considerations
8-15

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents