Consider a machine with a -way set associative data cache of size Kbytes and block size bytes. The cache is managed using bit virtual addresses and the page size is Kbytes. A program to be run on this machine begins as follows:
double ARR[1024][1024];
int i, j;
/*Initialize array ARR to 0.0 */
for(i = 0; i < 1024; i++)
for(j = 0; j < 1024; j++)
ARR[i][j] = 0.0;
The size of double is bytes. Array is located in memory starting at the beginning of virtual page and stored in row major order. The cache is initially empty and no pre-fetching is done. The only data memory references made by the program are those to array .
Which of the following array elements have the same cache index as ?
View worked solution
Answer: B
To find which element has the same cache index as , we first determine the cache parameters:
- Cache Size:
- Block Size:
- Associativity: -way set associative
- Number of Sets: sets
The cache index is determined by the set index bits. For any two memory addresses to map to the same cache index, the difference between their byte addresses must be a multiple of:
Since each double element is bytes, the address difference between and in row-major order is:
For this difference to be a multiple of bytes:
Let us test the given options:
- Option A: (not a multiple of )
- Option B: (which is exactly )
- Option C: (not a multiple of )
- Option D: (not a multiple of )
Thus, maps to the exact same cache index as .
Free practice · Your answers on this page are not saved.
