🔄 Delayed Branch Pipeline

Understanding Branch Delays in Pipelined Processors

📋 Program Instructions

1. Load from memory to R1
2. Increment R2
3. Add R3 to R4
4. Subtract R5 from R6
5. Branch to address X

🎯 Pipeline Stage

I - Instruction Fetch
A - Address/Decode
E - Execute

Approach A: No-Operation Instructions

The compiler inserts two no-op instructions after the branch. The branch address X is transferred to PC in clock cycle 7.

Instruction 1 2 3 4 5 6 7 8 9 10
1. Load I A E
2. Increment I A E
3. Add I A E
4. Subtract I A E
5. Branch to X I A E
6. No-operation I A E
7. No-operation I A E
8. Instruction at X I A E
⚠️ Key Point: The instruction at X is delayed by two clock cycles due to the no-op instructions. It starts the fetch phase at clock cycle 8 after the program counter PC has been updated.

Approach B: Rearranging Instructions

The program is rearranged by placing the add and subtract instructions after the branch instruction. PC is updated to the value of X in clock cycle 5.

Instruction 1 2 3 4 5 6 7 8
1. Load I A E
2. Increment I A E
3. Branch to X I A E
4. Add I A E
5. Subtract I A E
6. Instruction at X I A E
✅ Optimization: The add and subtract instructions are fetched and executed in the proper sequence. The value of X is transferred to PC in clock cycle 5 in the E segment, so the instruction fetched at clock cycle 6 is from address 350 (the branch address).

📊 Comparison

Method A: No-Op Instructions

  • ✗ Wastes 2 clock cycles
  • ✗ Increases program size
  • ✓ Simple implementation
  • ✗ Lower performance

Method B: Instruction Rearrangement

  • ✓ No wasted cycles
  • ✓ Maintains program size
  • ✓ Better performance
  • ✗ Requires smart compiler
Start Learning Vector Processing