CSCI 343 April 3: MIPS Pipelining, Parallelism, and Hazards


Overview

This lecture focused on instruction-level parallelism via pipelining in MIPS architecture, a technique designed to improve performance by increasing instruction throughput. Key topics included:


Five-Stage Instruction Cycle in MIPS

Each MIPS instruction may go through the following five stages:

  1. Instruction Fetch (IF) - Access instruction memory
  2. Instruction Decode (ID) - Decode and read register operands
  3. Execute (EX) - Perform ALU operations
  4. Memory Access (MEM) - Read/write data memory (only for load/store)
  5. Write Back (WB) - Write result to register file

Not every instruction uses every stage actively, but all must pass through each stage in a pipelined design.

Some instructions like R-format skip MEM, and store instructions skip WB. Branch instructions may skip both MEM and WB. However, all must move through all stages to maintain pipeline structure and timing.

Key Idea

Each stage uses a different hardware component (e.g., instruction memory, register file, ALU, data memory), allowing multiple instructions to proceed in parallel without interference.


Pipelining Basics

Pipelining increases throughput by overlapping stages of multiple instructions. Each pipeline stage operates on a different instruction during the same clock cycle.

Analogy: Doing Laundry

Requirements for Pipelining:

Advantages of Pipelining

To illustrate how pipelining reduces total clock cycles, refer to the diagram linked below:

Click here to view the pipelining diagram



Pipeline Timing & Speedup

Pipeline Time = (n + k - 1) × t
where:
    n = number of instructions
    k = number of stages (5 for MIPS)
    t = clock cycle time (determined by slowest stage)

This formula calculates the total time required to execute n instructions through a pipeline with k stages and clock cycle time t. It reflects the idea that the first instruction takes k cycles to complete, and each additional instruction completes in one additional cycle.

In the Pipeline visualization above:


MIPS Design and Pipelining

MIPS architecture is designed with pipelining in mind. Features include:

These choices allow each pipeline stage to be predictable and efficient, with less complex control logic.


Pipeline Hazards

Pipeline hazards are issues that prevent the next instruction from executing during its designated clock cycle.

1. Structural Hazards

2. Data Hazards

alt text

Solutions:

Load-Use Hazard

lw $s0, 20($t1)
sub $t2, $s0, $t3  # Requires stall before forwarding

alt text

3. Control Hazards (Branch Hazards)

Solutions:


Pipeline Registers & Forwarding Unit

Pipeline registers isolate each stage and store information needed by subsequent stages. This supports overlapping execution and forwarding.

Typical Inter-Stage Registers:

Forwarding Unit


Performance Comparison

Model Instructions Clock Cycles Clock Time Total Time
Single-cycle CPU 5 5 × 800 ps 800 ps 4000 ps
Pipelined CPU 5 9 cycles 200 ps 1800 ps

Example Problems

Data Hazard with Forwarding

add $s0, $s1, $s2
sub $t0, $s0, $s3  # Forward $s0 from EX to EX

Load-Use Hazard

lw $s0, 0($t0)
add $t1, $s0, $t2  # Requires 1 stall cycle + forwarding

Summary of Hardware Support for Pipelining


Exam Notes


Suggested Reading