7 Pipelining And Instruction Processing

Microprocessor and Computer Architecture ยท Unit 7

Pipelining and Instruction Processing

Exam-focused notes for Pipelining and Instruction Processing (Microprocessor and Computer Architecture, BIT151): what the TU syllabus asks and how it has actually been tested, with 8 solved past questions from this unit.

Pipelining and Instruction Processing in short

A processor can work faster if it handles several instructions at the same time, each in a different stage. This is pipelining. This chapter explains the idea, the instruction and arithmetic pipelines, the problems called hazards, and how to measure the gain.

Pipelining and Instruction Processing: notes

Pipelining concept and role in computing

Pipelining splits a task into smaller segments (stages). Each segment has its own hardware and works on a different task at the same time. Registers between the segments hold the partial results.

A good example is a laundry with a washer, a dryer and an iron. While one load is in the dryer, the next load is already in the washer.

Important points:

  • One task still takes the same total time, but a new task finishes every clock cycle once the pipeline is full.
  • It increases throughput (tasks finished per unit time), not the time for one task.
  • It is used in instruction execution and in arithmetic units.

Speedup formula. Let there be k segments, n tasks, and a clock period $t_p$. A non-pipelined unit takes $t_n = k,t_p$ per task.

$$\begin{aligned} \text{Time with pipeline} &= (k + n - 1),t_p \ \text{Time without pipeline} &= n,k,t_p \ S &= \frac{n,k}{k + n - 1} \end{aligned}$$

When n is very large, $S$ approaches $k$. The best possible speedup equals the number of segments.

Four segment instruction pipeline

A common instruction pipeline has four segments.

SegmentNameWork done
FIFetch instructionRead the instruction from memory
DADecode and addressDecode it and compute the effective address
FOFetch operandRead the operand from memory
EXExecutePerform the operation and store the result

The space-time diagram shows four instructions moving through the segments.

Clock1234567
Instruction 1FIDAFOEX
Instruction 2FIDAFOEX
Instruction 3FIDAFOEX
Instruction 4FIDAFOEX

Four instructions need $4 + 4 - 1 = 7$ clock periods. Without a pipeline they would need $4 \times 4 = 16$.

What this unit covers

  • Pipelining concept and role in computing
  • Four segment instruction pipeline
  • Instruction pipeline stages
  • Pipelining hazards and solutions
  • Arithmetic pipeline with examples
  • Performance of pipelined processors

Pipelining hazards and solutions

2082 ยท 5 marks

What are different pipelining hazards? Explain along with their solution. [5]

Show solved answer

Pipelining Hazards

Definition

Pipelining hazards are situations that prevent the next instruction in the instruction stream from executing during its designated clock cycle, causing the pipeline to stall.


Types of Pipelining Hazards

1. Structural Hazards

Definition: Arise when the hardware cannot support all possible combinations of instructions in simultaneous overlapped execution (resource conflict).

Example: Two instructions needing the same memory unit or ALU at the same time.

IF  ID  EX  MEM  WB
    IF  ID  EX   MEM  WB
                 ^
         Both need memory at same time --> CONFLICT

Solutions:

  • Resource duplication: Use separate instruction memory and data memory (Harvard architecture).
  • Pipeline stalling (bubble insertion): Insert a NOP (no-operation) cycle to delay one instruction.

2. Data Hazards

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

Types:

TypeDescription
RAW (Read After Write)Instruction reads a register before a previous instruction writes to it (most common)
WAR (Write After Read)Instruction writes before a previous one reads
WAW (Write After Write)Two instructions write to the same register out of order

Example (RAW):

ADD R1, R2, R3    ; writes R1
SUB R4, R1, R5    ; reads R1 -- hazard!

Solutions:

  • Forwarding (Data Bypassing): Route the result directly from the output of one stage to the input of another without waiting for WB stage.
  • Pipeline Stalling / Bubbles: Insert NOP cycles (stall) until the required data is available.
  • Compiler-based reordering: Reorder instructions so that independent instructions fill the delay slots.

