GATE / CS ARCHIVE

SIMILAR QUESTIONS / COMPUTER ORGANIZATION & ARCHITECTURE

Extract cache indices from concrete memory addresses

6 questions solved the same way, newest first. Back to Computer Organization & Architecture

How these are solved

Compute a memory address when needed from array element size and layout, remove block offset bits, then take the block number modulo the set/line count. Compare indices or report tag/index values.

2 marks · MCQ
Report issue

Cache Memory

Question 30, GATE 2020: A 32-bit-word system has 16 MB byte-addressable memory and a 64 KB four-way set-associative cache with 256-byte blocks. Addresses: A1=0x42C8A4, A2=0x546888, A3=0x6A289C, A4=0x5E4880. Which is true? A A1,A4 map to different sets; B A2,A3 same set; C A3,A4 same set; D A1,A3 same set.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Worked explanation

Compute organization before extracting bits. Total cache blocks=216/28=28; four blocks per set gives 26 sets. A 24-bit physical byte address therefore divides as tag 10 bits | set 6 bits | byte offset 8 bits. Shifting each address right by 8 discards its final byte; masking the next six bits gives 0x08,0x28,0x28,0x08, or 8,40,40,8. Same set does not require equal tags or equal byte offsets, and four-way associativity does not change this index extraction. Only B among the offered statements is true.

Derivation and answer

The cache has 65536/256=256 lines and 64 four-way sets. Offset uses 8 bits and set index 6 bits, so index=(address>>8)&63. The four addresses map to sets 8, 40, 40, 8, respectively. Exactly A2 and A3 share a set among the listed positive claims, B; A1 and A4 actually also share a set, contrary to A.

Original paper, page 10 · Answer key

1 mark · MCQ
Report issue

Cache Memory

Question 34, GATE 2015: A byte-addressable main memory has size 2²⁰ bytes. Blocks contain 16 bytes, and a direct-mapped cache has 2¹² lines. Two consecutive memory-byte addresses are hexadecimal E201F and E2020. For address E201F, identify the tag and cache-line address, in hexadecimal. (A) E,201; (B) F,201; (C) E,E20; (D) 2,01F.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step through it (7 steps)

1. A hexadecimal digit represents four bits, so the 4+12+4 split aligns exactly with E | 201 | F. The next address E2020 illustrates the offset wrapping from F to 0 and the cache-line index advancing from 201 to 202.

2. The20-bit address has 4 offset bits for 16-byte blocks and 12 index bits for 212 lines, leaving 4 tag bits. Hex E201F therefore splits tagE, index 201, offsetF. Thus A.

Original paper, page 65 · Answer key

1 mark · MCQ
Report issue

Set-associative cache line range

Cache Memory

Question 20, GATE 2013: A cache has v sets of k consecutive lines each, sets numbered from 0 in order. Memory block j maps to which line interval? A(j mod v)k through(j mod v)k+k−1; B(j mod v) through(j mod v)+k−1; C(j mod k) through(j mod k)+v−1; D(j mod k)v through(j mod k)v+v−1.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Block j maps to set s=j mod v. Each earlier set occupies k consecutive lines, so this set starts at sk and ends at sk+k−1. Substituting s gives the interval in A.

First choose the set, not a particular way: s=j mod v. There are s earlier sets, each occupying k line positions, so the first line of set s is sk. The k allowed ways occupy offsets 0 through k−1, hence last line sk+k−1. For example, v=4, k=2, j=6 gives s=2 and lines 4, 5. This example also shows why omitting the factor k, as in B, gives the wrong physical positions.

Original paper, page 5 · Answer key

2 marks · MCQ
Report issue

Array element sharing a cache index

Cache Memory

Question 72, GATE 2008: A machine has a 64-KiB, two-way set-associative data cache with 16-byte blocks, managed using 32-bit virtual addresses; pages are 4 KiB. A row-major double ARR[1024][1024] starts at the beginning of virtual page 0xFF000. A double occupies 8 bytes. The cache is initially empty, there is no prefetching, and only ARR causes data-memory references. The code is:
for(i=0;i<1024;i++)
 for(j=0;j<1024;j++) ARR[i][j]=0.0;
Which element has the same cache index as ARR[0][0]?

(A) ARR[0][4]
(B) ARR[4][0]
(C) ARR[0][5]
(D) ARR[5][0]
Question 72, GATE 2008: A machine has a 64-KiB, two-way set-associative data cache with 16-byte blocks, managed using 32-bit virtual addresses; pages are 4 KiB. A row-major double ARR[1024][1024] starts at the beginning of virtual page 0xFF000. A double occupies 8 bytes. The cache is initially empty, there is no prefetching, and only ARR causes data-memory references. The code is:
for(i=0;i<1024;i++)
 for(j=0;j<1024;j++) ARR[i][j]=0.0;
Which element has the same cache index as ARR[0][0]?

(A) ARR[0][4]
(B) ARR[4][0]
(C) ARR[0][5]
(D) ARR[5][0]
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. The index repeats every 2048 sets×16 bytes=32768 bytes. A row contains 1024 doubles×8 bytes=8192 bytes.
2. ARR[4][0] is 4×8192=32768 bytes after ARR[0][0], so it has the same set index, option B. ARR[0][4] and ARR[0][5] are only 32 and 40 bytes later; ARR[5][0] is 40960 bytes later, changing the index.

Original paper, page 15

Descriptive
Report issue

Find array elements that conflict in a direct-mapped cache

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

1 mark · MCQ
Report issue

Two-way set-associative mapping

Cache Memory

Question 1.22, GATE 1999: Main memory has 2cm blocks and cache has 2c blocks, with two blocks per set. Which set receives block k: k mod m,c,2c,or 2cm?
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

The number of cache sets is capacity divided by associativity: (2c)/2=c. Consecutive main-memory blocks are distributed cyclically over these c sets, so the set index is k mod c. The remaining quotient supplies tag information, while either way within that indexed set may hold the block. Thus B. The paper display products 2cm and 2c, not exponents; reading the latter as 2c would change the set-count formula incorrectly.

Original paper, page 3