Professional Documents
Culture Documents
1) What kind of program would you expect to show lots of temporal locality but not much
spatial locality? How about lots of spatial locality, but not much temporal? Describe in
either C/Java style pseudocode or in words.
[Based on Hennessy and Patterson 7.3, 7 .4]
One example of a program with lots of temporal but little spatial locality is one that
increments one integer inside each element of vector of class objects 1000 times. There is no
guarantee that each integer in the vector are physically next to each other (they probably
aren’t since each classFoo object has 1 integer and 75 floating point numbers), but each one
is reused 1000 times before moving on to the next one.
class classFoo{ vector <classFoo> cF(10);
int onlyInt; for(j = 0; j <cF.size(); j++){
vector <float> bunchAFloats(75); for(i = 0; i < 1000; i++){
} cF.at(j).onlyInt = cF.at(j).onlyInt + 1;
}
}
One example of a program with lots of spatial but little temporal locality is one that
increments all elements of a vector 1000 times in this manner. In this case, each integer in
the vector is right next to each other, but we only access each one once or twice before
moving on to the next.
vector <float> floatVector(75);
for(i = 0; i < 1000; i++){
for(j = 0; j < floatVector.size(); j++){
floatVector.at(j) = floatVector.at(j) + 1;
}
}
2, 3, 11, 16, 21, 13, 64, 48, 19, 11, 3, 22, 4, 27, 6, 11
Assume a direct-mapped cache with 16 one-word blocks that is initially empty. Label each
address request and show the final contents of the cache. If there is a cache miss, indicate
what type of miss it is (compulsory/conflict (with what)/capacity miss).
3) Repeat Problem 2, but now assume that the cache is direct-mapped, 4-word blocks, total 16
word capacity.
13 3 Miss-CS
64 16 Miss-CS
48 12 Miss-CS
19 4 Miss-Conflict w/16
11 2 Hit
3 0 Miss-Conflict w/4
22 5 Hit
4 1 Miss-CS
27 6 Miss-CS
6 1 Hit
11 2 Miss-Conflict w/6