Pipelining was born as a disappointment. IBM's 7030 "Stretch" was promised to be 100 times faster than the IBM 704; it came out about 30 times faster, IBM cut its price from 13.5 to 7.78 million dollars and sold nine. But its "lookahead" unit, which overlapped the fetching and decoding of instructions with the execution of earlier ones, is the ancestor of every pipeline in this course.
The assembly line in silicon
After this lesson you will push five instructions through the five stages of the RISC-V pipeline cycle by cycle, say what each pipeline register carries, and compute how long any program takes on an ideal pipeline — and why it is never the 5× the notes promise.
Take five instructions and a processor whose five stages take 2 ns each. One instruction after another: 5 × 10 ns = 50 ns. Overlapped on the pipeline: 18 ns. Next to that 18 ns the notes print "a speedup of 5×". Divide 50 by 18 and you get 2.78.
Where did the other half of the promised speedup go, and when, if ever, do you get it back? The answer is one subtraction — and it is the same subtraction that puts the "+4" into the cycle-count formula on the A4 sheet you are allowed to bring to the exam.
One more number before you start. In March 2026 the first self-assessment test of this course — on the basics of pipelining, hazards and caches — was taken by 124 students; the average score was 5.3 out of 10 (WeBeep, week 2). The basics are examined, and they are missed.
Five stops for every instruction
Here is the loop this whole lesson runs on. It is written the way the exam papers write assembly: capital mnemonics, F registers for floating-point values, R registers for integers, and the memory address as an offset in front of a base register in brackets. The papers of 2024 and 2025 wrote the registers as $F2 and $R1; the 2026 paper dropped the dollar sign, and so does this notebook.
LOOP: LD F2, 0(R1)
FADD F4, F2, F0
SD F4, 0(R1)
ADDUI R1, R1, 8
BNE R1, R2, LOOP
Read it once in words: load the number at address R1 into F2; add F0 to it and put the sum in F4; store F4 back to the same address; move the pointer R1 on by 8 bytes; go back to LOOP unless R1 has reached R2. The instructions are numbered I0 to I4 as the papers number them. The machine of this lesson is the one of the notes: five stages, one clock cycle each, and every instruction — the FADD included — spends exactly one cycle in the execute stage. Real floating-point adders take several cycles; that pipeline arrives in lesson 7.
The RISC-V subset of the notes, in three spellings
The notes (pp. 8–9) introduce the instruction set in three families, with the effect of each instruction written as a register transfer: ALU instructions (add rd, rs1, rs2 does rd ← rs1 + rs2; addi adds a constant), load and store instructions (ld rd, offset(rs1) does rd ← M[rs1 + offset]; sd rs2, offset(rs1) does the reverse) and branches and jumps (beq, bne, j, jr). These are the only kinds of instruction the pipeline ever sees. The same instructions appear in three spellings during the course, and you must read all three fluently, because the exam is written in the third.
| What it does | RISC-V, notes pp. 8–12 | MIPS style, notes pp. 16–17 | Exam papers |
|---|---|---|---|
| load from memory into a register | ld x10, 40(x1) | lw $x, offset($y) | LD F2, 0(R1) |
| store a register to memory | sd x5, 8(x1) | sw $x, offset($y) | SD F4, 0(R1) |
| register + register | add x3, x1, x2 | op $x, $y, $z | FADD F4, F2, F0 |
| register + constant | addi x1, x1, 8 | — | ADDUI R1, R1, 8 |
| conditional branch (not equal / equal) | bne x1, x2, L1, beq x1, x2, L1 | beq $x, $y, offset (the notes' only MIPS-style example) | BNE R1, R2, LOOP |
| register names | x0 … x31 | $x, $y, $z | R1, R2 … and F0, F2 … (2024–25: $R1, $F2) |
Two small things to know about the first spelling. The notes use ld and sd, the 64-bit load and store of RV64, and on p. 10 call the registers 32-bit wide; in RV64 they are 64 bits (the width is called XLEN). And the notes' j and jr are pseudo-instructions. None of this matters for the exam; the mnemonics of the papers do.
What happens at each stop
Every instruction visits the same five stages in the same order. Walk LD F2, 0(R1) through them — it is the notes' Example 1 (p. 12), ld x10, 40(x1), in the papers' spelling:
- IF, instruction fetch. The program counter (PC) addresses the instruction memory; the instruction word comes out, and a separate adder computes PC + 4, the address of the next instruction. (Separate, so that IF never needs the ALU while EX is using it for another instruction.)
- ID, instruction decode. The opcode is decoded, the register file is read — here
R1— and the immediate 0 is extracted and sign-extended. - EX, execute. The ALU adds
R1 + 0: the memory address. - MEM, memory access. The data memory is read at that address.
- WB, write-back. The word that came out of memory is written into
F2.
Now look at the hardware those five steps use, and you will see why there are exactly five of them and not four or six. Each step uses a different resource, and uses it once: the instruction memory, the two read ports of the register file, the ALU, the data memory, the one write port of the register file. The notes list these components on pp. 10–11; the register file has two read ports and one write port because every RISC-V instruction reads at most two registers and writes at most one. That one-resource-per-stop property is the precondition for everything that follows: five instructions can occupy the five stops at the same time without fighting over hardware.
"RISC-V adopts a Harvard architecture, so there are no structural hazards." The notes come close to this on p. 10 ("RISC-V adopts a Harvard Architecture style … This prevents structural hazards"). Separate instruction and data memories are a choice of the implementation — in a real chip two level-1 caches in front of one memory — made so that the fetch of one instruction and the memory access of another never compete. It is not a property of the RISC-V instruction set, and a RISC-V processor with a single memory port, or with a multi-cycle divider, has structural hazards all the same. Keep the reasoning, drop the "RISC-V adopts".
Five stages because five resources: instruction memory, register read ports, ALU, data memory, register write port — each used once per instruction.
Overlap, not speed: the assembly line
In a car factory nobody waits for one car to be finished before the next body enters the line. Each station does its one job and passes the car on; a new car rolls off the end at the pace of the slowest station, not at the pace of a whole car. The notes (p. 13) use the same picture, and it is exact: the five stops of Fig. 1 are the five stations, and the instructions are the cars.
Take the notes' numbers: 2 ns per stage, so 10 ns per instruction. Without overlap, five instructions take 50 ns — each one must leave the last stop before the next enters the first. With overlap, the second instruction enters IF while the first moves to ID, and so on. The first instruction still needs the full 10 ns; after that one instruction completes every 2 ns.
Before: one instruction after another
After: overlapped on the pipeline
Latency and throughput
Pipelining changes nothing about one instruction. Latency, the time from the fetch of an instruction to its write-back, is still five stages, 10 ns (p. 14: "does not change"). What changes is the throughput: the number of instructions completed per unit of time. One per 10 ns becomes one per 2 ns once the line is full. The notes call pipelining a technique (p. 8), and that is the right word: it is a property of the implementation, not of the instruction set — the program cannot tell whether it runs on a pipeline, it only finishes sooner.
The table is the exam's way of writing Fig. 2: rows are instructions, columns are clock cycles C1, C2 …, and each cell names the stage. (The notes' Table 1 on p. 15 is the transpose, rows for cycles and columns for stages; same diagonal.)
| C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9 | |
|---|---|---|---|---|---|---|---|---|---|
I0 LD F2, 0(R1) | IF | ID | EX | MEM | WB | ||||
I1 FADD F4, F2, F0 | IF | ID | EX | MEM | WB | ||||
I2 SD F4, 0(R1) | IF | ID | EX | MEM | WB | ||||
I3 ADDUI R1, R1, 8 | IF | ID | EX | MEM | WB | ||||
I4 BNE R1, R2, LOOP | IF | ID | EX | MEM | WB |
One honesty note. This table assumes what the notes assume for the ideal case: that no instruction needs a value a previous one has not yet produced, and that the branch does not disturb the fetching. Our loop breaks both — FADD needs the F2 that LD produces, and BNE jumps. Lesson 2 and lesson 4 charge for that. Today the pipeline is ideal.
The formula behind the 18 ns
Count cycles in the table. The first instruction needs five; every later one finishes one cycle after its predecessor. Write \(k\) for the number of stages, \(n\) for the number of instructions and \(T\) for the stage time (which is the clock period):
-
Without a pipeline every instruction takes all \(k\) stage times, one after another:
\[ T_{\text{seq}} = n \, k \, T . \] -
On the pipeline the first instruction finishes in cycle \(k\). Instruction number \(i\) (counting from 1) enters one cycle later than its predecessor and therefore finishes one cycle later: in cycle \(k + (i - 1)\).
-
The last instruction has \(i = n\), so the whole program ends in cycle \(k + n - 1\):
\[ T_{\text{pipe}} = (k + n - 1) \, T . \]With \(k = 5\), \(n = 5\), \(T = 2\) ns: \(9 \times 2 = 18\) ns, the number of the hook. The \(k - 1 = 4\) extra cycles are the fill: the cycles before the first instruction comes out, during which the stops behind it are still filling up.
-
The speedup is the ratio; the stage time cancels:
\[ S(n) = \frac{n \, k \, T}{(k + n - 1) \, T} = \frac{n \, k}{k + n - 1} . \] -
Divide numerator and denominator by \(n\). As \(n\) grows, \((k - 1) / n\) vanishes and the speedup climbs towards \(k\) — never reaching it:
\[ S(n) = \frac{k}{1 + (k - 1)/n} \;\longrightarrow\; k . \]For five instructions: \(25 / 9 = 2.78\). For a hundred: \(500 / 104 = 4.81\).
| \(n\) | sequential \(10n\) ns | pipelined \((n + 4) \times 2\) ns | speedup |
|---|---|---|---|
| 1 | 10 | 10 | 1.00 |
| 5 | 50 | 18 | 2.78 |
| 10 | 100 | 28 | 3.57 |
| 20 | 200 | 48 | 4.17 |
| 100 | 1000 | 208 | 4.81 |
| 1000 | 10 000 | 2008 | 4.98 |
Why not ten stages of 1 ns, then twenty of 0.5 ns?
Because the clock period is not "the work divided by \(k\)". Every stage ends in a pipeline register (next section), and that register costs time on every cycle: setup, delay, the uncertainty of the clock edge. The clock period must be at least the delay of the slowest stage plus this overhead, \(T_{\text{clk}} \ge \max_i d_i + t_{\text{reg}}\). Split 10 ns into 10 stages with 0.5 ns of overhead each and the clock is 1.5 ns, not 1 ns; the ceiling is 6.67, not 10. Stages are never perfectly balanced either, so the slowest sets the pace for all, and a deeper pipeline has more instructions in flight, so every hazard of the next lessons costs more cycles. This argument is Hennessy and Patterson's, not the notes': it is the standard answer to "why deeper is not always faster".
Pipelining raises throughput, not speed: one instruction still takes \(k\) cycles, but once the line is full one completes every cycle, and \(n\) instructions take \(k + n - 1\) cycles.
What each instruction does at each stop
All five instructions march through the same five stages, but they do different things there — and in some stages nothing at all. The notes give one small table per instruction class (pp. 16–17); here they are side by side, in the loop's own instructions. The cell marked "born" is where the instruction's result first exists; the cell marked "idle" is a stage the instruction passes through without doing anything.
| Instruction | IF | ID | EX | MEM | WB |
|---|---|---|---|---|---|
LD F2, 0(R1)load | fetch; PC + 4 | read R1; extract 0 | address R1 + 0 | read memory — F2 born | write F2 |
FADD F4, F2, F0ALU | fetch; PC + 4 | read F2, F0 | F2 + F0 — F4 born | idle: passes through | write F4 |
SD F4, 0(R1)store | fetch; PC + 4 | read R1 and F4 | address R1 + 0 | write F4 to memory | idle: nothing to write |
ADDUI R1, R1, 8ALU, immediate | fetch; PC + 4 | read R1; extract 8 | R1 + 8 — R1 born | idle: passes through | write R1 |
BNE R1, R2, LOOPbranch | fetch; PC + 4 | read R1, R2 | compare R1 with R2; target = PC + offset | load the PC if taken | idle: no register to write |
Three facts in this table are worth more than the rest, because the next lessons are built on them. A load's value is born at the end of MEM, one stage later than an ALU result, because the load needs the ALU for the address and then the memory: this is why a load's consumer will cost a stall that no wire can remove. A store reads two registers in ID — the base and the data — although the data is needed only in MEM: ID is the only stage with read ports, so the value is read early and carried along. And a branch compares in EX and loads the PC in MEM; the instructions fetched meanwhile were fetched blind. That is the control hazard the notes name on p. 17 and lesson 4 is about.
Why an idle stage is not a skipped stage
Look at the grey cells and ask the obvious question: the FADD has its result at the end of EX, so why not write it in the very next cycle and let the instruction leave the pipeline early? Because of the fifth column of Fig. 1. The register file has one write port, and in any cycle the instruction one step ahead may be using it. If FADD jumped from EX to WB, it would reach WB in cycle 5, the same cycle as the LD in front of it — two writes, one port. Worse, an ALU instruction that follows a load would then write its register before the load writes its own, and results would land in the register file out of program order. Keeping every instruction in the pipe for exactly five cycles guarantees that at most one instruction is in WB per cycle and that writes happen in order. The idle stage is the price of that guarantee, and the price is zero: the stage was going to exist anyway.
One last look at the table before moving on. F2 is born at the end of cycle 4, in the LD's MEM stage — but FADD reads F2 in its ID stage, which is cycle 3. The ideal table of the previous section quietly reads a value that does not exist yet. That is the data hazard, and what the hardware does about it is the whole of lesson 2.
An ALU result is born at the end of EX, a loaded value at the end of MEM; an instruction with nothing to do in a stage still spends the cycle there.
What travels between the stops: the pipeline registers
Between any two stations of a car factory there is a short stretch of conveyor that holds the car — and its work order — while the next station is busy. The pipeline has the same thing between any two stages: a pipeline register, a bank of flip-flops that is written at the end of every clock cycle and read in the next. There are four of them, named after the stages they separate: IF/ID, ID/EX, EX/MEM and MEM/WB (notes, p. 19 and Fig. 4 on p. 18). All four are clocked together, so on every clock edge the whole pipeline advances by one stop.
What must a register hold? Everything the instruction inside it still needs for the stages ahead — because the instruction word itself stays behind in IF/ID and is overwritten by the next fetch one cycle later. The notes list the contents in one line each; here is the full list, with the control-signal names of Patterson and Hennessy, which the notes do not spell out:
IF/ID: the instruction word (32 bits) and PC + 4.ID/EX: PC + 4; the two values read from the register file; the sign-extended immediate; the number of the destination registerrd; and the control signals decoded from the opcode for the three stages ahead — for EX (ALUOp,ALUSrc: register or immediate as the second operand), for MEM (MemRead,MemWrite,Branch) and for WB (RegWrite,MemtoReg: write the ALU result or the loaded word).EX/MEM: the ALU result, which for a load or store is the address; the value to be stored; for a branch the target address and the outcome of the comparison;rd; the control signals for MEM and WB.MEM/WB: the word read from memory, or the ALU result passed through;rd; the control signals for WB.
Two things travel in every register and are easy to forget at the exam: the destination register number and the control bits. Decoding happens once, in ID; from then on the instruction carries its own work order, and each stage consumes the part addressed to it, so the control word gets shorter from register to register. The write-back stage, three cycles after decode, learns which register to write from the rd field of MEM/WB, not from the instruction word, which by then belongs to an instruction three places behind.
rd and the control signals, decoded once in ID and carried along. ID/EX holds control for three stages, EX/MEM for two, MEM/WB for one.Why have the registers at all? Not for the reason the notes give on p. 19 ("they eliminate the need for re-fetching or re-decoding instructions at each cycle" — re-fetching was never on the table). The real reason is the clock. Without a register between two stages, their logic would form one long combinational path, and the clock period would have to cover both; the register cuts the path, so that the period only has to cover one stage. That is what lets the clock run at the pace of a stage instead of the pace of an instruction, which is the entire point of the technique. The registers are also where the forwarding hardware of the next lesson reads its values from: a result that sits in EX/MEM can be handed to the ALU without waiting for WB.
The instruction word stays in IF/ID for one cycle; everything the later stages need — operands, immediate, destination number, control bits — travels with the instruction through ID/EX, EX/MEM and MEM/WB.
The puzzle, solved — and what spoils the ideal line
Back to the hook. Five instructions, 50 ns sequential, 18 ns pipelined, and the notes' "5×". You now have the subtraction: the pipeline needs \(k + n - 1 = 9\) cycles, not \(n = 5\), because the first instruction must travel the whole line before anything comes out — four fill cycles, \(k - 1\). The speedup is \(nk / (k + n - 1) = 25/9 = 2.78\). You get the rest back only by amortising the fill: 100 instructions give 4.81, 1000 give 4.98, and the 5 is a ceiling, approached and never reached. Add the register overhead and the ceiling itself drops below 5.
The same four cycles appear on the example A4 formula sheet the course page shows as "Clock Cycles = IC + Stall Cycles + 4". The "+4" is this fill, counted once per program; the "stall cycles" are the price of what this lesson assumed away. Lesson 3 turns these into CPI and MIPS.
Three things spoil the ideal line, and the notes name them on pp. 10, 17 and 20–21. A structural hazard: two instructions need the same resource in the same cycle — with one memory for instructions and data, the IF of one instruction and the MEM of another would collide, which is why the datapath has two. A data hazard: an instruction needs a value an earlier one has not produced yet — our FADD and its F2. A control hazard: the next PC is not known when the next fetch should start — our BNE. Each of them costs cycles, each has a fix, and each fix is a lesson: data hazards and forwarding next, branches in lesson 4, the hazards that return with multi-cycle units in lesson 7.
One rule to carry with you until lesson 7, where exceptions are treated: whatever overlapping the pipeline does, an exception must look as if the faulting instruction had executed alone — everything before it completed, nothing after it started. Overlap is allowed to change timing, never meaning.
Exam-style questions
Explain the main concepts and benefits of each one of the following techniques used by a pipelined RISC-V processor:
- Pipelining of the instruction execution
- The five-stage organisation IF / ID / EX / MEM / WB
- The pipeline registers
- Separate instruction and data memories
Show model answer
1. Pipelining is an implementation technique that overlaps the execution of consecutive instructions: the execution is divided into stages and each stage works on a different instruction in the same clock cycle. The latency of one instruction does not change (k cycles), but once the pipeline is full one instruction completes per cycle, so the throughput grows by up to k times; n instructions take k + n − 1 cycles instead of nk, and the clock period becomes the time of one stage instead of a whole instruction. Costs: a fill of k − 1 cycles, pipeline-register overhead, and hazards (structural, data, control) that insert stalls.
2. The five stages correspond to five resources used once by every instruction: IF fetches from the instruction memory and computes PC + 4; ID decodes and reads the two source registers (two read ports); EX uses the ALU for the operation, the address or the branch comparison; MEM accesses the data memory (loads and stores only); WB writes the destination register (one write port). Because each stage uses a different resource, five instructions can be in flight without conflicts; every instruction traverses all five stages (idle stages are not skipped), so completion is in order and at most one instruction writes per cycle.
3. The pipeline registers IF/ID, ID/EX, EX/MEM and MEM/WB sit between the stages and are written on every clock edge. They hold everything an in-flight instruction still needs: the instruction and PC + 4 (IF/ID); the operand values, the immediate, the destination register number and the control signals for EX, MEM and WB (ID/EX); the ALU result or address, the store data, the branch target, rd and the MEM/WB control (EX/MEM); the loaded data or ALU result, rd and the WB control (MEM/WB). Benefits: they isolate the stages so that the clock period equals one stage; the control is decoded once and carried along; and they are the source of the values used by forwarding.
4. With a single memory, the instruction fetch of one instruction and the data access of another (IF and MEM of two different instructions in the same cycle) would compete for the memory port: a structural hazard with a stall every time. Separate instruction and data memories (in practice separate L1 caches) give the two stages their own port, so the hazard is designed away. It is a property of the implementation, not of the instruction set.
The 2026 paper asks its 8-point question in exactly this form: "Explain the main concepts and benefits of each one of the following techniques", with a few lines per sub-point. Fill them with the key words — overlap, throughput versus latency, k + n − 1, one resource per stage, the four register names with their contents, "structural hazard" for the memory — and with a cost next to each benefit. A sub-point that only says what the thing is called says nothing.
Consider the five-stage RISC-V pipeline (IF, ID, EX, MEM, WB) with one clock cycle per stage and no hazards (ideal case). Complete the pipeline diagram for one iteration of the following loop, then give the total number of clock cycles and the execution time with a 2 ns clock. How many cycles would the same five instructions take on a non-pipelined machine that executes the five stages one after another?
LOOP: LD F2, 0(R1)
FADD F4, F2, F0
SD F4, 0(R1)
ADDUI R1, R1, 8
BNE R1, R2, LOOP
Show model answer
| C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9 | |
|---|---|---|---|---|---|---|---|---|---|
I0 LD F2, 0(R1) | IF | ID | EX | MEM | WB | ||||
I1 FADD F4, F2, F0 | IF | ID | EX | MEM | WB | ||||
I2 SD F4, 0(R1) | IF | ID | EX | MEM | WB | ||||
I3 ADDUI R1, R1, 8 | IF | ID | EX | MEM | WB | ||||
I4 BNE R1, R2, LOOP | IF | ID | EX | MEM | WB |
Total clock cycles = k + n − 1 = 5 + 5 − 1 = 9 (equivalently IC + 4 = 5 + 4 with no stalls); execution time = 9 × 2 ns = 18 ns. Non-pipelined: 5 × 5 = 25 cycles = 50 ns. Speedup of the pipeline = 50 / 18 = 2.78.
Every row has all five stages, the idle ones included — a row that stops at EX for the FADD or at MEM for the SD is wrong. The diagonal must shift by exactly one column per instruction, and the cycle count must be read from the last WB (C9), not guessed as "5 instructions, 5 cycles".
An ideal five-stage pipeline with a 2 ns clock executes 100 independent instructions. How many nanoseconds does the execution take?
Show model answer
Against 1000 ns without the pipeline: a speedup of 1000 / 208 = 4.81.
The tempting wrong answer is 200 ns (one instruction per cycle, no fill). The four extra cycles are the fill of the five-stage pipeline, the "+4" of the course's cycle formula.
A non-pipelined processor executes one instruction in 10 ns. A designer splits that work evenly into 10 pipeline stages, but every stage adds 0.5 ns of pipeline-register overhead to the clock period. What is the maximum speedup over the non-pipelined processor, for a very long program of independent instructions? Give two decimals.
Show model answer
Stage time = 10 / 10 = 1 ns; clock period = 1 + 0.5 = 1.5 ns. For n → ∞ the pipeline completes one instruction per clock period, so the speedup tends to 10 / 1.5 = 6.67 — not 10.
This is the "why deeper is not always faster" question. The expected reasoning is: ceiling = time of one instruction / clock period, and the clock period = slowest stage + register overhead. A five-stage pipeline with the same overhead has a ceiling of 10 / 2.5 = 4, so the deeper pipeline is still better here — but by 1.67×, not 2×.
Which of the following statements about an ideal five-stage pipeline is correct? (Single answer)
Show model answer
Answer 2. The pipeline overlaps instructions: the time of one instruction is still k cycles, but a new one completes every cycle once the pipeline is full, so n instructions take k + n − 1 cycles.
The quiz tests the latency/throughput distinction — the first bullet of the notes' p. 14. Options 1 and 3 are the same misconception in two forms.
Which of the following statements are true for the basic five-stage RISC-V pipeline? (Multiple answers)
Show model answer
Answers 1, 3 and 5.
Options 2 and 4 are the two claims of the notes corrected in this lesson (pp. 16–17). The 2026 paper uses "Multiple Choice – Multiple answer" quizzes of exactly this shape.
Check yourself
LD F2, 0(R1) is fetched in cycle 1. At the end of which cycle does the value of F2 exist for the first time anywhere in the processor?
A processor executes an instruction in 10 ns. It is pipelined into five stages of 2 ns. The time one instruction spends from its fetch to its write-back becomes…
SD F4, 0(R1) has just finished its ID stage. Which of these are in the ID/EX register at that moment?
A picture to keep: ID/EX holds the inputs of EX — two values, an immediate, the destination and the work order — never the result of EX.
Why does FADD not jump from EX straight to WB, skipping the MEM stage in which it has nothing to do?
A balanced seven-stage pipeline with no overhead and no hazards executes 50 instructions. How many clock cycles does it need?
On an ideal five-stage pipeline you double the program from 100 to 200 instructions. The speedup over sequential execution…
The exam paper writes ADDUI R1, R1, 8. Which instruction of the notes' RISC-V subset does the same thing?
Key take-aways
- Pipelining is an implementation technique that overlaps the five stages of consecutive instructions; it multiplies throughput by up to \(k\) and leaves the latency of one instruction unchanged.
- There are five stages because there are five resources, each used once per instruction: instruction memory, register read ports, ALU, data memory, register write port.
- \(n\) instructions take \(k + n - 1\) cycles: the \(k - 1 = 4\) fill cycles are paid once and are the "+4" of the course's cycle formula, Clock Cycles = IC + Stall Cycles + 4; the speedup \(nk/(k + n - 1)\) approaches \(k\) and never reaches it.
- The clock period is the slowest stage plus the pipeline-register overhead, so a deeper pipeline raises the ceiling by less than its depth.
- An ALU result is born at the end of EX, a loaded value at the end of MEM; a store reads its data in ID and writes memory in MEM; a branch compares in EX and loads the PC in MEM. No instruction skips a stage: idle stages are traversed, which keeps completion in order and one write per cycle.
- The pipeline registers IF/ID, ID/EX, EX/MEM, MEM/WB carry everything an in-flight instruction still needs — operands, immediate, destination number, control bits — and let the clock run at the pace of one stage.
- Three things break the ideal line: structural, data and control hazards. They are the next lessons.
What to watch and read
-
CPU Pipeline
Computerphile, Matt Godbolt≈ 22 min
The production-line picture told with pen and paper and no formulas: the best twenty minutes before reading anything about stages and cycles.
-
Interactive RISC-V CPU Visualizer: sequential vs pipelined
student project, GitHub Pages
One page, two modes — a single-cycle CPU and a five-stage pipelined one. Run the same program in both and compare the cycle counts: Fig. 2 of this lesson, live.
-
Ripes, a visual RISC-V pipeline simulator (browser build)
Morten Borup Petersen
Type the five instructions of the loop, step cycle by cycle and watch the real datapath: which multiplexer selects what, which pipeline register holds which value. Keep it open for lesson 2, where its forwarding switch becomes the point.
-
Hennessy & Patterson, Appendix C condensed to 74 slides
UIUC CS43374 slides
The textbook chapter the course page points to — Appendix A in the 4th edition is Appendix C in the 5th and 6th. Slide 2 is the speedup identity of this lesson; sections C.1 and C.2 are its scope.
-
Pipelining review
Mark Smotherman, Clemson
Five real pipelines side by side — the MIPS R2000 with 5 stages, the R4000 with 8, the Intel i486 with 5 — to see that the exam's five-stage machine was a real product, not a toy.