324_Book

# The l2 cache can be attached to the memory bus or it

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: uch as sumvec that visits each element of a vector sequentially is said to have a stride-1 reference pattern (with respect to the element size). Visiting every Ø element of a contiguous vector is called a stride- reference pattern. Stride-1 reference patterns are a common and important source of spatial locality in programs. In general, as the stride increases, the spatial locality decreases. Stride is also an important issue for programs that reference multidimensional arrays. Consider the sumarrayrows function in Figure 6.18(a) that sums the elements of a two-dimensional array. The doubly nested loop reads the elements of the array in row-major order. That is, the inner loop reads the elements of the ﬁrst row, then the second row, and so on. The sumarrayrows function enjoys good spatial locality because 1 2 3 4 5 6 7 8 9 int sumarrayrows(int a[M][N]) { int i, j, sum = 0; for (i = 0; i &lt; M; i++) for (j = 0; j &lt; N; j++) sum += a[i][j]; return sum; } Address Contents Access order 0 ¼¼ 4 ¼½ 8 ¼¾ 12 ½¼ 16 ½½ 20 ½¾ 1 2 3 4 5 6 (a) (b) Figure 6.18: (a) Another function with good locality. (b) Reference pattern for array a (Å ¾,...
View Full Document

Ask a homework question - tutors are online