Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[15 pts] Consider the following C program. It will run on a processor of a data

ID: 3718381 • Letter: #

Question

[15 pts] Consider the following C program. It will run on a processor of a data cache and ar instruction cache. For this question, ignore instruction cache miss (the instruction cache size is more than enough) 3. // double is 8-byte double Xr10241 double sum - 0.0; double max DBL MIN; // DBL MIN ?s minimum value for double sum +-- x [i] ; if (X[d] > max ) x [i] ; max = Assume that the start address of the array is a multiple of 32. [5 pts] Assume the cache is 16 KB, direct mapped, and of 32-byte blocks. How many cache misses will happen? Explain your result. a. b. [5 pts] Now assume the cache is 4 KB, direct mapped, and of 32-byte blocks. How many cache misses will happen? Explain your result. Pay attention to the difference in the cache size c. [5 pts] This question continues sub-question b). Revise the code to reduce the number of cache misses. Write down the code in the space below. You don't have to copy the declarations.

Explanation / Answer

1)

Assume array is sorted in row major order.

Initial for loop causes 1024 misses.

Block size is 32 bytes. So 32/8=4per cache line (Size of double =8)

Cache size=16 KB

Number of lines=Cache size/Bock size=16 KB/32=512

Therefore a total of 512*4=2048 array elements can be stored in cache when first loop executes.

For the second loop there is no cache miss since array size is just 1024.

Therefore total number of misses=1024 (Initial miss by first for loop).

2)

Assume array is sorted in row major order.

Initial for loop causes 1024 misses.

Block size is 32 bytes. So 32/8=4per cache line (Size of double =8)

Cache size=4 KB

Number of lines=Cache size/Bock size=4 KB/32=128

Therefore a total of 128*4=512 array elements can be stored in cache when first loop executes.

For the second loop number of cache misses =512 since array size is 1024.

Therefore total number of misses=1024+512=1536 (Initial miss by first for loop=1024 and 512 misses in second loop).

3)

Merge two loops to single loop. Only first loop is required.

for(int i=0;i<1024;i++)

{

sum+=x[i];

if(x[i]>max)

max=x[i];

}

The for loop causes 1024 misses.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote