You are on page 1of 2

HW #6 – Due 15/10

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) This series of word addresses is accessed:

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).

Address DM Line Cached Word


2 Miss-CS 0 16 64 48
3 Miss-CS 1
11 Miss-CS 2 2
16 Miss-CS 3 3 19 3
21 Miss-CS 4 4
13 Miss-CS 5 21
64 Miss-CS 6 22 6
48 Miss-CS 7
19 Miss-CS 8
11 Hit 9
3 Miss-Conflict w/19 10
22 Miss-CS 11 11 27 11
4 Miss-CS 12
27 Miss-CS 13 13
6 Miss-CS 14
11 Miss-Conflict w/27 15
16

3) Repeat Problem 2, but now assume that the cache is direct-mapped, 4-word blocks, total 16
word capacity.

Address 4-Word Block # DM Line Cached Blocks


2 0 Miss-CS 0 0 4 16 12 4 0
3 0 Hit 1 51
11 2 Miss-CS 2 262
16 4 Miss-CS 3 3
21 5 Miss-CS

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

You might also like