r/AskComputerScience • u/Puzzleheaded-Tap-498 • Jun 11 '25
MIPS CPU pipelining: why does the HDU check if the instruction at IF/ID is using the rs/rt operands, but the Forwarding Unit does not?
for context, I am currently studying about load-use hazards and the construction of the HDU. it's written in my textbook that the HDU detects whether the instruction at it's second cycle (IF/ID) uses it's rs/rt operands (such as the add, sub... instructions) or not (such as I-type instructions, jump instructions...), and ignores them if not.
it's then written that the Forwarding Unit will check instructions regardless of whether the instruction has rs/rt fields. then we are told to "think why".
I have no idea. did I understand the information correctly? is there ever a situation where there is a data hazard, if we don't even refrence the same register multiple times in the span of the writing instruction's execution?
1
u/ghjm MSCS, CS Pro (20+) Jun 11 '25
I don't know for sure, but if you had
Presumably the FU needs to detect, during the jump instruction, that the value in $t2 isn't fully written yet.
1
u/computerarchitect MSCS, CS Pro (10+) Jun 12 '25
Provide more context? Keep in mind that the author might just be flat out wrong. I can't tell what they're thinking or what they want you to think without more context. Ultimately to me a forwarding unit in the context of your question needs to be checking source register indices against destination register indices.
A data hazard occurs when older data could be used when a newer result is available, which is what I think you're trying to say. If the most up to date value is stored in the register file at the time you read from the register file, there is no hazard.
Loads and stores suffer from data hazards as well, but that's graduate level material typically.
1
u/Lil_Biggums2K Jun 14 '25
When the HDU detects a load-use RAW hazard, it inserts a bubble/stall in the pipeline, which by design hurts performance but maintains functional correctness. You only want to do this when you absolutely have to due to the worsened performance caused by the stall. You only absolutely have to if the instruction actually needs its rs/rt register which comes from a matching load register write.
Forwarding, on the other hand, does not create any bubbles or stalls. It is definitely required for functional correctness when there is a rs/rt register match and the rs/rt is needed. However when the rs/rt is not used, it is fine to uselessly forward the value as it will be naturally ignored by the pipeline.
As to why you would purposely not check if rs/rt is needed in the forwarding case: the combinational logic hardware to implement forwarding will be simplified if it doesn’t have to check if rs/rt is actually needed.