COMPUTER ORGANIZATION & ARCHITECTURE/Student Engineering Notebook
Page 07·notes
INSTRUCTION PIPELINING, HAZARDS & PERFORMANCE—~30 MIN READ

Instruction Pipelining: Stages, Speedup & Hazards

“Clock period = max(stage) + latch, RAW data stalls, forwarding, and speedup.”

1.The 5-Stage RISC Pipelined Execution Principle

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

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.

notice this:— Register File Half-Cycle Reading Assumption

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!

WORKED EXAM ANALYSIS · STEP-BY-STEP DERIVATION2 Marks

3. GATE Worked Numerical: Unequal Stage Delays & Effective CPI

⚠️ Pitfall Warning:

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×.

SOURCE TRANSPARENCY & CITATIONS

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 University Lecture Series
Computer Organization and Design RISC-V Edition ·
LECTURE SERIES
RECOMMENDED YOUTUBE EDUCATORS & FULL-COURSE PLAYLISTS

Curated for clarity, rigorous numerical solving, and semester excellence:

Gate Smashers · COA Full Course↗Instructor: Varun Singla · Covers: Instruction cycle, addressing modes, cache mapping, pipelining, I/O

Rapid GATE-focused conceptual coverage with numericals.

Open YouTube↗
Knowledge Gate · COA for GATE↗Instructor: Sanchit Jain · Covers: Cache bit-splitting, AMAT, pipeline CPI, IEEE 754, DMA

Past-paper-focused approach with clear COA numerical explanations.

Open YouTube↗
ETH Zürich · Digital Design & Computer Architecture↗Instructor: Prof. Onur Mutlu · Covers: Microarchitecture, pipelining, out-of-order execution, memory hierarchy

Graduate-level depth on how real modern processors are designed.

Open YouTube↗