# CS计算机代考程序代写 cache Q1 Locality 4 Points

Q1 Locality 4 Points
The following function sums up the elements in an array:
Q1.1
1 Point
What type of locality does the variable “sum” benefit from, assuming the code is highly optimized?
 Spatial locality
 Temporal locality
 Both temporal and spatial locality
 None, as sum will be put in register %rax instead of in memory.
Q1.2
1 Point

The loop needs to read an element of array a in each iteration. What type of locality can that array access benefit from?
 Temporal locality
 Spatial locality
 Both temporal and spatial locality  None
Q1.3
1 Point
If we change the loop body from
sum += a[i][j];
into
if(j>0) {sum += a[i][j] – a[i][j-1]};
What type of locality can that array access to a[i][j-1] benefit from?  Temporal locality
 Spatial locality
 Both temporal and spatial locality
 None
Q1.4
1 Point
Program execution uses memory accesses to fetch not only data but also code from physical memory. For example, near the end of the execution of sumA , the program needs to fetch the ret instruction from memory. What type of locality can that memory access benefit from during the first execution of sumA?

 Temporal locality
 Spatial locality
 Both temporal and spatial locality  None
Q2 Caches 4 Points
You are given the a direct mapping cache (i.e., each set only contains one cache line block). Each cache line block is 64-Byte long; the whole cache capacity is 2048 Bytes; every memory address on this machine contains 32 bits.
Q2.1
1 Point
How many sets (S) does this cache have?
2 8  32  64  128
Q2.2
1 Point
While accessing the cache, how many bits in each memory address are used to locate the set?

2 3 4 5 6
Q2.3
1 Point
How many tag bits (t) does this cache use?
 21  24  26  27
Q2.4
1 Point
Right after an access to memory location 0XAB3F, accessing which memory location below is guaranteed to get a cache hit?
 0xAB08  0xAA3F  0xAC3F  0xAB40