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 cacheConceptIn 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…

  1. A.

    (k mod m) of the cache

  2. B.

    (k mod c) of the cache

  3. C.

    (k mod 2c) of the cache

  4. 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

  1. Here the cache has 2c blocks and each set contains 2 blocks.

  2. Therefore, number of sets = 2c / 2 = 2c - 1.

  3. 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.

Explore the full course: Isro

Loading lesson…