GATE / CS ARCHIVE

GATE CSE 2002 / QUESTION 10(a)

Find array elements that conflict in a direct-mapped cache

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

GATE 2002, Q10(a) Descriptive
Report issue

Cache Memory

Question 10(a), 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). Which array elements conflict with A[0] in the cache? Briefly justify.
Question 10(a), 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). Which array elements conflict with A[0] in the cache? Briefly justify.
Question 10(a), 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). Which array elements conflict with A[0] in the cache? Briefly justify.
Tap to enlarge
Shared context

float A[2048] begins at address 0; each element occupies 4 bytes. The direct-mapped data cache has 8 Kbytes = 8192 bytes and 16-byte lines. Part (b) scans from A[2047] to A[0], starting with an empty cache and no other accesses.

Answer & solution

Answer: None; A[1], A[2], A[3] share A[0]’s block but do not conflict (no official key was published)

1. Convert sizes using the standard binary Kbyte convention. The cache holds 8×1024=8192 bytes. Dividing by the 16-byte block size gives 512 direct-mapped cache lines. Each block holds 16/4=4 array elements.

2. Derive the mapping from an array index. Since A begins at address 0, A[i] starts at address 4i. Its memory-block number is floor(4i/16)=floor(i/4). The corresponding cache-line index is floor(i/4) mod 512; the tag distinguishes blocks with that same index.

3. Find all array elements with A[0]’s index. Its block is block 0 and its cache index is 0. An index of 0 requires block number 0,512,1024,… . Within the declared array, 0≤i≤2047, so floor(i/4) ranges only from 0 to 511. Only block 0 occurs, containing A[0], A[1], A[2], A[3].

4. Distinguish sharing from conflict. A[1], A[2], A[3] are in the same memory block as A[0], so they are fetched together and coexist. They do not compete for the line or evict A[0]. A conflict requires a different memory block, hence a different tag, mapping to that line.

5. The next genuinely conflicting block would start at byte address 8192, corresponding to A[2048], which is outside the declared array. Therefore no element within A[0…2047] conflicts with A[0]. Saying merely “A[1…3] have the same cache index” is true but does not answer the eviction/conflict question correctly.

Original paper, page 8