In general, having higher associativity leads to
fewer cache misses. However, this general rule doesn't always
hold true. Consider the following code:
for (i=0; i<10; i++)
for (j=0; j<600; j++)
sum += a[i]*b[j];
Suppose all data items are 4 Bytes long, and there is a 2KB cache
with a line size of 16 Bytes.
- Suppose the cache is fully-associative with LRU replacement.
Approximately how many cache misses will there be?
(Don't bother counting misses associated with the "a" array
or the scalars i, j, and sum. Assume the cache is initially
empty.)
- Now suppose the cache is direct mapped. Approximately
how many cache misses will there be?