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

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

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?

+6

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?

+1

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

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

+1 vote

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.

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

- All categories
- General Aptitude 1.9k
- Engineering Mathematics 7.5k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.1k
- Non GATE 1.5k
- Others 1.5k
- Admissions 595
- Exam Queries 576
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 17

50,645 questions

56,597 answers

195,837 comments

102,140 users