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.
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 answerHide 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:
| Type | Description |
|---|---|
| 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
| Hazard | Cause | Solution |
|---|---|---|
| Structural | Resource conflict | Resource duplication, stalling |
| Data (RAW/WAR/WAW) | Data dependency | Forwarding, stalling, instruction reordering |
| Control | Branch instructions | Branch 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.
Four segment instruction pipeline
2081 ยท 5 marks
What is pipelining? Explain about 4 segment instruction pipelines. [5]
2080.1 ยท 5 marks
What is pipelining? Explain the four segment instruction pipelining. [5]
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 answerHide 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):
| Stage | Name | Description |
|---|---|---|
| S1 | Instruction Fetch (IF) | Fetch instruction from memory |
| S2 | Instruction Decode (ID) | Decode instruction and read registers |
| S3 | Execute (EX) | Perform ALU operation or address calculation |
| S4 | Write 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
| Concept | Description |
|---|---|
| Pipelining | Overlapping execution of multiple instructions |
| Instruction Pipeline | Division of instruction execution into stages |
| Four Stages | IF โ ID โ EX โ WB |
| Advantage | Increases throughput, ideal speedup = k (no. of stages) |
| Limitation | Hazards 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.
2079 ยท 5 marks
What is pipelining? Explain the role of pipelining in computing. [5]
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]
Arithmetic pipeline with examples
2078 ยท 5 marks
Explain arithmetic pipeline with suitable example. [5]
Make Unit 7 stick
Practice BIT151 with flashcards & quizzes