Back to the 2022 paper

Module 4: Memory Organization

20227m

A set-associative cache has a block size of four 16-bit words and a set size of 2. The cache can accommodate a total of 4096 words. The main memory size that is cacheable is 64K 32 bits. Design the cache structure and show how the processor’s addresses are interpreted.

Worked SolutionAI Assisted

Set-Associative Cache Design (Numerical)

Given: Block = 4×164 \times 16-bit words =64=64 bits =8=8 bytes
Cache capacity =4096=4096 words ×16\times16 bit =65536=65536 bits =8192=8192 bytes
Set size k=2k =2 (2-way set-associative)
Cacheable main memory =64K×32=64K \times32 bits =65536×4=65536\times4 bytes =256=256 KB

1. Number of Blocks & Sets

Nblocks=Cache wordswords per block=40964=1024 blocksN_{blocks}= \frac{\text{Cache words}}{\text{words per block}} = \frac{4096}{4}=1024 \text{ blocks}

Nsets=Nblocksk=10242=512 setsN_{sets}= \frac{N_{blocks}}{k}= \frac{1024}{2}=512 \text{ sets}

Set  index  bits=log⁡2Nsets=log⁡2512=9 bitsSet\;index\;bits = \log_2 N_{sets}= \log_2 512 =9 \text{ bits}

Block  offset  (word)=log⁡24=2 bits (selects one of 4×16-bit words)Block\;offset\;(word) = \log_2 4 =2 \text{ bits (selects one of 4×16-bit words)}
If normalized to 32-bit CPU word: block =2×32=2\times32 bits ⇒\Rightarrow offset =1=1 bit. Add byte offset 11 bit if byte-addressed.

2. Address Interpretation

Main memory 64K×3264K\times32 bits needs 1616 bits for 32-bit word address (216=64K2^{16}=64K). Equivalent 128K×16128K\times16 bits needs 1717 bits for 16-bit word address.

Case A - 16-bit word address (most exam-expected):
Total 17 bits (00-1616 for 128K128K)

Tag  bits=17−Set  bits−Word  offset=17−9−2=6 bitsTag\;bits = 17 - Set\;bits - Word\;offset =17-9-2=6 \text{ bits}

17-bit word address:
| Tag (6) | Set index (9) | Word (2) |
  16-11      10-2            1-0

If CPU byte-addressed: add 11 bit byte offset inside 16-bit word:
Tag(6) | Set(9) | Word(2) | Byte(1) =18 bits total for 256256KB.

Case B - 32-bit word address (normalized):
Total 1616 bits, block =2=2 words

16-bit address:
| Tag (6) | Set (9) | Block offset (1) |
 15-10      9-1          0

With byte offset: Tag(6)|Set(9)|Word(1)|Byte(2) =18 bits (Byte2Byte2 because 32-bit =4 bytes).

3. Cache Structure Design

  • Organization: 512512 sets ×\times 22 lines/set =1024=1024 lines.
  • Each line: Valid(1) + Dirty(1) + Tag(6) + Data(64 bits = 4×16 bits). Optionally LRU bit per set (1 bit for 2-way).
  • Data RAM: 81928192 bytes, divided into 10241024 blocks of 8 bytes.
  • Tag RAM: 1024×61024 \times 6 bits (or 512×2×6512\times2\times6 ).
  • Size: Total tag storage ≈1024×6=6144\approx 1024\times6=6144 bits.
CPU Address (17-bit word) ---> [Tag 6] [Set 9] [W 2]
                                  |       |      |
                          +-------+ +-----+ +----+
                          |         |      |    word mux 4:1
                  Tag compare (×2)  --> set decoder 512 --> selected set's 2 tags
                          | HIT if tag match & Valid=1
                          v
                    Data out (selected 16-bit word or 32-bit word)

Operation: Set field selects one of 512 sets (both ways read in parallel); Tag field compared associatively with 2 tags in set; if match, Word offset selects one of 4 words in block (or 1 of 2×32-bit words). Replacement uses LRU per set.

For exam diagram show set decoder, two comparators, 2:12:1 MUX and valid/LRU bits. Numbers: 512 sets, 2 lines/set, 8 bytes/block, 9+2+6 split.

Check: Cache ratio =8KB/256KB=1/32= 8\text{KB} / 256\text{KB}=1/32.

Similar questions

Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.