Skip to main content
@shmVirus

Pipelining and Parallelism

Quantify pipeline speedup, resolve instruction hazards, and compare scalar, superscalar, vector, attached-array, and SIMD organizations.

Updated

Learning objectives

  • Classify parallel organizations with Flynn's taxonomy
  • Construct pipeline timing diagrams and calculate throughput and speedup
  • Explain arithmetic and instruction pipeline stages
  • Identify structural, data, and control hazards and their remedies
  • Explain RISC, superscalar, vector, interleaved-memory, and array processing

Prerequisites

  • Instruction Set Design
  • Computer Arithmetic
  • Memory Hierarchy

Parallel processing performs multiple useful operations during the same interval. It may duplicate functional units, divide work into pipeline stages, apply one instruction to a vector, or coordinate many independent processors.

TermDefinition
LatencyTime from starting one task until its result is complete.
ThroughputNumber of completed tasks per unit time after the system is active.
StageCombinational suboperation bounded by pipeline registers.
HazardA condition that prevents the next instruction from advancing normally.
StallA cycle in which selected pipeline state is deliberately held.
BubbleAn empty pipeline slot that moves through later stages.

A pipeline improves throughput before it improves latency. A four-stage pipeline may still take four cycles to produce one result; its advantage is completing later results one cycle apart.

Forms of Parallel Processing

Flynn classifies machines by the number of simultaneous instruction and data streams.

Flynn classification grid beside a CPU containing independent add, multiply, logic, shift, and increment functional units
Flynn describes visible instruction/data streams. Multiple functional units and pipelines can also provide internal parallelism inside one SISD processor.
ClassInstruction streamsData streamsTypical interpretation
SISD11Conventional sequential processor; may have internal pipelines
SIMD1ManyArray processor or vector-style lanes executing one operation
MISDMany1Mainly theoretical/specialized fault-tolerant flows
MIMDManyManyMultiprocessors and multicomputers running several programs

Independent adders, multipliers, logic units, and shifters can operate simultaneously on different values. This improves throughput but requires a controller to allocate operands and prevent resource conflicts. Large-scale applications include weather forecasting, aerodynamics, finite-element analysis, remote sensing, medical imaging, genetics, AI, and scientific simulation.

Pipeline Principle

A pipeline decomposes one operation into kk suboperations. Each stage has combinational logic followed by a register; a common clock advances every intermediate result. After filling, different stages work on different tasks and ideally complete one task per cycle.

Four registered pipeline stages and a space-time diagram for six tasks over nine cycles
A four-stage pipeline needs four cycles for its first result, then completes one task per cycle. Six tasks therefore occupy $4+(6-1)=9$ cycles.

For nn tasks, kk stages, and pipeline clock period tpt_p:

Tpipe=(k+n1)tp.T_\text{pipe}=(k+n-1)t_p.

If a nonpipelined unit takes tnt_n per task:

S=ntn(k+n1)tp.S=\frac{nt_n}{(k+n-1)t_p}.

If balanced stages divide the same work so tn=ktpt_n=kt_p, then as nn grows, SkS\to k. Real speedup is lower because the slowest stage fixes the clock, pipeline registers add delay, and stalls create empty slots.

Numeric example

A four-stage pipeline with tp=20t_p=20 ns executes 100 tasks in

Tpipe=(4+1001)20=2060 ns.T_\text{pipe}=(4+100-1)20=2060\text{ ns}.

The equivalent 80 ns nonpipeline unit needs 100(80)=8000100(80)=8000 ns, so

S=8000/20603.88.S=8000/2060\approx3.88.

The result approaches the theoretical fourfold limit for a long stream. If the nonpipeline operation were only 60 ns, the asymptotic speedup would be 60/20=360/20=3.

A Three-Stage Data Pipeline

Compute Ri=AiBi+CiR_i=A_iB_i+C_i with:

  1. Load Ai,BiA_i,B_i.
  2. Multiply and delay CiC_i.
  3. Add the product to the delayed CiC_i.

