Similar questions 2 more →
Cache Memory
![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)
Answer & solution
Answer: B (no official key was published)
1. P1 has 16384 misses under the block-aligned assumption. P2 accesses A[j][i] with stride 512×8=4096 bytes=32 cache lines.
2. The cache has 32768/128=256 lines, so successive row accesses cycle through only 256/gcd(256,32)=8 cache indices. With 512 rows, every would-be reused block is evicted before the next column accesses it.
3. All 512²=262144 P2 accesses miss. M1/M2=16384/262144=1/16, B.
4. The last options are on physical page 13.
5. Teaching check: A 4096-byte stride advances by 32 cache indices modulo 256. Only eight indices participate in a column, repeatedly overwriting each other. Thus the next column cannot reuse the previous column’s blocks, even though adjacent elements within a row occupy the same block.