Solution of Control Dependency

Last Updated : 14 Nov, 2025

When a jump happens in the program, the computer might fetch the wrong instruction by mistake. This wrong instruction runs and can mess up the program. This problem is called control dependency. To fix it, we stop fetching new instructions for a moment.

  • We do this by putting a "NOP" (do-nothing) instruction right after the jump.
  • This stopping action is called freezing the pipeline.
solution_of_control_dependency

Pipeline Freeze + NOP (Flush & Stall)

Technique: Insert NOP after branch → Freeze the pipeline

AddressInstruction
1000I₁
1001I₂
1002I₃ (JMP .2000)
1003NOP
1004I₄
......
2000B.I₁
2001B.I₂

Note: The NOP is inserted after the jump to freeze the pipeline and prevent unwanted instructions from being fetched.

InstructionC1C2C3C4C5C6
I₁IF (PC: 1001)IDEXMAWB
I₂IF (PC: 1002)IDEXMAWB
I₃IF (PC: 1003)Unconditional TOC ID (PC: 2000, PC: 2004)EXMA
I₄IF (PC: 2000, PC: 2004)IDEX
B1₁IF (PC: 2001)ID
B1₂IF (PC: 2002)

Key Points:

  • I₃ = Unconditional branch (jump) instruction
  • NOP inserted = Delayed branch slot filled with No Operation
  • Actual sequence: I₁ → I₂ → I₃ → NOP → B1₁ → B1₂
  • PC values: Shows branch target address (2000) and next sequential address (2004)
  • Stage abbreviations: IF = Fetch, ID = Decode, EX = Execute, MA = Memory Access, WB = Write Back

This demonstrates delayed branching in action - the NOP instruction executes while the branch is resolved.

Branch Prediction

Predict the outcome of a branch before it is resolved to avoid stalling. Branch Prediction is divided into two types:

  1. Static → Fixed guess (same every time)
  2. Dynamic → Changes based on past behavior

Static Branch Prediction

  • Branch is always Taken: In this we Assume Every time Branch is Taken. So the next instruction address is Target Address of the branch instruction.
  • Branch is Never Taken: In this we Assume Branch is never taken, so the next instruction address is the next sequential instruction address.

Dynamic Predictors:

  • 1-bit Predictor: Remembers last outcome
  • 2-bit Saturating Counter: More robust (hysteresis)
  • Correlating Predictor: Uses global/local history
  • GShare / Perceptron / TAGE: Advanced tournament predictors (used in modern CPUs)

Benefit: Reduces misprediction penalty (e.g., Intel/AMD use TAGE-like predictors)

Note: If Prediction goes Wrong (Wrong Prediction) then have to Suffer Stalls.

Delayed Branch

It is a compiler technique, so the compiler rearranges the code, if possible, to arrange or substitute the NOP instruction after the branch instruction. If not possible to rearrange, it preserves the execution path.

Note: To minimize the control dependency stalls, a software technique is used i.e., Delayed Branch.

Comment

Explore