Spatial Locality in Cache – Which addresses are loaded

cachememory

I don't understand quite well the concept of spatial locality in cache. I understand that when there is a miss in the cache, not only the specific address we write is loaded into the cache, but also "near by addresses'' are loaded too.

However, I can't understand WHICH addresses are loaded. I have an assignment with the following question:

The cache consists of 16 words (4 bytes per word). It is arranged in blocks of 2 words.
The following addresses are in BYTES in decimal base. The cache is initially empty.
12,8,24,28,36,44,48,52,60,64,68,76,136,140,144,148,152,220,224,228,220,224,228
Determine what are the addresses which are a MISS (determine if valid/tag miss).

What is hard for me is to understand which addresses are loaded, when, for example, the address 12 is reached. Is 13 loaded into the cache? 14? 15? or maybe 11? How do I know that?

I think that if understand this fundamental question, I could answer this question with ease.

Thank you.

Best Answer

When they say that the cache block size is two words, that means that 2 words, or 8 bytes of data is transferred to the cache whenever a miss occurs. You can think of main memory as being divided into groups of 8 bytes, on 8-byte boundaries (0-7, 8-15, 16-23, etc.). Whenever any byte in one of those groups is accessed, the entire group is loaded into a cache block.

So, for example, when byte 12 is accessed, all of the bytes from 8 to 15 are loaded into the cache. As long as that block remains in the cache, any subsequent accesses to any of those bytes will result in a cache hit, rather than a miss.

Note that the cache can only hold a total of 8 blocks (16 words / 2 words per block). This means that if you access a byte that's in a ninth block, you're going to have to remove a block from the cache first. Selecting which block to remove is an entirely separate topic that is the subject of much debate. Since the problem doesn't specify a cache replacement strategy, I'm guessing that it doesn't matter for this particular example.