Same Bytes Different Order
4 KB pages, 8-byte doubles, so 512 elements per page. a is page-aligned and spans exactly 8 pages. The TLB is 4-entry, fully associative, LRU, and starts empty. Count only accesses to a.
#define N 4096
double a[N];
double s = 0;
/* loop A */
for (int i = 0; i < N; i++)
s += a[i];
/* loop B */
for (int j = 0; j < 512; j++)
for (int i = j; i < N; i += 512)
s += a[i];
Both loops touch all 4096 elements exactly once. How many TLB misses does each take?
Sign in to answer questions and track your progress
Sign In