编程辅导 Name: ID#:

Name: ID#:
X.500:
CS 2021: Practice Exam 3
Fall 2021 University of Minnesota
Exam period: 20 minutes Points available: 40
Below is an initial memory/cache configuration along with several memory load operations. Indicate whether these load operations result in cache hits or misses and show the state of the cache after these loads complete.
MAIN MEMORY DIRECT-MAPPED Cache, 8-byte lines
| Addr | Addr Bits | Value | 4 Sets, 8-bit Address = 3-bit tag
|——+—————-+——-|
Problem 1 (10 pts):
|10|00010000
| 14|000 10 100
| 18|000 11 000
| 1C | 000 11 100 | 13 | |—–+—+—–+————-|
| 20|001
| 24|001
| 28|001
| 2C|001
| 30|001
| 34|001
| 38|001
| 3C|001
| 40|010
| 44|010
| 48|010
| 4C|010 |——+—————-+——-| | |TagSetOffset| |
| 10|INITIALCACHESTATE
| 11| | | | | Blocks/Line | | 12| |Set|V|Tag|0-3 4-7 |
|00|1| 010 |01|1| 001 |10|1| 000 |11|0| –
HITS OR MISSES?
| OPEARTION |————–+———–| |1.Load0x48| | |2.Load0x4C| | |3.Load0x24| |
FINAL CACHE STATE
| || | Blocks/Line |
| Set |V| Tag | 0-3 4-7 | |—–+—+—–+————-+———-| |00||| | | |01||| | | |10||| | | |11||| | |
read in a free online blog post “Memory for Morons” that there is no need to invest much money in buying RAM. Instead, one can configure the operating system’s virtual memory system to use disk space as main memory leading to a much less expensive computer with a seemingly large memory. Pyra is quite excited about this as some programs she wants to execute fast need a lot of main memory and it would be nice to save some cash. Advise her on any risks or performance drawbacks she may encounter using such an approach.
Problem 2 (5 pts):
00 000
00 100
01 000
01 100
10 000
10 100
11 000
11 100
00 000
00 100
01 000
01 100
| 20| | 21| | 22| | 23| | 100 | | 101 | | 102 | | 103 | | 200 | | 201 | | 202 | | 203 |
| 200 201 | |2223 | |1011 | |- |
| HIT/MISS? |
| Changed? |
1/ 2

7 8 9
10 11 12 13
WRITE ON EVERY PAGE – Name:
Problem 3 (15 pts): Nearby is the definition for base scalvec() which scales a vector by multiplying each element by a number. Write an optimized ver- sion of this function in the space provided. Mention in comments why you performed certain transforma- tions.
void base_scalevec(vector_t *vec, int *scale){
for(int i=0; i < vec->len; i++){
int cur = vget(*vec,i);
int new = cur * (*scale);
vset(*vec,i,new);
} }
int vget(vector_t vec, int idx){
return vec.data[idx];
1
2
3}
4 void vset(vector_t vec, int idx, int x){ 5 vec.data[idx] = x;
6}
Problem 4 (10 pts): Examine the two functions be- low which add elements of a row or column vector to all corresponding rows or columns of a matrix. Consider the benchmark timing of these two provided.
1. Explain which of these two functions is faster and why.
1 // add given row to each row of mat
2 void matrix_addrow_vec(matrix_t mat,
3 vector_t row) { 4 for(int i=0; i