GATE / CS ARCHIVE

GATE CSE 2002 / QUESTION 10(b)

Count reverse-scan cache misses

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

GATE 2002, Q10(b) Descriptive
Report issue

Cache Memory

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.
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.
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.
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: 512 cache misses (no official key was published)

1. Count the blocks touched. The array holds 2048 four-byte elements, so its total size is 8192 bytes. With 16-byte lines, there are 8192/16 = 512 distinct array blocks, each containing four consecutive elements.

2. Trace the first reversed block. The first access, A[2047], misses because the cache is empty and loads the entire block A[2044…2047]. The next accesses A[2046], A[2045], A[2044] therefore hit. Crossing to A[2043] causes the next miss and loads the next group of four.

3. Generalize the pattern. In every group of four reversed accesses, the first is a miss and the other three are hits. No accesses outside the array intervene. The 512 array blocks have distinct cache indices, although even a smaller cache would still preserve this immediate three-hit pattern for a single uninterrupted sequential scan.

4. Multiply the counts: misses = 512×1 = 512, hits = 512×3 = 1536, total accesses = 512+1536 = 2048. All these misses are compulsory first references, not conflict misses.

5. Reverse traversal changes which element first brings in each block, but not the number of blocks touched. A direct-mapped simulation from A[2047] down to A[0] confirms the count of 512 misses.

Original paper, page 8