Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|cite|improve this question
up vote 2 down vote accepted

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.

share|cite|improve this answer
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. – dddd Jul 21 '14 at 23:54
@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. – Paul A. Clayton Jul 22 '14 at 0:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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