A 2-way set associative cache consists of four sets. Main memory contains 2K blocks of eight words each.
a) Show the main memory address format that allows us to map addresses from main memory to cache. Be sure to include the fields as well as their sizes.
b) Compute the hit ratio for a program that loops 3 times from locations 8 to 51 in main memory. You may leave the hit ratio in terms of a fraction.
Hello Sir, I am write now solving sums from "The essentials of Computer architecture " I got this sum . and there is no solution provided i just wanna ask you to check this
Solution :
No of lines in a set=2
No of set in Cache = 4
Block size=8 words
So, Size of each cache= No of set* No of line in set * Block Size= 8*4*2=64 Words
Size of MM= no of block in main memory * size of each block=(2^11)*(2^3)= 2^14 words
Bits used to represent Physical address = 14 bits
Field of Cache address will be
1. word offset = 3 bits
2. index bits = 2 bits
3.Therefore no of bits used to represent Tag field =(14-(3+2)) = 9 bits.
Now the solution for part b
Since the size of both memory is expressed in words
We have a cache size/ capacity = 64 words and Size of Main Memory as( 2 ^ 14 words )
And since the loop says it starts from location 8 to 51 then . No of elements that will be encountered = (51-8+1)= 44 which is equivalent for running i from 0 to 43 times (for 44 words )
Since they have asked for 3 iteration,
we know that size of cache= 64 words
And the required data that we have is 44 words
Out of these 44 words there would be 22 words which would be mapped to set 0 and 22 words which would be mapped to Set 1
Now in each Set , we have 2 lines and Each block has a size of 8 words ,
So in 16 words we have would have 2 miss
And so in reamining in (22-16) words we would have 6 words . to accomodate these 6 words again 1 block need to replaced
So total miss in 1 set in first iteration is 3 miss
Similarly total miss in second set in first iteration = 3 miss
Total no of miss in first iteration = 6 miss
While in second iteration there would be again need of replacing 1 block to (first 8 words ) rest would be hit till and then again 1 miss for (last 6 words ) this is just for 1 set
so total no of miss in second iteration=4 (both sets )
And similarly Total no of miss in third set = 4
And miss ratio would be equal to = (6+4+4)/(44+44+44)= 14/132.
Is this correct ? Please help . i am sorry to write such a big content . But this question need and to show my way of approaching towards sums :)