10/27/21, 1:12 PM HW7.3 - CS 61C | PrairieLearn
https://cbt-dev.berkeley.edu/pl/course_instance/50/instance_question/1345714/ 1/1
HW7.3. Homework 7 Cache Programming
The following C program is run (with no optimization) on a processor with a direct-mapped
data cache with a size of 1 KiB and a block size of 32 bytes:
int i, j, array[256*256];
/* ... */
for (i = 1 ; i < 256 ; i++) {
for (j = 0 ; j < 256 ; j++) {
array[256*j] += array[256*j+i];
}
}
Assume sizeof(int) == 4 and array == 0x4000.
1a: For the first iteration of the outer loop (i = 1), what is the hit rate of this code?
1b: After the first n iterations of the outer loop, the hit rate changes. What is n, and what is the
new hit rate of each iteration of the outer loop?
1c: What is the overall hit rate of this code?
2: We decide to rewrite our code to be more cache-efficient, while maintaining the same
behavior. Fill in the blanks of this code (write your answers in the same format as the original
code):
int i, j, array[256*256];
/* ... */
for ([CODE A]; i < 256 ; i++) {
for ([CODE B]; j < 256 ; j++) {
array[[CODE C]] += array[[CODE D]];
}
}
3: What is the new hit rate of this code?
Hit Rate= number (2 significant figures)
n= integer
Hit Rate= number (2 significant figures)
Hit Rate= number (2 significant figures)
CODE A:
CODE B:
CODE C:
CODE D:
Hit Rate= number (2 significant figures)
Save & Grade 20 attempts left Save only Additional attempts available with new variants
Previous question
Homework 7
Assessment overview
Total points: 30/100
Score: 30%
Question
Value:
History:
Awarded points:
Report an error in this question
40
0/40
Next question
Attached files
No attached files
Attach a file
Attach text
2
学霸联盟学霸联盟