C e version f version figure 645 six versions

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cache them in the register file (temporal locality). Stride-1 reference patterns are good because caches at all levels of the memory hierarchy store data as contiguous blocks (spatial locality). Spatial locality is especially important in programs that operate on multidimensional arrays. For example, consider the sumarrayrows function from Section 6.2 that sums the elements of a two-dimensional array in row-major order. 1 2 3 4 5 6 7 8 9 int sumarrayrows(int a[M][N]) { int i, j, sum = 0; for (i = 0; i < M; i++) for (j = 0; j < N; j++) sum += a[i][j]; return sum; } Since C stores arrays in row-major order, the inner loop of this function has the same desirable stride-1 access pattern as sumvec. For example, suppose we make the same assumptions about the cache as for sumvec. Then the references to the array a will result in the following pattern of hits and misses: a[i][j] i=0 i=1 i=2 i=3 j=0 1 [m] 9 [m] 17 [m] 25 [m] j=1 2 [h] 10 [h] 18 [h] 26 [h] j=2 3 [h] 11 [h] 19 [h] 27 [h] j=3 4 [h] 12 [...
View Full Document

Ask a homework question - tutors are online