The main memory of a computer has 2m blocks, while the cache has 2c blocks. If…
1999
The main memory of a computer has 2m blocks, while the cache has 2c blocks. If the cache uses a set-associative mapping scheme with 2 blocks per set, then block k of main memory maps to the set:
Answer: D. (k mod 2c - 1) of the cache — ConceptIn an n-way set-associative cache, the number of sets equals the total number of cache blocks divided by n. A main-memory block numbered k maps to set…
- A.
(k mod m) of the cache
- B.
(k mod c) of the cache
- C.
(k mod 2c) of the cache
- D.
(k mod 2c - 1) of the cache
Attempted by 149 students.
Show answer & explanation
Correct answer: D
Concept
In an n-way set-associative cache, the number of sets equals the total number of cache blocks divided by n. A main-memory block numbered k maps to set k mod (number of sets).
Application
Here the cache has 2c blocks and each set contains 2 blocks.
Therefore, number of sets = 2c / 2 = 2c - 1.
Substituting this set count into the mapping rule gives set index = k mod 2c - 1.
Cross-check
The expression k mod 2c - 1 produces indices from 0 through 2c - 1 - 1, exactly one index for each of the 2c - 1 cache sets. Hence block k maps to the set (k mod 2c - 1) of the cache.