Two Loops One Matrix
#define N 2048
static int m[N][N]; /* 16 MiB, page aligned */
long row_major(void) {
long s = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
s += m[i][j];
return s;
}
long col_major(void) {
long s = 0;
for (int j = 0; j < N; j++)
for (int i = 0; i < N; i++)
s += m[i][j];
return s;
}
Pages are 4 KiB, the data TLB holds 64 entries, huge pages are off. Both functions read all 4,194,304 elements exactly once. How do their TLB miss counts compare?
Sign in to answer questions and track your progress
Sign In