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.

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+15 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 ____

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

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.

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.

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)

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

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.

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?

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?

+11 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

+1

After reading this question,it seems to hard to solve.But, reading this conclusion ,now it is quite easy.

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. :)

- All categories
- General Aptitude 1.4k
- Engineering Mathematics 5.9k
- Digital Logic 2.3k
- Programming & DS 4.3k
- Algorithms 3.7k
- Theory of Computation 4.6k
- Compiler Design 1.7k
- Databases 3.4k
- CO & Architecture 2.9k
- Computer Networks 3.4k
- Non GATE 1.2k
- Others 1.3k
- Admissions 506
- Exam Queries 482
- Tier 1 Placement Questions 22
- Job Queries 64
- Projects 15

40,903 questions

47,557 answers

146,279 comments

62,304 users