Refining C/C++ Code
3-38
If your code operates on global arrays as in Example 3–24, and you build your
application with the -pm and -o3 options, the compiler will have enough infor-
mation (trip counts and alignments of variables) to determine whether or not
packed-data processing optimization is feasible.
Example 3–24. Automatic Use of Word Accesses Without the _nassert Intrinsic
<file1.c>
int dotp (short *restrict a, short *restrict b, int c)
{
int sum = 0, i;
for (i = 0; i < c; i++) sum += a[i] * b[i];
return sum;
}
<file2.c>
#include <stdio.h>
short x[40] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
short y[40] = { 40, 39, 38, 37, 36, 35, 34, 33, 32, 31,
30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
20, 19, 18, 17, 16, 15, 14, 13, 12, 11,
10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
void main()
{
int z;
z = dotp(x, y, 40);
printf(“z = %d\n”, z);
}
Compile file1.c and file2.c with:
cl6x -pm -o3 -k file1.c file2.c