Caching: Actual role of byte offset field in the cache address?

  • Thread starter Thread starter bremenfallturm
  • Start date Start date
AI Thread Summary
The discussion centers on the practical application of the "byte offset" field in a direct-mapped instruction cache for a 32-bit RISCV processor. The example provided involves a cache with 16 sets and an 8-byte block size, leading to a 3-bit byte offset field. A key point raised is the discrepancy between theoretical byte offset values and practical implementation, where the byte offset is often simplified to only utilize certain bits in hardware, such as a MUX with limited inputs. This raises questions about how caches handle data retrieval, particularly when accessing different byte offsets within a block. The consensus is that caches typically return the entire word associated with the byte offset, regardless of the specific offset value, which is dependent on the implementation details of the cache system. The discussion emphasizes the need to refer to specific course materials or hardware datasheets for accurate implementation details.
bremenfallturm
Messages
81
Reaction score
13
TL;DR Summary
Something that I can't seem to find a good explanation of online is how the "byte offset" field in the cache address is used practically. In the examples I have seen, it seems to only give different outputs for some of the byte values (only returning a word at a time)
Hi!

Something that I can't seem to find a good explanation of online is how the "byte offset" field in the cache address is used practically.

For example, take this example from the course I am currently taking:

Assume that we have a 32-bit RISCV processor with a direct mapped instruction cache.
Assume further that the number of sets (also called rows) are 16, and the block size is 8
bytes.

Draw the hardware implementation for reading from the instruction cache.


In this example, we have a direct-mapped cache, and this cache has 8 bytes per block. So the number of bits in the byte offset field is ##\log_2(8)=3## bits.

The question asks for a hardware implementation of the cache. While there are 8 bytes stored per block and the byte offset field can take any value from 0 to 8, in the solution key, the byte offset field is wired to a MUX with only two inputs (0 and 1), and we only use bit 2 of the byte offset field in practise. See the screenshot of the solution key below and look at the MUX wired to byte offset, and you'll hopefully see what I mean!


1735318931764.png

If I read my course book, they have an example (Figure 8.7) where they instead of 8 bytes have a similar direct-mapped cache, but with 4 bytes (1 word in their context) in the data field. Since they have only one word in each block, they say: "the byte offset bits, are ignored for word accesses."



So, even though the byte offset field in theory for a cache storing ##m## bytes of data can take on values ##0,1,...m## caches will generally return the whole word that the passed byte offset is associated with? For example, returning to the question I mentioned in the quote above and the 8 bytes data per block, accessing addresses on byte offsets 0,1,2, and 3 would all return the same data from the cache, it would return the whole least signifcant word stored in the block.

I hope my question is understandable:)
 
Technology news on Phys.org
bremenfallturm said:
I hope my question is understandable:)
Not really, and in any case the answer is implementation dependent. Refer to your course materials or the datasheet for the specific hardware implentation (if any).
 
Ah, sorry for not getting my point across. Anyways, I will simply assume that the case for the implementations my course has been discussing is that the cache returns a word at a time, regardless if the byte offset points to the beginning of a word in the cache or not.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top