The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+15 votes
6.1k views
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 ____
asked in CO & Architecture by Veteran (99.8k points)
retagged by | 6.1k views

2 Answers

+30 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.
answered by Veteran (355k points)
edited by
0
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.
0
8M words = 1M blocks since block size is 8 words. Now, 1M = 2^20. So, to address 2^20 blocks we need 20 bits.
+2
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?
+5
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)
0
"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.
+3
yes. Unless specified use byte addressing.
0
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
TAG_BITS = ADDRESS_BITS $-$ SET_BITS $-$ WORD_BITS
$= 32 - 7 - 2 = 23 $ bits

Why above calculations are wrong? @Arjun sir can you please have a look at this?
+9 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

answered by Boss (16.2k points)
edited by
+1
After reading this question,it seems to hard to solve.But, reading this conclusion ,now it is quite easy.
+2
correct it ... # of sets = 512 / 4 = 128 ...nt 127 ....
0
@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. :)
0

" The word length is 32 bits."

that means word addressable

0
@Srestha,This I understood. But why 4k when capacity is 16kb of cache?Please help with this. :)
0
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$
0
@Srestha,Now I got it. Thanks a lot. :)


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

38,053 questions
45,543 answers
131,853 comments
48,880 users