3
$\begingroup$

I'm going through an exercise trying to store address references into a direct mapped cache with 128 blocks and a block size of 32 bytes. The address are 20000, 20004, 20008, and 20016 in base 10.

When I start to store them, I realize that the offset is the only value that changes. All of the examples I find determine hits and misses based on the target and index values, without mention of offset. What is the purpose of the offset? If the tag and index are in the cache, is it a hit regardless of the offset? Or is the offset also looked at?

$\endgroup$

1 Answer 1

2
$\begingroup$

If the cache blocks are not sectored, then if the tag field matches any offset within the block will be a hit. With sectoring a cache block can have multiple valid bits, in which case the tag might match but the valid bit for the section corresponding to the offset might be cleared (indicating that the section is invalid).

In theory a valid bit could be provided for every smallest unit of access (commonly an 8-bit byte), but sectoring is more commonly used to allow an outer level of cache to use a larger block size than L1 caches without forcing all the data associated with a tag to be invalidated when the smaller unit needs to be. For an inclusive cache, this avoids unnecessary back-invalidation of L1 cache. (It would also be possible to include fully independent coherence state, e.g., MESI, rather than just validity. This could be used to avoid unnecessary writebacks, e.g.)

Sectoring can also be used to directly fill the cache and allow early restart; alternatives include using a side (fill) buffer with extra valid bits (similar to a write buffer) and waiting for the entire cache block is loaded before restarting execution.

To confuse matters, Intel uses cache line to indicate the smaller unit that shares a tag with other lines in a sector while some others use cache block/line for the larger unit with the term sector used for the portion that can be individually invalidated.

For the level of complexity for this type of exercise, one can reasonably assume that sectoring is not used, so a tag match would indicate a hit regardless of the offset.

$\endgroup$
2
  • $\begingroup$ Thanks for your response. I haven't learned about sectoring yet, so for this exercise I assume it is without sectoring. But I was told that they should all be miss. The examples I've found online use both tag AND index to determine if there is a hit. I haven't found any examples that even use an offset, so I can't figure out what role that plays in the direct map cache. $\endgroup$
    – danb
    Commented Jul 21, 2014 at 23:54
  • $\begingroup$ @dddd The offset is basically only used to select the appropriate chunk (the size of the access width) within the cache block. If the four listed accesses were all writes and the cache was no-write allocate (common for small direct-mapped caches), then they would all be misses because the block would not be allocated to the cache after a write miss. However, the four accesses share the same index and tag (assuming byte and not word addressing), so once one is loaded into the cache they would all hit until a conflicting allocation kicks the block out of the cache. $\endgroup$
    – user4577
    Commented Jul 22, 2014 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.