In: Computer Science
Assume a computer with a cache that holds 64 bytes and has a block size of 32 bytes. Direct address mapping is used and from the beginning the cache is empty. The following program sequence is executed:
for (col = 0; col < 2; col++) {
for (row = 0; row < 4; row++)
A[row][col] = B[row] * C[col]; }
Assume that for the variables row and col registers are
used.
The matrix A consists of 4 rows and 4 columns with integers (one
word long). A is located in the RAM with start address 0 and is
stored in rows (A [0] [0], A [0] [1], ... ).
Array B consists of 4 integers (one word long). B is located in RAM
with start address 64.
The arrayC consists of 4 integers (one word long). C is located in
RAM with start address 80.
What will be the hit probability for the program sequence? What
will be the hit probability if 2-way set associative address
mapping (with LRU when changing blocks) is used instead of direct
address mapping? Also write explanations of how the calculations
are done and interpret the results. (Note that the outer loop runs
twice and the inner one four times. There will be a total of 24
memory references.)
Number of lines in cache
= Cache size / Line size
= 32 words / 8 words
= 4 lines
Since each element of the array occupies 4 words, so-
Number of elements that can be placed in one line = 2
Now, let us analyze the statement-
A[i] = A[i] + 10;
For each i,
Thus,
Assume the cache is all empty initially.
In the first loop iteration,
In the second loop iteration,
In the similar manner, for every next two consecutive elements-
Likewise, for 100 elements, we will have 50 such pairs in cache and in every pair, there will be one miss and three hits.
Thus,
Thus,