3. Control Hazards (Branch Hazards)

Definition: Arise due to branch instructions (conditional/unconditional jumps). The pipeline fetches the next sequential instruction before knowing whether a branch is taken, causing incorrect instructions to enter the pipeline.

Example:

BEQ R1, R2, LABEL   ; branch instruction
ADD R3, R4, R5      ; fetched but may not be needed

Solutions:

  • Branch Prediction: Predict whether a branch will be taken (static or dynamic) and fetch accordingly.
    • Static: Always predict taken or always predict not taken.
    • Dynamic: Use a branch history table (BHT) to predict based on past behavior.
  • Delayed Branching: Execute one or more instructions after the branch (delay slot) that are independent of the branch outcome.
  • Flushing the Pipeline: If a wrong instruction is fetched, flush (discard) it and fetch the correct one (costly but correct).
  • Branch Target Buffer (BTB): Cache the target address of branches to reduce delay.

Summary Table

HazardCauseSolution
StructuralResource conflictResource duplication, stalling
Data (RAW/WAR/WAW)Data dependencyForwarding, stalling, instruction reordering
ControlBranch instructionsBranch prediction, delayed branching, flushing

Key Point: Hazards reduce pipeline efficiency. The goal of all solutions is to minimize CPI (Cycles Per Instruction) and keep the pipeline as full as possible.

Open this answer on its own page โ†’

Four segment instruction pipeline

2081 ยท 5 marks

What is pipelining? Explain about 4 segment instruction pipelines. [5]

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 a series of stages, and different instru...

Open this answer on its own page โ†’

2080.1 ยท 5 marks

What is pipelining? Explain the four segment instruction pipelining. [5]

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 a series of stages and processes differe...

Open this answer on its own page โ†’

0 ยท 5 marks

Explain 4 segment instruction pipeline. [5]

Pipelining is a technique used in CPU design where multiple instructions are overlapped in execution. A 4-segment instruction pipeline divides the instruction execution process into 4 distinct stages, allowing up to 4 instructions to be processed simultaneously at different stages. --- - The CPU ...

Open this answer on its own page โ†’

Pipelining concept and role in computing

2080 ยท 10 marks

What is pipelining? Define instruction pipeline and explain the four segment instruction pipeline.[10]

Show solved answer

Pipelining, Instruction Pipeline, and Four-Segment Instruction Pipeline


1. What is Pipelining?

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

It is analogous to an assembly line in a factory: just as different workers perform different tasks on different products simultaneously, different pipeline stages work on different instructions at the same time.

Key Idea: Increase throughput (number of instructions completed per unit time) without necessarily reducing the time for a single instruction.


2. Instruction Pipeline

An instruction pipeline is a pipeline mechanism applied specifically to the execution of instructions in a CPU. The instruction execution process is divided into a sequence of steps (stages), and each stage is handled by a dedicated hardware unit. Multiple instructions can be in different stages of execution at the same time.

Benefits:

  • Increases CPU throughput
  • Better utilization of hardware resources
  • Reduces idle time of functional units

Limitations:

  • Pipeline hazards (data, control, structural)
  • Overhead due to pipeline registers between stages
  • Branch instructions can cause pipeline stalls

3. Four-Segment Instruction Pipeline

A common and fundamental model divides instruction execution into four stages (segments):

StageNameDescription
S1Instruction Fetch (IF)Fetch instruction from memory
S2Instruction Decode (ID)Decode instruction and read registers
S3Execute (EX)Perform ALU operation or address calculation
S4Write Back (WB)Write result to register or memory

Stage-by-Stage Explanation

Stage 1: Instruction Fetch (IF)

  • The Program Counter (PC) holds the address of the next instruction.
  • The instruction is fetched from memory (or instruction cache) and loaded into the Instruction Register (IR).
  • PC is incremented to point to the next instruction.

