Computer Organisation and Architecture · Pipelining Basics
Introduction to Pipelining and Instruction Phases
Overview
Pipelining is a technique that speeds up program execution on a single processor by overlapping the execution of multiple instructions in time.
It is analysed using the four phases of the instruction cycle, first under the simplifying assumption that every phase takes one clock, which gives the baseline non-pipelined cost of 4 clock cycles per instruction.
Key concepts
- Pipelining: a technique to speed up execution when only one processor is available; more than one instruction can be in execution at the same time (overlapped in time). Using many processors instead is parallel processing.
- Instruction cycle phases: the four phases assumed for the CPU are Instruction Fetch (IF), Instruction Decode (ID), Execute (EX), and Write Back the result (WB).
- Non-pipelined execution: as in the basic computer design, instructions are executed one after another — each instruction must pass through all four phases before the next instruction starts.
- Equal-phase assumption: every phase of the instruction cycle takes the same time, called one clock — one clock to fetch, one clock to decode, one clock to execute, one clock to write back.
- Clock: the clock is applied to the processor; its time period depends on the clock frequency.
- Why phase times differ in practice: fetch time depends on how long the memory cycle takes; decode time depends on how long the instruction takes to load into the processor and how long it takes to generate the control signals; execute time depends on the type of operation — addition/subtraction take less time, multiplication takes more time; integer operations take less time, floating-point operations take more time.
How it works
- Divide the instruction cycle into the four phases IF, ID, EX, WB.
- Without pipelining, run each instruction through all four phases before starting the next.
- Assume each phase takes one clock, so one instruction costs 4 clock cycles.
- With pipelining, overlap instructions so that more than one instruction is in execution at the same time.
- For the initial analysis, keep the equal-phase assumption; real questions may give each phase a different number of clocks.
Drawing the diagram…
Formulas
- — is the clock time period (seconds), is the clock frequency (Hz)
Worked examples
Example 1 — Clock period from frequency
- Meaning: one phase of the instruction cycle completes in 1 microsecond.
Example 2 — Clocks for 3 instructions without pipelining
- Phases per instruction = 4 (IF, ID, EX, WB), each 1 clock
- Clocks for 1 instruction = 4
- Clocks for 3 instructions = clock cycles
Comparison
| Aspect | Non-pipelined | Pipelined |
|---|---|---|
| Instructions in execution at a time | One after another; each finishes all four phases before the next starts | More than one instruction in execution at the same time (overlapped in time) |
| Clocks per instruction (equal phase times) | 4 | Overlapped, so execution is sped up |
Revision summary
- Pipelining speeds up execution on a single processor; using many processors is parallel processing, not pipelining.
- The four phases are IF, ID, EX, WB.
- The equal-phase assumption (one clock each) is a simplifying assumption for the first analysis, not a practical fact.
- In reality phase times differ: fetch depends on the memory cycle, decode on instruction loading and control-signal generation, execute on the operation type (multiplication and floating-point take more time).
- ; 1 MHz gives microsecond.
- Non-pipelined time for instructions is clock cycles; 3 instructions take 12 clocks.
Previous-year exam insights
- Pipelining is most effective when all stages take approximately equal time; the pipeline clock period is set by the slowest (bottleneck) stage, so speedup is limited by the maximum stage delay (plus register/latch delay).
Asked inUGC NET 2012GATE 2017GATE 2016 - For a k-stage pipeline with equal stage delay t and N instructions, total time = (k + N - 1) * t;
non-pipelined time = N * k * t;
speedup = N*k / (k + N - 1), which tends to k as N tends to infinity.
Asked inGATE 2020GATE 2017GATE 2016 - Pipelining improves throughput (instructions completed per unit time) by exploiting instruction-level parallelism; it does not reduce the latency of a single instruction (and adds register overhead), and it does not eliminate data hazards.
Asked inUGC NET 2016 - Instruction prefetch (fetching the next instruction while the current one executes, storing it in an instruction buffer) speeds up processing by overlapping fetch with execution, i.e. by overlapping instruction cycle phases.
Asked inGATE 1992UGC NET 2012 - Software pipelining is a compile-time (compiler) technique that reorders/overlaps loop iterations to expose ILP; it is a form of out-of-order-style scheduling done by the compiler, unlike loop unrolling, dead code elimination and strength reduction which are ordinary optimizations.
Asked inISRO 2020 - Reservation tables describe the stage usage of successive instructions in a pipeline; the minimum average latency (MAL) is found from the minimum cycle length (latency) of the collision-free scheduling, and the throughput is 1/MAL.
Asked inGATE 2015