2080 9

CSC213 ยท 2080 ยท 5 marks

What do you mean by pipelining concept? Discuss various pipeline hazards and their solutions in detail.

What do you mean by pipelining concept? Discuss various pipeline hazards and their solutions in detail. [5]

Computer ArchitectureChapter 6: PipeliningInstruction Level Pipelining

Quick answer

Pipelining is a technique used in computer architecture to improve CPU performance by overlapping the execution of multiple instructions. Instead of completing one instruction fully before starting the next, the processor divides instruction execution into several stages, and different instructions occupy different stages simultaneously.

Pipelining Concept and Pipeline Hazards

Pipelining Concept

For example, a typical 4-stage pipeline:

StageOperation
IFInstruction Fetch
IDInstruction Decode
EXExecute
WBWrite Back

Example of pipeline operation:

Time:    T1   T2   T3   T4   T5   T6
I1:      IF   ID   EX   WB
I2:           IF   ID   EX   WB
I3:                IF   ID   EX   WB

This overlap increases throughput (instructions completed per unit time) without reducing the time for a single instruction.


Pipeline Hazards (Pipelining Conflicts)

As stated in the notes: "There are three major difficulties that cause the instruction pipeline to deviate from its normal operation."

These three hazards are:


1. Structural Hazards (Resource Conflicts)

Definition: Occur when two or more instructions in the pipeline require the same hardware resource at the same time.

Example: Two instructions both needing memory access simultaneously.

Solutions:

  • Resource duplication: Provide separate instruction memory and data memory (Harvard Architecture).
  • Stalling the pipeline: Insert a pipeline bubble (NOP) to delay one instruction until the resource is free.

2. Data Hazards (Data Conflicts)

Definition: Occur when an instruction depends on the result of a previous instruction that has not yet completed its execution.

Example:

I1: ADD R1, R2, R3    ; R1 = R2 + R3
I2: SUB R4, R1, R5    ; R4 = R1 - R5  (needs R1 from I1)

I2 tries to read R1 before I1 has written it.

Types:

  • RAW (Read After Write): Most common; instruction reads before previous writes.
  • WAR (Write After Read): Instruction writes before previous reads.
  • WAW (Write After Write): Two instructions write to the same location out of order.

Solutions:

  • Forwarding (Data Bypassing): The result is forwarded directly from the output of one stage to the input of another without waiting for write-back.
  • Pipeline Stalling (Interlocking): The pipeline is stalled (bubbles inserted) until the required data is available.
  • Compiler-based instruction reordering: The compiler reorders instructions to place independent instructions between dependent ones.

3. Control Hazards (Branch Conflicts)

Definition: As stated in the notes, "These difficulties arise from branch and other instructions that change the value of PC." When a branch instruction is encountered, the pipeline may have already fetched the wrong instructions.

Example:

I1: BEQ R1, R2, LABEL   ; branch if R1 == R2
I2: ADD ...              ; fetched but may not be needed
I3: SUB ...              ; fetched but may not be needed

Solutions:

  • Pipeline Flushing: Discard (flush) the incorrectly fetched instructions when a branch is detected.
  • Branch Prediction:
    • Static prediction: Always predict branch taken or not taken.
    • Dynamic prediction: Use a branch history table to predict based on past behavior.
  • Delayed Branching: The compiler fills the delay slot after a branch with a useful instruction that executes regardless of the branch outcome.
  • Branch Target Buffer (BTB): A cache that stores the target address of recent branches for faster resolution.

Summary Table

Hazard TypeCauseSolution
StructuralResource conflictDuplication, Stalling
DataInstruction dependencyForwarding, Stalling, Reordering
ControlBranch/PC changeFlushing, Branch Prediction, Delayed Branch

Pipelining significantly improves CPU performance, but these hazards must be carefully managed to ensure correct and efficient execution.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.