1 valid bit per line valid set 0 valid t tag bits per

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: ¿). There is good spatial locality because the array is accessed in the same row-major order that it is stored in memory. it references the array in the same row-major order that the array is stored (Figure 6.18(b)). The result is a nice stride-1 reference pattern with excellent spatial locality. 6.2. LOCALITY 297 Seemingly trivial changes to a program can have a big impact on its locality. For example, the sumarraycols function in Figure 6.19(a) computes the same result as the sumarrayrows function in Figure 6.18(a). The only difference is that we have interchanged the and loops. What impact does interchanging the loops have on its locality? The sumarraycols function suffers from poor spatial locality 1 2 3 4 5 6 7 8 9 int sumarraycols(int a[M][N]) { int i, j, sum = 0; for (j = 0; j < N; j++) for (i = 0; i < M; i++) sum += a[i][j]; return sum; } Address Contents Access order 0 ¼¼ 4 ¼½ 8 ¼¾ 12 ½¼ 16 ½½ 20 ½¾ 1 3 5 2 4 6 (a) (b) Figure 6.19: (a) A function with poor spatial locality. (b)...
View Full Document

Ask a homework question - tutors are online