cycle123456789LDI r0, 2IFIDEXMEMWBLDI r1, 3IFIDEXMEMWBLDI r2, 3IFIDEXMEMWBLDI r3, 1IFIDEXMEMWBADD r0, r1IFIDEXMEMWBregistersr00r10r20r30programdone01IFFETCH01IDDECODE01EXEXECUTE01MEMMEMORY01WBWRITE BACKLDI r0, 2LDI r1, 3LDI r2, 3LDI r3, 1ADD r0, r1
Five stage blocks: fetch, decode, execute, memory, write-backTall blocks between them: pipeline registers; their lamps flash at each clock edgeMoving blocks: TINY-8 instructions, one stage per clock tickBack panel: the pipeline diagram, instructions against cyclesA pipelined processor splits each instruction into five stages separated by pipeline registers, so a new instruction can start every clock tick. Five TINY-8 instructions take 25 ticks one at a time and 9 ticks pipelined; each one still takes 5 ticks from fetch to write-back. With k equal stages and nothing stalling, n instructions take k + n − 1 ticks instead of k × n. As n grows the speed-up k × n / (k + n − 1) approaches k: 25 / 9 ≈ 2.8 for 5 instructions, 5000 / 1004 ≈ 4.98 for 1,000. Real pipelines fall short: stages are never perfectly balanced, so the slowest one sets the clock, and hazards make some instructions wait.

Five stages

  1. Running one TINY-8 instruction takes five jobs: fetch its two bytes, decode them, execute, use memory, then write the result back. Give each job its own piece of hardware, a stage, and one clock tick.

Overlapping work

Reading the diagram

How much faster

Tick by tick

;; step 1/10 · five-stages
;; about: Fetch, Decode, Execute, Memory, Write-back
LDI r0, 2  (bytes 10 02)

cycle 1  IF   read bytes 10 02 at address 0
cycle 2  ID   opcode 1 = LDI, target r0, value 2
cycle 3  EX   nothing to compute, 2 passes on
cycle 4  MEM  no memory access (only LD and ST)
cycle 5  WB   r0 = 2

1 instruction, 5 stages, 5 ticks

Pipelining improves performance by increasing throughput, not by making one instruction faster. Each pipeline register adds a small delay (the time to capture and pass on a value), so one instruction's latency is a little longer than without a pipeline (Harris and Harris, sections 3.5 and 7.5). The five instructions are lines of the course's TINY-8 example, reordered so the four LDI instructions come first. Bytes come from the TINY-8 assembler (LDI r0, 2 is 10 02; ADD r0, r1 is 51 00) and every register value from its reference simulator. ADD r0, r1 reads r1 in the same tick LDI r1, 3 writes it, which works because the register file is written in the first half of a tick and read in the second (Patterson and Hennessy, chapter 4).