A CPU has a 32 KB direct-mapped cache with a 128-byte block size. Array A is a…

GATE · 2006 · CSModified — slightly modified from the official paper; see the solution

A CPU has a 32 KB direct-mapped cache with a 128-byte block size. Array A is a two-dimensional 512 × 512 array whose elements occupy 8 bytes each. Consider the following C code segment P1: Assume that A[0][0] is aligned to a 128-byte cache-block boundary.

 
for (i=0; i<512; i++) {
   for (j=0; j<512; j++) {
      x += A[i][j];
   }
} 

The second code segment P2 is:

 
for (i=0; i<512; i++) {
   for (j=0; j<512; j++) {
      x += A[j][i];
   }
}

P1 and P2 are executed independently from the same initial state: no block of A is in the cache, and i, j, and x are held in registers. Let M1 and M2 denote the numbers of cache misses for P1 and P2, respectively. The value of M1 is:

  1. A.

    0

  2. B.

    2048

  3. C.

    16384

  4. D.

    262144

Attempted by 413 students.

Show answer

Correct answer: C

The worked solution is available to enrolled students.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…