6 Pipelining

Computer Architecture · Unit 6 · 6 hrs

Pipelining

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

Pipelining in short

A single instruction executed start to finish before the next one begins wastes hardware that sits idle between phases. This chapter covers the techniques, from simple parallel functional units to full instruction pipelining and vector processing, that let a processor overlap work and raise its throughput.

Pipelining: full notes

Parallel Processing

Parallel processing covers the techniques that let a computer carry out several data-processing tasks simultaneously rather than one at a time, in order to raise computational speed and throughput (the amount of processing completed in a given interval); the price is more hardware, since extra functional units and control logic are needed to keep several operations moving at once. Amdahl's law quantifies the speedup available when only part of a computation can be run in parallel: if a fraction $f$ of the work is parallelizable across $n$ processors and the rest, $1-f$, must still run sequentially, $$S = \frac{1}{(1-f)+\dfrac{f}{n}}$$ With $f=0.8$ and $n=4$ processors, $S = \dfrac{1}{0.2+0.2} = 2.5$: even though 80% of the work is parallelized across four processors, the remaining sequential 20% caps the overall speedup well below 4.

Multiple Functional Units

Rather than one ALU performing every microoperation in sequence, a processor can provide several multiple functional units, dedicated hardware for addition, multiplication, shifting, and logic, each able to operate on its own data at the same time as the others. Independent operations issued to different units proceed concurrently, so overall throughput rises as long as the instruction stream contains enough independent work to keep the units busy.

Flynn's Classification

Flynn's classification groups computer architectures by how many simultaneous streams of instructions and data they process:

ClassMeaning
SISD (single instruction, single data)One control unit, one processor and one memory executing instructions sequentially; the conventional single-processor computer
SIMD (single instruction, multiple data)Many processing units under one control unit, all executing the same instruction on different data items at once
MISD (multiple instruction, single data)Multiple processors each apply a different instruction to the same data stream; of theoretical interest only, with no significant practical system built this way
MIMD (multiple instruction, multiple data)Multiple processors, each executing its own instruction stream on its own data; the class covering most multiprocessor and multicomputer systems

Pipelining: Concept and Demonstration, Speedup Equation, Floating-Point Addition and Subtraction with Pipelining

Pipelining decomposes a repeated sequential process into a series of suboperations, each carried out by its own dedicated segment (stage) of hardware, with a register placed between consecutive segments so every segment can work on a different task's data during the same clock cycle, much like an assembly line. To compute $\text{Result}=(A+B)\times C$ for many operand triples, a three-segment pipeline can fetch $A$, $B$ and $C$ in one segment, add $A+B$ in a second, and multiply by $C$ in a third; once the pipeline is full, one finished result emerges every clock cycle even though each individual result still passed through all three stages.

For a $k$-segment pipeline with clock cycle time $t_p$ processing $n$ tasks, the first task takes $k t_p$ to clear every segment, and the remaining $n-1$ tasks then complete at one per cycle, so the total time is $[k+(n-1)]t_p$. Comparing this with a non-pipelined circuit that takes $t_n$ per task gives the speedup equation $$S = \frac{n,t_n}{(k+n-1),t_p}$$ As $n$ grows large, $k+n-1$ approaches $n$, so $S$ approaches $\dfrac{t_n}{t_p}$; if the non-pipelined time is assumed to be $t_n=k t_p$ (the same total work done without overlap), the limiting speedup approaches $k$, the number of segments. For example, with $k=4$ segments, $t_p=20$ ns, and $t_n=k t_p=80$ ns, pipelining $n=100$ tasks gives $$S = \frac{100\times80}{(4+100-1)\times20} = \frac{8000}{2060} = 3.88$$ approaching, but not reaching, the theoretical limit of 4.

