Memory Hierarchy
How many sets does a 4-way set-associative cache with 32-bit addresses, 32 KB capacity and 64-byte lines have?
- A128
- B512
- C32
Show answer and explanation
Answer: A. 128
The number of lines is 32 KB ÷ 64 B = 512. A 4-way cache holds four lines per set, so there are 512 ÷ 4 = 128 = 2⁷ sets, giving a 7-bit index and a 32 − 7 − 6 = 19-bit tag. 512 is the line count itself, which equals the set count only when direct-mapped. Raising associativity reduces the number of sets, which adds tag bits and comparators. 32 comes from wrongly dividing the 64-byte line size by the number of ways.
- A. Correct. 512 lines ÷ 4 ways = 128 sets.
- B. 512 is the line count, the set count for a direct-mapped cache.
- C. 32 is not the set count but the result of a wrong division.