mtrn
mtrn

Reputation: 35

MIPS N-way associative cache

This is a question about memory organization which I have had very difficulty to understand,

Assume we have an N-way set associative cache with the capacity 4096bytes. The set field size of the address is 7 bits and the tag field 21 bits. If we assume that the cache is used together with a 32-bit processor, what is then the block size (in bytes), how many valid bits does the cache contain, and what is the associativity of the cache?

Upvotes: 1

Views: 1589

Answers (2)

Adam
Adam

Reputation: 846

Here are some equation that is good to know in order to solve question of these type.

Parameter to know

C = cache capacity
b = block size
B = number of blocks
N = degree of associativity
S = number of set
tag_bits
set_bits (also called index)
byte_offset
v = valid bits

Equations to know

B = C/b
S = B/N
b = 2^(byte_offset)
S = 2^(set_bits)

Memory Address

|___tag________|____set___|___byte offset_|

Now to the question

known:

C = 4096 bytes
set_bits = 7
tag_bits = 21
32 bits address field

Asked:

b?
N?
v?

Simply subtract the tag_bits and set_bits from the 32 bit field this gives you the byte_offset.

byte_offset = 32-21-7 = 4 bits

b = 2^4 = 16 bytes
S = 2^7 = 128 set
B = C/b = 4096/16 = 256
N = B/S = 256/128 = 2
v = B = 256 valid bits

Upvotes: 1

Rahul Behl
Rahul Behl

Reputation: 381

So, we have the following information about the processor and the cache -

Cache Size = 4096 B

Address bits = 32

Index bits = 7

Tag bits = 21

From the above information you can quickly calculate the number of bits required for the offset field -

Offset bits = Address bits - Tag bits - Index bits

Offset bits = 32 - 21 - 7 = 4

Offset bits = 4

Using the offset bits, you can find the block size, 2**offset bits

Block Size = 16 bytes

Next thing is the associativity of the cache We know that the index bits = 7. This means we have 128 blocks. Each block is 16 bytes wide.

Therefore, the number of ways in the cache would be -

Number of ways = Cache Size / (number of blocks * block Size)

Number of ways = 2 Hence the associativity is 2.

Regarding the number of valid bits. Each block requires a valid bit. Hence the number of valid bits would be -

Valid bits = 128*2

Valid bits = 256

Upvotes: 1

Related Questions