Consider an array A[100] & 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. Assume one block is read into cache in case of miss:
for(i=0;i<100;i++)
A[i]=A[i]+10
each array element is of 4 word & each cache block size is 8 words, so we load 8 words into cache.
When program tries to read A[0], for the first time it will be miss. Hence it will be brought to memory (& also A[1]). Next, A[1] will be hit. So, it will be like :
- A[0] - Miss
- A[1] - Hit
- A[2] - Miss
- A[3] - Hit
- .....
So hit ratio is 50% ? Am I wrong anywhere ?
I also have one more doubt. First when it tries to access A[0], it will be miss. And then when it brings A[0] to cache, CPU tries to access A[0] again, now it should be considered as hit ? Like,
- A[0] (Read) - Miss
- A[0] (Write) - Hit
- A[1] (Read) - Hit
- A[1] (Write) - Hit
If above is correct, then Hit ratio will be 75%.
Any help regarding this is appreciated.