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

  • Thread starter Thread starter bremenfallturm
  • Start date Start date
bremenfallturm
Messages
80
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 want to ask as a beginning programmer, when should one learn to use vim/emacs beyond using an ide for a particular programming language? I know there are passionate debates over which of the two are better. For the purpose of my question, such debate would go over my head. I am only interested to know say if I started out in C, C++/Matlab, then plan to go onto assembly, and Haskell. But if I need to know an object oriented language or go to some other language in a...
Alice generates a random series of digits that define a key 0 < K < 1, using a physics based, nearly perfect random generator. She then calculates exp( Pi * K) / 4, or some such irrational number. She calculates as many decimal places as are required to encrypt the block of plain text. She converts the result to hexadecimal. She takes successive pairs of digits of this hex value and XORs them bytewise with the plain text characters. Finally, Alice inserts the hex digits of K among these...
Back
Top