0

There are a multitude of different instructions in MIPS. I'm currently learning about data and instruction cache.

Instruction cache simply takes what it can so to say, depending on the block size it might utilize spatial locality and fetch multiple instructions. But for data cache I have a harder time understanding when it fetches things from main memory and when it doesn't.

For example, the instruction lw $t0, 0x4C($0) will fetch a word of data stored in address 0x4C and depending on data cache capacity, sets, block size and so forth it will temporarily store in in a block in the cache if for that adress the valid bit or tag doesn't exist there.

In my litterature, an addi instruction does not fetch from memory, why? The only times it seems to need to fetch data from memory is when using the lw instruction, why?

I also have a question regarding registers in MIPS. If we're simply doing the instructions over the registers, then there will be no access to any main memory, correct? It will not even go to the data cache, correct? Are the registers the highest level in the memory heirarchy?

Don_twice
  • 41
  • 1
  • 6
  • These are decisions of the designers. There are alternatives, and these choices met their criteria. One would have to look for the underlying philosophy and drivers and motivations around RISC architecture – Erik Eidt Nov 12 '21 at 14:15
  • I understand, but it's very hard for me to figure out the hit-rate for a data cache when I dont understand which instructions would need to be fetched from memory in the first place :/ – Don_twice Nov 12 '21 at 15:43
  • All instructions are fetched from memory ;) Anyway MIPS is a load-store architecture, so only loads and stores touch the data cache. The other instructions only affect registers. – Erik Eidt Nov 12 '21 at 20:29
  • If you need more info consult Wikipedia article on RISC. Also, look for the MIPS green sheet, that tells, on one page, what each instruction does, and hence, whether data memory is accessed. – Erik Eidt Nov 12 '21 at 20:49
  • Thank you so much for your reply!! :) – Don_twice Nov 12 '21 at 22:19

1 Answers1

0

The reason addi doesn't "fetch from memory" is that it's using an immediate operand, as in, the program counter has already fetched the value that's going to be loaded. (Technically it is fetching from memory, since all code resides in some form of memory, but when literature refers to "memory" typically it's referring to a range of memory outside the program counter. When MIPS uses something like lw to load from memory, the CPU has no idea what value the destination register will have until the load is finished.

Just to illustrate this concept further, the original MIPS I architecture (which was used by the PlayStation 1) actually wouldn't finish loading from memory before the next instruction was already being worked on!

lw $t0,0($a0)    ;load from the address pointed to by $a0
addi $t0,$t0,5   ;the value in $t0 hasn't been updated yet so this won't have the desired result.

The easiest solution to this was to put a nop after every lw. Chances are the version of MIPS you're using doesn't have this problem, so don't worry about it.

puppydrum64
  • 1,598
  • 2
  • 15