I'm studying compute rarchitecture and read that "control hazard are worse the deeper the pipeline is". But why is this the case? Is the branch deeper and therefore takes longer time to run?
1 Answer
If a control hazard isn't taken care of properly, the program is forced to wait until an instruction is finished before it can move on to the next instruction and thus performance is dramatically slowed down. This event usually occurs when we don't really know what the next instruction will be in the program. It wastes time, which is why we need pipelining so that we can do multiple things while we are waiting for an instruction to finish.
From a textbook I had when I was in college studying computer architecture: "Suppose our laundry crew was given the happy task of cleaning the uniforms of a football team. Given how filthy the laundry is, we need to determine whether the detergent and water temperature setting we select are strong enough to get the uniforms clean but not so strong that the uniforms wear out sooner. In our laundry pipeline, we have to wait until the second stage to examine the dry uniform to see if we need to change the washer setup or not."
But there are ways to avoid the issue:
- Stalling until the branch is finished
- Predict if a branch is taken
- Predict if a branch is not taken
- Delay the branch after an instruction