Row-major traversal cache misses
Cache Memory
![Question 80, GATE 2006: A CPU has a 32 KB direct-mapped cache with 128-byte blocks. C array A[512][512] uses 8-byte elements. The two programs execute separately from the same initially cold cache; i,j,x are in registers.
P1: for(i=0;i<512;i++) for(j=0;j<512;j++) x+=A[i][j];
P2: for(i=0;i<512;i++) for(j=0;j<512;j++) x+=A[j][i];
Let M1,M2 be their cache-miss counts. Use the conventional block-aligned base address assumed by the listed answers. Find M1.
Options:
(A) 0
(B) 2048
(C) 16384
(D) 262144](../../../assets/questions/CS-2006-Q80-1.webp)
![Question 80, GATE 2006: A CPU has a 32 KB direct-mapped cache with 128-byte blocks. C array A[512][512] uses 8-byte elements. The two programs execute separately from the same initially cold cache; i,j,x are in registers.
P1: for(i=0;i<512;i++) for(j=0;j<512;j++) x+=A[i][j];
P2: for(i=0;i<512;i++) for(j=0;j<512;j++) x+=A[j][i];
Let M1,M2 be their cache-miss counts. Use the conventional block-aligned base address assumed by the listed answers. Find M1.
Options:
(A) 0
(B) 2048
(C) 16384
(D) 262144](../../../assets/questions/CS-2006-Q80-2.webp)
Answer & solution
Answer: C (no official key was published)
1. In C, A is row-major. Each 128-byte cache block holds 128/8=16 elements.
2. P1 visits all 512×512 elements sequentially, so one compulsory miss serves each group of 16 elements. For a block-aligned A, M1=512×512/16=16384, C; each later element in the same block hits.
3. Teaching check: C’s rightmost subscript varies over contiguous elements. Each cache block supplies sixteen consecutive doubles, causing one miss followed by fifteen hits in a sequential scan. The whole array is much larger than the cache, but immediate within-block reuse still occurs.
![Question 81, GATE 2006: A CPU has a 32 KB direct-mapped cache with 128-byte blocks. C array A[512][512] uses 8-byte elements. The two programs execute separately from the same initially cold cache; i,j,x are in registers.
P1: for(i=0;i<512;i++) for(j=0;j<512;j++) x+=A[i][j];
P2: for(i=0;i<512;i++) for(j=0;j<512;j++) x+=A[j][i];
Let M1,M2 be their cache-miss counts. Use the conventional block-aligned base address assumed by the listed answers. Find M1/M2.
Options:
(A) 0
(B) 1/16
(C) 1/8
(D) 16](../../../assets/questions/CS-2006-Q81-1.webp)
![Question 81, GATE 2006: A CPU has a 32 KB direct-mapped cache with 128-byte blocks. C array A[512][512] uses 8-byte elements. The two programs execute separately from the same initially cold cache; i,j,x are in registers.
P1: for(i=0;i<512;i++) for(j=0;j<512;j++) x+=A[i][j];
P2: for(i=0;i<512;i++) for(j=0;j<512;j++) x+=A[j][i];
Let M1,M2 be their cache-miss counts. Use the conventional block-aligned base address assumed by the listed answers. Find M1/M2.
Options:
(A) 0
(B) 1/16
(C) 1/8
(D) 16](../../../assets/questions/CS-2006-Q81-2.webp)
![Question 81, GATE 2006: A CPU has a 32 KB direct-mapped cache with 128-byte blocks. C array A[512][512] uses 8-byte elements. The two programs execute separately from the same initially cold cache; i,j,x are in registers.
P1: for(i=0;i<512;i++) for(j=0;j<512;j++) x+=A[i][j];
P2: for(i=0;i<512;i++) for(j=0;j<512;j++) x+=A[j][i];
Let M1,M2 be their cache-miss counts. Use the conventional block-aligned base address assumed by the listed answers. Find M1/M2.
Options:
(A) 0
(B) 1/16
(C) 1/8
(D) 16](../../../assets/questions/CS-2006-Q81-3.webp)
![Question 10(b), GATE 2002: A C program declares float A[2048], with four bytes per element and A starting at address 0x00000000. It runs on a computer with an 8-Kbyte direct-mapped data cache and 16-byte cache blocks (lines). Starting with an empty cache, access each array element once in reverse order, from the last element through the first. Ignore all other data and instruction accesses. How many data-cache misses occur? Briefly justify.](../../../assets/questions/CS-2002-Q68-1.webp)
![Question 10(b), GATE 2002: A C program declares float A[2048], with four bytes per element and A starting at address 0x00000000. It runs on a computer with an 8-Kbyte direct-mapped data cache and 16-byte cache blocks (lines). Starting with an empty cache, access each array element once in reverse order, from the last element through the first. Ignore all other data and instruction accesses. How many data-cache misses occur? Briefly justify.](../../../assets/questions/CS-2002-Q68-2.webp)
![Question 10(b), GATE 2002: A C program declares float A[2048], with four bytes per element and A starting at address 0x00000000. It runs on a computer with an 8-Kbyte direct-mapped data cache and 16-byte cache blocks (lines). Starting with an empty cache, access each array element once in reverse order, from the last element through the first. Ignore all other data and instruction accesses. How many data-cache misses occur? Briefly justify.](../../../assets/questions/CS-2002-Q68-3.webp)