GATE / CS ARCHIVE

GATE CSE 2006 / QUESTION 80

Row-major traversal cache misses

Computer Organization & Architecture · Cache Memory · Full GATE CSE 2006 paper

GATE 2006, Q80 2 marks · MCQ
Report issue

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
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
Tap to enlarge
Your answer
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.

Original paper, page 12