Instruction Pipelining: Stages, Speedup & Hazards
“Clock period = max(stage) + latch, RAW data stalls, forwarding, and speedup.”
1.The 5-Stage RISC Pipelined Execution Principle
§ 4.1.Pipelining overlaps the execution of multiple instructions across independent hardware execution stages:
1. IF (Instruction Fetch): Fetch instruction from cache using PC; increment PC ≤ftarrow PC + 4.
2. ID / RF (Instruction Decode / Register Fetch): Decode opcode and read operand registers from the register file.
3. EX (Execute / ALU): Perform arithmetic/logical operation or compute effective memory address.
4. MEM (Memory Access): Read or write data cache (LOAD/STORE instructions only).
5. WB (Write Back): Write the result back into destination register.
Clock Cycle Time (T_{clock}):
The pipeline clock period is determined by the slowest stage plus the pipeline register latch overhead:
T_{clock} = \max(Stage Delay_i) + Latch Delay.
Pipeline Performance Metrics:
- Ideal CPI of an in-order pipeline = 1.
- Speedup (S) for n instructions on a k-stage pipeline:
T_{nonpipe} = n × k × T_{clock}
T_{pipe} = [k + (n - 1)] × T_{clock}
S = \frac{n × k}{k + n - 1}. As n \to \infty, S \to k.
2.The Three Pipeline Hazards & RAW Forwarding
§ 4.2.A hazard is any condition that prevents the next instruction from executing in its designated clock cycle:
1. Structural Hazard: Two instructions compete for the same physical hardware resource in the same cycle (e.g., single memory port accessed by IF and MEM simultaneously). Solution: Separate L1 Instruction and Data caches (Harvard architecture).
2. Data Hazard (RAW - Read-After-Write): An instruction needs an operand produced by an earlier instruction that has not yet completed write-back. Three types exist:
- RAW (True Dependency): I_2 reads a register written by I_1. Occurs in in-order pipelines.
- WAR (Anti-Dependency): I_2 writes a register before I_1 reads it. Occurs only in out-of-order execution.
- WAW (Output Dependency): I_2 writes a register before I_1 writes it. Occurs only in out-of-order execution.
Remedies for RAW Hazards:
- Software/Hardware Stalls: Inserting bubble cycles.
- Operand Forwarding (Bypassing): Routing ALU result from EX/MEM or MEM/WB pipeline registers directly to the ALU input multiplexers, eliminating stalls for ALU-to-ALU dependencies!
- Load-Use Delay: A LOAD instruction produces its data at the end of the MEM stage. Even WITH forwarding, a dependent instruction immediately following a LOAD requires 1 stall bubble cycle.
In GATE problems, assume that the Register File is written during the FIRST half of the clock cycle (WB stage), and read during the SECOND half (ID stage). This allows an instruction to read the newly written value in the same clock cycle without an extra stall!
3. GATE Worked Numerical: Unequal Stage Delays & Effective CPI
Clock period is set by the slowest stage delay PLUS latch delay! Non-pipelined instruction time is the pure sum of stage delays without latches.
Problem: A 5-stage pipeline has stage delays: IF = 160 ps, ID = 120 ps, EX = 220 ps, MEM = 180 ps, and WB = 100 ps. Pipeline register latch delay is 20 ps. In a benchmark program, 20% of instructions are conditional branches that cause 2 stall cycles. Find:
1. Clock cycle time.
2. Effective CPI.
3. Speedup over an unpipelined processor.
Step 1: Clock Cycle Time:
T_{clock} = \max(160, 120, 220, 180, 100) + 20 ps = 220 + 20 = 240 ps.
Step 2: Effective CPI:
CPI = Ideal CPI + Stall cycles per instruction
CPI = 1 + (0.20 × 2) = 1 + 0.40 = 1.40 cycles/instruction.
Step 3: Average execution time per instruction in pipelining:
T_{pipe,avg} = CPI × T_{clock} = 1.40 × 240 ps = 336 ps.
Step 4: Non-pipelined execution time per instruction:
T_{nonpipe} = 160 + 120 + 220 + 180 + 100 = 780 ps.
Step 5: Speedup:
S = \frac{T_{nonpipe}}{T_{pipe,avg}} = \frac{780 ps}{336 ps} \approx 2.32×.
Primary Academic References & Exam Sources
Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.
Curated for clarity, rigorous numerical solving, and semester excellence:
Rapid GATE-focused conceptual coverage with numericals.
Past-paper-focused approach with clear COA numerical explanations.
Graduate-level depth on how real modern processors are designed.