For seven input triples, the first result appears at clock 3 and the last at clock 9:

ClockStage 1 registersStage 2 registersStage 3 output
1A1,B1A_1,B_1
2A2,B2A_2,B_2A1B1,C1A_1B_1,C_1
3A3,B3A_3,B_3A2B2,C2A_2B_2,C_2A1B1+C1A_1B_1+C_1
4A4,B4A_4,B_4A3B3,C3A_3B_3,C_3A2B2+C2A_2B_2+C_2
\dots\dots\dots\dots
9A7B7+C7A_7B_7+C_7

The delay register for CiC_i is essential: it keeps each addend aligned with its matching product.

Arithmetic Pipelines

Floating-point addition/subtraction naturally separates into:

  1. Compare exponents.
  2. Align the smaller significand by shifting.
  3. Add or subtract significands.
  4. Normalize the result and adjust its exponent.
Four-stage floating-point add subtract pipeline with exponent compare, significand alignment, addition subtraction, and normalization
Registers isolate stages so several operand pairs occupy the floating-point pipeline simultaneously.

If combinational stage delays are 60, 70, 100, and 80 ns and each interstage register adds 10 ns, the clock must be 100+10=110100+10=110 ns. The equivalent unpipelined path is 60+70+100+80+10=32060+70+100+80+10=320 ns, giving an asymptotic throughput speedup 320/1102.9320/110\approx2.9, not four, because the stages are unbalanced.

Fixed-point multiply and divide can also be pipelined by unrolling their repeated add/subtract and shift steps into separate stages.

Instruction Pipelines

An instruction pipeline overlaps phases of successive instructions. A general six-phase breakdown is fetch instruction, decode, calculate effective address, fetch operand, execute, and store result. Combining decode with address calculation and execute with write-back yields the source’s four stages:

  • FI: fetch instruction.
  • DA: decode and calculate effective address.
  • FO: fetch operand.
  • EX: execute and store result.

In cycle 4, instruction 1 can be in EX, instruction 2 in FO, instruction 3 in DA, and instruction 4 in FI. Separate instruction and data memories or caches allow FI and FO to access memory simultaneously.

Four-stage instruction pipeline timing chart showing normal overlap, a data dependency stall, a shared-memory structural conflict, and a flushed branch path
A dependency, unavailable resource, or changed control flow inserts bubbles or discards work; forwarding and prediction reduce but do not eliminate these costs.

Pipeline hazards

HazardCauseExampleRemedies
StructuralTwo stages need one resourceFI and FO share one memory portDuplicate/partition resource or stall
DataOperand is not readyADD R1,... followed by SUB ...,R1Forward/bypass, interlock stall, compiler scheduling
ControlNext PC is unknownConditional branch or interruptPredict, prefetch target, delayed branch, flush

Forwarding routes a computed result directly to a later ALU input before it reaches the register file. A hardware interlock inserts a bubble when forwarding cannot satisfy the timing, as with some load-use pairs. A compiler may reorder independent instructions or insert a no-operation; this is delayed load.

Branch handling

  • Prefetch both paths: fetch sequential and target instructions until the decision.
  • Branch target buffer (BTB): associative memory remembers branch PCs, targets, and sometimes target instructions.
  • Loop buffer: holds a small repeated instruction sequence close to fetch.
  • Branch prediction: guess direction/target and discard speculative instructions if wrong.
  • Delayed branch: define one or more instructions after the branch to execute regardless; the compiler fills these delay slots with useful work when possible.

An interrupt also changes the PC. The pipeline completes or discards in-flight work according to the machine’s precise-interrupt rules before fetching from the handler.

RISC and Superscalar Pipelines

RISC instructions are usually fixed length, have simple addressing, use a load/store organization, and perform register operations in uniform stages. These properties make stage timing and decode regular. A classic three-segment teaching pipeline is I fetch, A ALU/address operation, and E memory/write result.

