The Gateway to Computer Science Excellence
+19 votes
A $4$-way set-associative cache memory unit with a capacity of $16$ KB is built using a block size of $8$ words. The word length is $32$ bits. The size of the physical address space is $4$ GB. The number of bits for the TAG field is ____
in CO and Architecture by Veteran (105k points)
edited by | 8.5k views

4 Answers

+35 votes
Best answer
Number of sets$=\dfrac{\text{cache size}}{\text{sizeof a set}}$

Size of a set $=\text{blocksize}\times  \text{no. of blocks in a set}$
$= 8 \text{ words}\times 4\text{ (4-way set-associative)}$
$= 8\times 4\times 4\text{ (since a word is 32 bits = 4 bytes)}$
$= 128\text{ bytes}.$

So, number of sets $=\dfrac{16\ KB}{(128\ B)}=128$

Now, we can divide the physical address space equally between these $128$ sets.
So, the number of bytes each set can access
$=\dfrac{4\ GB}{128}$

$={32\ MB}$

$=\dfrac{32}{4}=8\text{ M words}=1 \text{ M blocks. ($2^{20}$ blocks)}$

So, we need $20$ tag bits to identify these $2^{20}$ blocks.
by Veteran (425k points)
edited by
4 GB space is divided between 128 sets equally.

So each set contains 4GB / 128 = 32 MB.

Set is 4-way set associative , so contains 4 block / set.

32/4 = 8M words / block.  Can u explain further ?? I didnt get how 2^20 came.
8M words = 1M blocks since block size is 8 words. Now, 1M = 2^20. So, to address 2^20 blocks we need 20 bits.
I am a little confused. If tag field is 20 bits and set field is 7 bits(since there are 128 sets) then we need 5 bits for word field, since there are 32 bits in physical address. But there are just 8 words per block which implies 3 bits . Am I wrong?
That is for word addressing where the offset is used for fetching a word and not byte. By default we assume byte addressing. Here, each word is of 32 bits - so we need 2 more bits to access a byte.

(And we always calculate the set bits and offset bits and put the remaining in tag bits, not the other way)
"And we always calculate the set bits and offset bits and put the remaining in tag bits, not the other way"....yes that's what I am saying...we first calculate set bits(log 128 = 7), and then word bits(log 8 = 3), and finally tag bits, which equals 32-(7+3) = 22 bits.

In the book I am reading , the author divides the address into 3 parts..TAG : SET : WORD .

"By default we assume byte addressing"...should I solve questions by always assuming byte addressing in gate??

Thanks in advance.
yes. Unless specified use byte addressing.
Till now all such problems I came across of this type did: TAG_BITS = ADDRESS_BITS - SET_BITS - WORD_BITS. Why here problem is solved in different way?

I solved it like this:

(Given) 4 way set associative $\rightarrow$ 4 lines per set
(Given) Cache size = 16 KB = $2^{14}$B
(Given) words per line = 8
(Given) Main memory size = 4GB $= 2^{32}$B
$\rightarrow$ ADDRESS_BITS = 32
(Given) Word size = 32 bits = 4 bytes per word
$\rightarrow$ WORD_BITS = 2
Line size = 8 words per line $\times$ 4 bytes per word = 32 B
Set size = 4 lines per set $\times$ 32 bytes per line = 128 B $=2^7$B
Number sets in cache = cache size / set size = $2^{14}/2^7=2^7=128$
$\rightarrow$ SET_BITS = 7
$= 32 - 7 - 2 = 23 $ bits

Why above calculations are wrong? @Arjun sir can you please have a look at this?
Even im getting 23 bits as answer using the same method.


The number of bits needed for the word field is not 2, it's 5

As you said, size of a word is 4 Bytes, and since 1 block contains 8 words, the size of a block is 32 B.

So, to uniquely identify a word from a block, we need 5 bits ( cause 2^5 = 32 )

This is how we get no. of tag bits = 32 - 5 - 7 = 20

+24 votes

 Irrespective of byte or word addressable system number of bits required for TAG won't get affected

Let us fist assume that system is byte addressable

So to proceed ahead convert everything in byte addressable format

Block size= 32byte

Number of blocks in main memory= 16KB/32B= 512 blocks

Number of sets = 512/4= 128 sets

Format is TAG |SET | BLOCK

Set= 7 bit,

block = 5 bit,

tag = 32-5-7=20 bits


Now let us consider word addressable system

Convert everything with respect to word

Cache size is 4K words, physical address space is 1G words

Number of blocks in cache= 4K/8=512 blocks

Number of sets = 128 sets

Format = Tag| set | word

Set = 7 bit

Word = 3 bit

Tag =30-7-3= 20 bits


Conclusion irrespective of byte or word addressable system number of bits required for TAG won't be affected provided we define everything as per byte addressable or word addressable system

by Boss (18.3k points)
edited by
After reading this question,it seems to hard to solve.But, reading this conclusion ,now it is quite easy.
correct it ... # of sets = 512 / 4 = 128 ...nt 127 ....
@Srestha,@Shaik Masthan,Please may I know one thing?Here as word addressable system is mentioned for the second part, then accordingly how 4K words is assumed when the capacity is 16 KB. Also why are we dividing by 8?Please may I know,when the word size is 32 bits. Thanks again. :)

" The word length is 32 bits."

that means word addressable

@Srestha,This I understood. But why 4k when capacity is 16kb of cache?Please help with this. :)
32 bits word length=4B

Cache capacity of 16 KB, which is Byte addressable format

To change it to word addressable $\frac{16KB}{4B}=4K word$
@Srestha,Now I got it. Thanks a lot. :)
Thankssss a lot! Saved me
This should be the best answer with proper editing.
+1 vote

We try to convert in one format either byte addressable or word addressable.both case we will get same tag bits .


by Boss (35.7k points)

Total number of bits in a physical address should remain be same either u r doing with Byte addressable format(means converting evreything in to bytes) or word addressable please reply if i m wrong somewhere 

0 votes
> Total address length = bits required to represent no of words in Physical Address Space =  Log (Physical address size / Word size)

= Log(4 GB / 32 bits) = 30

> Block size = 8 words = 8 * 32 bits = 32 Bytes

> Bits required for set field = log (cache size / (block size * associativity)) = log(16 KB / (32 Bytes * 4)) = 7

> Bits required for word field = log (no of words in each block) = log 8 = 3

> So bits required for Tag field = 30 - 7 - 3 = 20 bits.
by Active (1k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,645 questions
56,597 answers
102,140 users