• retagged by
2,010 views
4 4 votes

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:

for(int i=0; i<200; i++)
A[i] = A[i]+5

  1.   0.85
  2.  0.65
  3.   0.95
  4.   0.75

3 Answers

4 4 votes
In the cache, there will be 4 blocks as 1 block=16 words. Now In main memory, we will require 100 blocks to hold the 200 elements of the array. Further, In one block there can be two elements present.

And each element of the array is referred two times.

At first, it will generate miss for A[0] while reading the value of A[0] but when it comes to writing its value, the reference will be a hit as the element is already present in the cache. For A[1] both for reading and writing it will be a hit coz it is already in cache because it was present in the same block as that of A[0].

So For each block, there will be 3 hits and 1 miss

hit ratio=total hits/total references

            =(3*100)/2*200

            =0.75
0 0 votes
For one instruction A[i] = A[i] + 5;

          No. of hits = 1 +1 + 1 = 3

          No. of misses = 1

For 200 instructions,

          No. of hits =  3 * 200 = 600

          No. of misses = 1 * 200 = 200

hit ratio = 600 / (600 + 200) = 0.75
0 0 votes

Read A[0] will bring A[0], A[1] in cache with one miss 

now write A[0], read A[1] and write A[1] will be hit 

and this will continue upto A[198], A[199]

Position:
Show:

Related questions

8 8 votes
4 answers 4 answers
7.8k
7.8k views
shekhar chauhan asked Jul 20, 2016
7,760 views
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 0 votes
1 1 answer
2.6k
2.6k views
nirupama thakur asked Mar 17, 2018
2,600 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...
5 5 votes
1 answers 1 answer
4.2k
4.2k views
shekhar chauhan asked Jul 20, 2016
4,195 views
Consider an array has 100 elements and each element occupies 4 words .A 32 bit word cache is used and divided into a block of 8 words .What is the hit rate of this for(i=...
0 0 votes
0 0 answers
259
259 views
Burak_Düzenli asked Nov 24, 2024
259 views
The following code snippet is executed on a system that uses a cache with a size of 128 bytes and a block size (1 row width) of 32 bytes. The array holds 2-byte int value...