Stage 2: Instruction Decode (ID)

  • The fetched instruction is decoded to determine the operation to be performed.
  • Source operands are read from the register file.
  • Control signals for subsequent stages are generated.

Stage 3: Execute (EX)

  • The ALU performs the required operation (arithmetic, logical, address computation).
  • For memory instructions: effective address is calculated.
  • For branch instructions: branch condition is evaluated.

Stage 4: Write Back (WB)

  • The result computed in the EX stage is written back to the destination register or memory location.
  • This completes the instruction execution.

Timing Diagram of Four-Segment Pipeline

Assume each stage takes 1 clock cycle (t).

Instruction | Clock Cycle
            | 1    2    3    4    5    6    7
------------|--------------------------------
   I1       | IF   ID   EX   WB
   I2       |      IF   ID   EX   WB
   I3       |           IF   ID   EX   WB
   I4       |                IF   ID   EX   WB

Performance Analysis

Without Pipeline (Sequential Execution):

For n instructions, each taking k stages with each stage taking time t:

$$T_{sequential} = n \times k \times t$$

For 4 instructions, 4 stages: $$T_{sequential} = 4 \times 4 \times t = 16t$$

With Pipeline:

$$T_{pipeline} = (k + n - 1) \times t$$

For 4 instructions, 4 stages: $$T_{pipeline} = (4 + 4 - 1) \times t = 7t$$

Speedup:

$$S = \frac{T_{sequential}}{T_{pipeline}} = \frac{n \times k}{k + n - 1}$$

$$S = \frac{16t}{7t} \approx 2.28$$

For large n, speedup approaches k (the number of stages), which is the ideal speedup.


Diagram of Four-Segment Pipeline

         +------+    +------+    +------+    +------+
 Instr.  |  IF  | -> |  ID  | -> |  EX  | -> |  WB  |  -> Result
 Stream  | Fetch|    |Decode|    |Execut|    |Write |
         +------+    +------+    +------+    +------+
            S1          S2          S3          S4
         [Pipeline Registers between each stage]

Each stage is separated by pipeline registers (latches) that hold intermediate results and pass them to the next stage on each clock edge.


Summary

ConceptDescription
PipeliningOverlapping execution of multiple instructions
Instruction PipelineDivision of instruction execution into stages
Four StagesIF โ†’ ID โ†’ EX โ†’ WB
AdvantageIncreases throughput, ideal speedup = k (no. of stages)
LimitationHazards can reduce efficiency

Pipelining is one of the most important performance enhancement techniques in modern processor design, forming the basis for more advanced techniques like superscalar and out-of-order execution.

Open this answer on its own page โ†’

2079 ยท 5 marks

What is pipelining? Explain the role of pipelining in computing. [5]

Pipelining is a technique used in computer architecture where multiple instructions are overlapped in execution. It is analogous to an assembly line in a factory: just as different stages of product assembly happen simultaneously on different items, different stages of instruction processing happ...

Open this answer on its own page โ†’

Performance of pipelined processors

2080 ยท 5 marks

Write short notes one a.) Performance of a pipelined processor Write short notes one b.) Page Replacement [2.5+2.5]

A pipelined processor divides instruction execution into a series of stages, where multiple instructions are overlapped in execution simultaneously: each stage handles a different instruction at the same time. 1. Pipeline Stages (k) If an instruction is divided into k stages, the pipeline has k s...

Open this answer on its own page โ†’

Arithmetic pipeline with examples

2078 ยท 5 marks

Explain arithmetic pipeline with suitable example. [5]

An arithmetic pipeline is a pipeline unit designed to implement floating-point operations, fixed-point multiplication, or other complex arithmetic computations by breaking the operation into a sequence of sub-operations, each performed in a separate pipeline stage. This allows multiple arithmetic...

Open this answer on its own page โ†’