A load can still create a delayed-load hazard because its value becomes available late. A delayed branch exposes the branch slot to software. Modern processors normally maintain the architectural illusion with interlocks and prediction, but compiler scheduling remains useful.

A superscalar processor issues more than one scalar instruction per cycle using multiple pipelines/functional units. Unlike one vector instruction, each issued instruction still names its own scalar operation and operands. Dependencies, available units, and commit order limit issue width.

Vector Processing

A scalar loop

for i = 1..100:
    C[i] = A[i] + B[i]

fetches and decodes loop-control instructions repeatedly. A vector processor expresses the work as one operation:

C(1:100)A(1:100)+B(1:100).C(1{:}100)\leftarrow A(1{:}100)+B(1{:}100).

A vector instruction includes an operation, source and destination base addresses or vector registers, and vector length. A pipelined functional unit accepts successive element pairs; after startup, it can produce one result per cycle.

Matrix multiplication and inner products

For C=ABC=AB,

cij=k=1naikbkj.c_{ij}=\sum_{k=1}^{n}a_{ik}b_{kj}.

An n×nn\times n product contains n2n^2 inner products and n3n^3 multiply-accumulate terms. A 3×33\times3 product therefore performs 27 multiply-accumulates when each cijc_{ij} starts at zero. Linked multiplier and adder pipelines stream the pairs (aik,bkj)(a_{ik},b_{kj}) and accumulate partial sums.

Interleaved Memory

Vector and instruction pipelines demand several words close together. In an mm-module interleaved memory, low address bits choose the module and the remaining bits choose a word within it:

module=addressmodm.\text{module}=\text{address}\bmod m.

For four modules, addresses 0,1,2,3 go to modules 0,1,2,3; addresses 4,5,6,7 repeat the pattern. Each module has its own address/data registers, so staggered requests overlap. Sequential words can approach one word per bus cycle even when one module’s internal cycle is longer.

Array Processors

Vector pipeline and interleaved memory beside attached array processor and SIMD processing-element array organizations
Vector processors stream elements through pipelines. Array processors either attach a specialized back-end to a host or broadcast one instruction to many local processing elements.

An attached array processor is an auxiliary numerical processor connected to a conventional host through an I/O interface and a high-speed main-to-local-memory path. The host handles general work; the attached unit provides pipelined floating-point adders and multipliers for scientific kernels.

An SIMD array processor contains many identical processing elements (PEs), each with an ALU, registers, and local memory, governed by one master control unit. Scalar/control instructions execute at the master; vector instructions broadcast to active PEs. For C=A+BC=A+B, PE ii stores ai,bia_i,b_i and all active PEs compute ci=ai+bic_i=a_i+b_i simultaneously. Masks disable PEs outside the current vector portion; a vector longer than the PE count is processed in batches.

OrganizationInstruction overheadParallel resourceStrong workload
Scalar pipelineOne scalar instruction at a timeOverlapped stagesGeneral instruction streams
SuperscalarSeveral scalar instructions/cycleMultiple issue unitsIndependent instruction-level work
Vector processorOne instruction for many elementsPipelined vector unitsLong regular vectors/matrices
SIMD arrayOne broadcast instructionMany PEsHighly data-parallel arrays
Attached array processorHost dispatch plus kernelSpecialized back-endAccelerated numerical routines

Check Your Understanding

  1. How many cycles do eight tasks need in a five-stage ideal pipeline?
  2. Why does the slowest stage determine the pipeline clock?
  3. Classify a 64-PE array executing one add on 64 different pairs.
  4. How many multiply-accumulates form a 10×1010\times10 matrix product?
  5. Which hazard is removed by separate instruction and data memories?
Answers
  1. 5+81=125+8-1=12 cycles.
  2. Every stage must finish before the common register edge.
  3. SIMD.
  4. 103=100010^3=1000.
  5. The structural conflict between instruction fetch and operand access.