Compiling C/C++ Code
3-8
To illustrate the concept of memory dependencies, it is helpful to look at the
algorithm code in a dependency graph. Example 3–1 shows the C code for a
basic vector sum. Figure 3–1 shows the dependency graph for this basic vec-
tor sum. For more information about drawing a dependency graph, see section
6.3.4, on page 6-11.
Example 3–1.Basic Vector Sum
void vecsum(short *sum, short *in1, short *in2, unsigned int N)
{
int i;
for (i = 0; i < N; i++)
sum[i] = in1[i] + in2[i];
}
Figure 3–1. Dependency Graph for Vector Sum #1
in1[i]
5
5
Load
Load
in2[i]
sum[i]
1
mem
1
1
Store to
memory
Number of cycles required
to complete an instruction
Add elements