A floating-point adder is a natural pipeline candidate, since adding two floating-point numbers always proceeds through the same fixed stages: compare exponents, align mantissas (shift the smaller-exponent operand's mantissa right by the exponent difference), add or subtract the aligned mantissas, and normalize the result. Adding $X=0.5\times2^4$ and $Y=0.9375\times2^3$: the exponents differ by 1, so $Y$'s mantissa is aligned by shifting it right one place, giving $Y=0.46875\times2^4$; adding the now-aligned mantissas gives $0.5+0.46875=0.96875$, so $$X+Y = 0.96875\times2^4 = 15.5$$ which checks against $8+7.5=15.5$ computed directly, and the mantissa $0.96875$ already lies in the normalized range, so no further normalization shift is needed.

Instruction Level Pipelining: Instruction Cycle, Three and Four-Segment Instruction Pipeline, Pipeline Conflicts and Solutions

Applying pipelining to the instruction cycle itself gives instruction-level pipelining. The full instruction cycle breaks into the stages fetch, decode, calculate the effective address, fetch the operand, execute, and store the result. A common four-segment instruction pipeline merges decoding with effective-address calculation into one segment, and merges execution with storing the result into another, giving four overlapped segments: FI (fetch instruction), DA (decode and calculate address), FO (fetch operand), and EX (execute). A coarser three-segment pipeline merges stages further still, for example combining fetch with decode, trading some of the achievable overlap for simpler control logic on processors that cannot justify a fourth pipeline register.

Three kinds of conflict can force an instruction pipeline to stall or restart. Resource conflicts arise when two segments need to access memory at the same time; separating instruction memory from data memory resolves most of these. Data dependency conflicts arise when an instruction needs a result that an earlier instruction, still moving through the pipeline, has not yet produced; the standard remedies are hardware interlocks (a circuit detects the dependency and stalls the dependent instruction the required number of cycles), operand forwarding (the needed result is routed directly from the producing segment to the consuming segment, bypassing the register file), and delayed load (execution of the dependent instruction is deliberately delayed until the needed data is guaranteed ready). Branch conflicts arise from branch and other instructions that change the program counter, since instructions already fetched from the sequential stream may have to be discarded; solutions include prefetching the target instruction before the branch resolves, a branch target buffer (an associative cache of recently used branch addresses and their targets), a loop buffer (a small, fast memory holding the entire body of a loop so it need not be re-fetched on each iteration), branch prediction (guessing whether a branch will be taken before it is evaluated, to keep fetching down the predicted path), and the delayed branch (the instruction immediately after a branch is always executed regardless of outcome, so the compiler fills that slot with useful, order-independent work instead of leaving it empty).

Vector Processing, Applications, Vector Operations, Matrix Multiplication

Vector processing applies a single instruction to an entire ordered set of data at once rather than one element at a time, and is suited to problems that a conventional scalar computer would take days or weeks to complete by looping over each element individually. Its main application areas include long-range weather forecasting, petroleum exploration, seismic data analysis, medical diagnosis, aerodynamics and space-flight simulation, artificial intelligence, and image processing.

A vector is a one-dimensional ordered array of data, written $V=[v_1,v_2,\ldots,v_n]$, with the index $i$ referring to a memory address or register holding $v_i$. Instead of a loop such as the Fortran statement C(I)=A(I)+B(I) executed once per element, a vector processor issues one instruction, $C(1{:}100)=A(1{:}100)+B(1{:}100)$, that carries the base addresses of $A$, $B$ and $C$ and the vector length, eliminating the fetch-and-decode overhead of repeating the same instruction 100 times. Matrix multiplication is one of the heaviest workloads suited to vector processors: multiplying two $n\times n$ matrices needs $n^2$ inner products, each an $n$-term multiply-add, so $n^3$ multiply-add operations overall. For $3\times3$ matrices $A$ and $B$, the product element in row $i$, column $j$ is $C_{ij}=\sum_k a_{ik}b_{kj}$; for instance the top-left element is $$C_{11} = a_{11}b_{11}+a_{12}b_{21}+a_{13}b_{31}$$

What this unit covers

  • Parallel Processing
  • Multiple Functional Units
  • Flynn's Classification
  • Pipelining: Concept and Demonstration with Example, Speedup Equation, Floating Point addition and Subtraction with Pipelining
  • Instruction Level Pipelining: Instruction Cycle, Three & Four-Segment Instruction Pipeline, Pipeline Conflicts and Solutions
  • Vector Processing, Applications, Vector Operations, Matrix Multiplication

Instruction Level Pipelining

2081 · 10 marks

What is pipelining? Explain pipelining using 4-segment instruction cycle. What are its advantages?[10]

Show solved answer

Pipelining: 4-Segment Instruction Cycle and Advantages

1. What is Pipelining?

Pipelining is a technique used in computer architecture to improve CPU performance by overlapping the execution of multiple instructions. Instead of waiting for one instruction to complete all its phases before starting the next, the CPU divides instruction execution into a series of stages (segments), and different instructions occupy different stages simultaneously.

It works like an assembly line in a factory: while one instruction is being executed, the next instruction is being decoded, and the one after that is being fetched, all at the same time.

Pipelining is easy in RISC architecture because instructions are simple and take a single cycle to execute.


2. Pipelining Using a 4-Segment Instruction Cycle

The instruction cycle is divided into 4 segments (stages):

SegmentStageOperation
S1Fetch (FI)Fetch the instruction from memory using PC
S2Decode (DI)Decode the opcode and determine instruction type
S3Execute (EI)Perform the operation (ALU, memory access, etc.)
S4Write Back (WB)Store the result back to register/memory

2.1 Micro-operations at Each Stage

Stage S1: Fetch

T0: AR <- PC
T1: IR <- M[AR], PC <- PC + 1

Stage S2: Decode

T2: Decode IR(12-14), AR <- IR(0-11), I <- IR(15)
    Determine instruction type (memory-reference, register, or I/O)

Stage S3: Execute

T3: Execute the instruction based on decoded opcode
    (ALU operation, memory read/write, I/O operation)

Stage S4: Write Back

T4: Write result to destination register or memory location
    SC <- 0 (reset sequence counter for next instruction)

2.2 Pipeline Timing Diagram

Without pipelining (sequential execution), each instruction takes 4 clock cycles. With pipelining, instructions overlap:

Clock Cycle:   1    2    3    4    5    6    7
               |    |    |    |    |    |    |
Instruction 1: FI   DI   EI   WB
Instruction 2:      FI   DI   EI   WB
Instruction 3:           FI   DI   EI   WB
Instruction 4:                FI   DI   EI   WB
  • Without pipeline: 4 instructions x 4 cycles = 16 clock cycles
  • With pipeline: 4 + (4-1) = 7 clock cycles

2.3 General Formula for Pipeline Execution Time

For a k-segment pipeline executing n tasks with clock cycle time t_p:

$$\text{Total Time} = [k + (n-1)] \times t_p$$

For our 4-segment pipeline (k = 4):

$$\text{Total Time} = [4 + (n-1)] \times t_p$$

Example: Execute 6 instructions (n = 6) with k = 4 segments:

$$\text{Total Time} = [4 + (6-1)] \times t_p = 9 \times t_p$$

Without pipelining: $$\text{Total Time} = n \times k \times t_p = 6 \times 4 \times t_p = 24 \times t_p$$

Speedup = 24 / 9 = 2.67x


2.4 Instruction Queue (FIFO Execution)

The instruction pipeline execution works like a queue using average execution (FIFO technique). When an instruction first arrives, it is placed in the queue and executed in the system, and the result is passed on to the next instruction in the queue.

This means:

  • Instructions enter the pipeline in order (FIFO)
  • Each instruction moves through S1 -> S2 -> S3 -> S4 sequentially
  • Multiple instructions are in different stages at the same time

3. Advantages of Pipelining

#AdvantageExplanation
1Increased ThroughputMore instructions are completed per unit time since multiple instructions execute simultaneously
2Better CPU UtilizationAll pipeline stages are kept busy, reducing idle time of CPU components
3Faster ExecutionOverall execution time for a large number of instructions is significantly reduced
4Cost EffectiveHigher performance is achieved without increasing the clock speed or adding more hardware
5Supports RISC ArchitectureSimple, uniform instructions in RISC make pipelining very efficient and easy to implement
6ScalabilityMore pipeline stages (deeper pipeline) can be added to further improve performance

4. Summary

FeatureWithout PipelineWith Pipeline
Execution styleSequentialOverlapped
Time for n instructionsn x k x t_p[k + (n-1)] x t_p
CPU utilizationLowHigh
ThroughputLowHigh

Pipelining is one of the most fundamental techniques in modern processor design. By dividing the instruction cycle into 4 segments (Fetch, Decode, Execute, Write Back) and overlapping their execution using a FIFO queue mechanism, the CPU achieves significantly higher performance without requiring faster hardware.

Open this answer on its own page →

2080 · 5 marks

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

Show solved answer

Pipelining Concept and Pipeline Hazards

Pipelining Concept

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.

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.

Open this answer on its own page →

2078 · 5 marks

Explain an instruction pipeline with an example. [5]

An instruction pipeline is a technique used 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 segments (stages), and different instruction...

Open this answer on its own page →

2075 · 10 marks

What are the different types of pipe line hazards? Explain each pipe line hazard with example.[10]

Pipelining is a technique of decomposing a sequential process into suboperations, with each subprocess being executed on a special dedicated segment that operates simultaneously with all other segments. However, certain situations arise during pipelined execution that prevent the next instruction...

Open this answer on its own page →

2075 · 5 marks

Differentiate between instruction pipeline and an arithmetic pipeline. [5]

An instruction pipeline is a pipeline technique used to execute multiple instructions simultaneously by overlapping the stages of the instruction cycle (fetch, decode, execute, store). It treats the processing of instructions like an assembly line, where each stage handles a different instruction...

Open this answer on its own page →

Flynn's Classification

2081 · 5 marks

What do you understand by Flynn's classification? Explain. [5]

Flynn's classification is a taxonomy that categorizes computer architectures into four major groups based on the number of concurrent instruction streams and data streams that a processor can handle simultaneously. - Instruction Stream: The sequence of instructions executed by the processor. - Da...

Open this answer on its own page →

2075 · 10 marks

Explain the Flynn's classification of computer architectures with diagrams.[10]

Flynn's classification (proposed by Michael J. Flynn in 1966) is a widely used taxonomy for categorizing computer architectures based on two independent dimensions: 1. Number of Instruction Streams - the sequence of instructions performed by the processor 2. Number of Data Streams - the sequence ...

Open this answer on its own page →

Parallel Processing

2078 · 5 marks

Draw a three dimensional hypercube and explain with example. [5]

--- A hypercube (also called an n-cube) is a geometric structure used in computer architecture and graph theory to represent interconnection networks. An n-dimensional hypercube has: - 2^n nodes (vertices) - Each node is labeled with an n-bit binary address - Two nodes are connected by an edge if...

Open this answer on its own page →

2075 · 5 marks

Explain an inter connection network and its use. [5]

An interconnection network is a programmable system of switches and links that connects a set of processors, memories, and input/output devices in a multiprocessor or parallel computing system. It provides the communication infrastructure that allows data to be transferred between different compo...

Open this answer on its own page →

Pipelining

2077 · 10 marks

What do you mean by pipeline? Explain with space time diagram for a six segmented pipeline showing the time it takes to process eight tasks.[10]

Show solved answer

Pipeline: Definition and Space-Time Diagram

Given

  • Number of pipeline segments: $k = 6$
  • Number of tasks to be processed: $n = 8$

(All required numeric values are present.)


Solution

What is a Pipeline?

A pipeline is a technique of decomposing a sequential process into sub-operations, with each sub-operation being executed in a dedicated segment that operates concurrently with all other segments. Information flows through the segments much like an industrial assembly line: while one segment works on one task, another segment simultaneously works on a different task.

Each segment consists of a combinational circuit that performs a sub-operation, followed by a register (latch) that holds the intermediate result to be passed to the next segment on the next clock pulse. All registers are controlled by a common clock.

The diagram that shows which segment is busy with which task at each clock period is called a space-time diagram.


Total Time for a k-Segment Pipeline Processing n Tasks

For a $k$-segment pipeline executing $n$ tasks, the number of clock cycles required is:

$$\text{Total Clock Cycles} = k + (n - 1)$$

Substituting $k = 6$ and $n = 8$:

$$= 6 + (8 - 1) = 6 + 7 = \boxed{13 \text{ clock cycles}}$$

  • The first task fills all 6 segments and completes at the end of clock cycle 6.
  • Thereafter, one task completes at every clock cycle, so the remaining 7 tasks finish in the next 7 cycles (cycles 7 to 13).

Space-Time Diagram (6 segments, 8 tasks)

Segment |               Clock Cycles
        |  1   2   3   4   5   6   7   8   9  10  11  12  13
--------|------------------------------------------------------
  S1    | T1  T2  T3  T4  T5  T6  T7  T8   .   .   .   .   .
  S2    |  .  T1  T2  T3  T4  T5  T6  T7  T8   .   .   .   .
  S3    |  .   .  T1  T2  T3  T4  T5  T6  T7  T8   .   .   .
  S4    |  .   .   .  T1  T2  T3  T4  T5  T6  T7  T8   .   .
  S5    |  .   .   .   .  T1  T2  T3  T4  T5  T6  T7  T8   .
  S6    |  .   .   .   .   .  T1  T2  T3  T4  T5  T6  T7  T8

Each task moves diagonally through the six segments.

TaskCompletes at cycle
T16
T27
T38
T49
T510
T611
T712
T813

Speedup Compared with Non-Pipelined Execution

MethodTime Required
Non-pipelined$n \times k = 8 \times 6 = 48$ cycles
Pipelined$k + (n-1) = 13$ cycles

Speedup:

$$S = \frac{n \times k}{k + (n-1)} = \frac{48}{13} \approx 3.69$$

As $n \to \infty$, the maximum speedup approaches $k = 6$.


Conclusion

A pipeline overlaps the execution of tasks across multiple segments. A six-segment pipeline processing eight tasks needs only 13 clock cycles (against 48 without pipelining), giving a speedup of about 3.69. The space-time diagram confirms that once the pipeline is full (from cycle 6), one task completes every clock cycle.

Open this answer on its own page →

2077 · 5 marks

How performance of computer is increased using pipeline? Explain with practical example. [5]

A pipeline is a technique where multiple instruction phases are overlapped in execution to improve the throughput of a computer. Instead of completing one instruction fully before starting the next, different stages of different instructions are executed simultaneously, much like an assembly line...

Open this answer on its own page →