All Exams Test series for 1 year @ ₹349 only
Question

The size of the physical address space of a processor is $2^{32}$ bytes. The capacity of a cache memory unit is $2^{23}$ bytes. The cache block size is 128 bytes. The cache memory unit can be built as a direct mapped cache or as a $K$-way set-associative cache, where $K = 2^L$ and $L \in \{1, 2, 3\}$. Let the length of the TAG field be $M$ bits for the direct mapped cache, and $N$ bits for the set-associative cache.
Which one of the following options is true?

The correct answer is
$N = M + L$

The problem asks for the relationship between the TAG field length ($M$) of a direct mapped cache and the TAG field length ($N$) of a $K$-way set-associative cache, given specific memory parameters.

Address Structure Breakdown

The physical address is divided into three parts: TAG, Index, and Offset. The total size of the physical address determines the sum of the bits used for these three fields.

  • Physical Address Size: $2^{32}$ bytes, meaning the physical address is 32 bits long.
  • Cache Block Size: 128 bytes = $2^7$ bytes. This determines the number of bits required for the Offset.
    • Offset bits = $\log_2(128) = \log_2(2^7) = 7$ bits.
  • Cache Capacity: $2^{23}$ bytes.

Direct Mapped Cache (TAG Length M)

In a direct mapped cache, there is only one block per cache line, and each main memory block maps to a unique cache line. Here, $K=1$ (or $L=0$).

  • Number of Blocks in Cache: Cache Capacity / Block Size = $2^{23} \text{ bytes} / 2^7 \text{ bytes} = 2^{16}$ blocks.
  • Index Bits: The number of bits needed to uniquely identify each cache block (line). Index bits = $\log_2(\text{Number of Blocks}) = \log_2(2^{16}) = 16$ bits.
  • TAG bits (M): Total Address Bits - Index Bits - Offset Bits = 32 - 16 - 7 = 9 bits.
    • Therefore, $M = 9$.

K-way Set-Associative Cache (TAG Length N)

In a $K$-way set-associative cache, blocks can map to any of the $K$ ways within a specific set. The cache is divided into sets.

  • Number of Sets: Cache Capacity / (Block Size $\times$ K) = $2^{23} / (2^7 \times K)$.
  • Since $K = 2^L$, Number of Sets = $2^{23} / (2^7 \times 2^L) = 2^{23} / 2^{7+L} = 2^{16-L}$.
  • Index Bits: The number of bits needed to identify a specific set. Index bits = $\log_2(\text{Number of Sets}) = \log_2(2^{16-L}) = 16 - L$ bits.
  • TAG bits (N): Total Address Bits - Index Bits - Offset Bits = 32 - (16 - L) - 7 = 32 - 16 + L - 7 = 9 + L bits.
    • Therefore, $N = 9 + L$.

Relationship between N and M

We found $M=9$ and $N=9+L$. Substituting $M$ into the equation for $N$ gives:

$N = M + L$

This relationship holds true for the given conditions where $L \in \{1, 2, 3\}$.

Was this answer helpful?

Important Questions from Cache Mapping

  1. Consider a system with 1 MB physical memory and a word length of 1 byte. The system uses a direct mapped cache, with block numbers starting from 0. The word with physical address 0xA2C28 is mapped to the cache block number $176_{10}$. The maximum possible size of the cache (in KB) for this configuration is ___________. (answer in integer)

    Note: 1K=$2^{10}$ and 1M=$2^{20}$
Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App