retagged by
5,206 views
8 votes
8 votes

Consider an array A[100] and each element occupies 4 word. A 32 word cache is used and divided into 8 word blocks. What is the hit ratio for the following statement.

for(i=0;i<100;i++)
  A[i]=A[i]+10

What mapping is going to be used in the Solution ?

retagged by

4 Answers

Best answer
11 votes
11 votes

According to the question, a block can have 2 elements. And each element has size of 4 words.

Now, the looping is given as follows ==>

for(i=0;i<100;i++)
  A[i]=A[i]+10

This means that for each value of i, we have to read the element first,and +10 shows that after reading , we have to add this constant value to the array element .

Hence, we will consider read and write cases now. Also, of the question was about just reading and no updating , then would have considered only read cases .

Now, first iteration will read first A[0] value, which is not there in the cache ( we have assumed cache to be initially empty), it will be a cache miss . 

Now, A[0] and A[1] cache block will be brought to the cache , and now write reference for A[0] is a hit, whereas, for A[1] ,both read and write access will be hits .

Hence, for a particular cache block , we have 1 miss and 3 hits .

Hence, hit ratio = 75% ..

selected by
1 votes
1 votes

Each cache block is of 8 words.

One array element is of 4 word size

Hence each block can store 2 array elements.

In the for loop, 

When i=0, cache miss, A[0] and A[1] are fetched

When i=1,cache hit

When i=2,cache miss, A[2] and A[3] are fetched

When i=3 cache hit

***************

When i=98, cache miss, A[98] and A[99] are fetched

When i=99 cache hit

So cache hit and miss come alternatively.hit ratio is 50% and set associative mapping is used

1 votes
1 votes
for(i=0;i<100;i++)
  A[i]=A[i]+10

Since cache clock size=8 words 

Each array element size is 4words 

Now in each cache block there exist two array elements like below way

A[0]A[1] A[2]A[3]   ........ A A[94]A[94] A[96]A[97] A[98]A[99]

So when ever we access A[0] then we can access both A[0]A[1]

A[0]     R(Miss)    W(Hit)

A[1]     R(Hit)         W(Hit)

Hit=3/4

Miss=1/4

0 votes
0 votes

According to the question size of block 8 words=3bits

No of  blocks=32/8 =22 = 2

Array A has 100 elements =400 words

Each block contain 8 words

So  in a block 1st one is hit and next 7 words are miss.

No of miss here 400/8 =50

Number of hits =350

So, hit ratio 350/400⨉100=87.5%

Related questions

4 votes
4 votes
3 answers
1
Parshu gate asked Nov 10, 2017
1,233 views
Consider an array A[200] and each element occupies 8-words. A 64-word cache is used and divided into 16-word blocks. What is the hit ratio for the following code segment:...
0 votes
0 votes
1 answer
3
nirupama thakur asked Mar 17, 2018
1,977 views
In some problems we multiply only with the second part of the equation with (1-H1) component and leave the first part. Whereas in other cases we multiply with cache hit a...