Execution inside the CPU, in 16 keywords

Learn how a core overlaps, reorders and guesses instructions, and when your code works against it.

Your win today You can answer the exam questions on ExecInsideCPU p.21 — whether an n-way superscalar CPU always runs n instructions in parallel, and whether a last-time predictor can learn an alternating branch. About 35 minutes.

1 · Instruction stages

instruction stages fetch · decode · execute · mem · write
An instruction is fetched from the cache, decoded into an operation and its inputs, executed, reads memory if needed, and writes its result back to registers ExecInsideCPU p.4. Every later trick overlaps or reorders these five stages.
subscalar CPU no implicit parallelism
The CPU runs one instruction at a time, so each instruction takes all five stages before the next one starts ExecInsideCPU pp.5–6. Two instructions already need about ten cycles, even without slow memory accesses ExecInsideCPU p.6.

In the slides' 5-stage model, which stage reads inputs from memory when an instruction needs them?

Decode only names the operation and its inputs; execute does the operation; mem accesses memory for inputs if needed ExecInsideCPU p.4.

On a subscalar CPU, when does instruction 2 start its fetch?

A subscalar CPU has no implicit parallelism: one instruction at a time ExecInsideCPU pp.5–6.

2 · Implicit parallelism inside one core

pipelining overlapping stages
Different instructions are in different stages at the same time: while one executes, the next decodes and a third is fetched ExecInsideCPU p.7. It is the fundamental way a core parallelises implicitly, without the programmer doing anything ExecInsideCPU p.7.
superscalar CPU n-way
The core issues several instructions in the same cycle, e.g. 4 per cycle on a 4-way superscalar CPU ExecInsideCPU p.8. n-way is a peak; it is reached only if n independent instructions are ready.
out-of-order execution OoO
The core executes an instruction as soon as its input data is available, not strictly in program order ExecInsideCPU p.9. Independent work fills the gaps while an earlier instruction waits, for example on memory ExecInsideCPU p.9.
data dependency r4 ← r1 + r5 needs r1
An instruction that reads a register written by an earlier one must wait for it; an independent instruction such as r6 ← r7 * r8 may run in parallel or even first ExecInsideCPU p.9. Dependencies, not the issue width, limit how many instructions really run together.
Hyper-Threading SMT
Modern CPUs build Hyper-Threading on superscalar and OoO execution to keep the core's resources busy ExecInsideCPU pp.8–9. Unlike multi-core and NUMA placement, it is handled internally by the CPU, not controlled from outside ExecInsideCPU p.22.

Program: (1) r1 ← r2 / r3, (2) r4 ← r1 + r5, (3) r6 ← r7 * r8. Which instruction may an OoO core run before (1)?

(2) needs r1 from (1); (3) is independent of both, so it can run in parallel or before them ExecInsideCPU p.9.

What does pipelining overlap?

Pipelining overlaps stages of different instructions in one core ExecInsideCPU p.7.

3 · Branches and prediction

branch penalty wasted pipeline slots
A jump is only resolved in its execute stage; without prediction, the instructions fetched behind it are thrown away and the target is fetched late ExecInsideCPU p.11. In the slide's example, two fetch slots are wasted and the jump target starts in cycle 4 instead of cycle 2 ExecInsideCPU p.11.
branch prediction unit BPU
Hardware that guesses whether the branch at an address is taken and, if so, the target address; CPUs use different logic for loops, jumps and IFs ExecInsideCPU p.13. A correct guess at decode lets the target be fetched in cycle 3, saving a slot ExecInsideCPU p.12; a wrong guess wastes the work.
last-time predictor 1-bit BHT
A one-bit Branch History Table entry per branch predicts the branch's last outcome and is updated after each execution ExecInsideCPU p.13. It is a "toy example"; modern CPUs use lots of execution history, some AMD CPUs even neural-network predictors ExecInsideCPU p.13.
branch-free code trade compute for branches
Rewrite an if into arithmetic that always runs, e.g. m += mdelta instead of if (month changed) m++ ExecInsideCPU p.14. You do a bit more work every time, but nothing can be mispredicted ExecInsideCPU p.14.

Without branch prediction, why are instructions 2 and 3 discarded in the slides' jmp example?

The jump is known only after its execute stage, so the instructions fetched after it were the wrong path ExecInsideCPU p.11.

What does a last-time predictor predict for a branch?

One bit per branch, set to the latest outcome ExecInsideCPU p.13.

4 · Internal accelerators

internal accelerators FPU · SIMD · AES-NI · NPU
CPUs contain specialised units for heavy workloads: floating-point units, vector (SIMD) instructions, crypto instructions such as Intel AES-NI, and NPUs for tensor operations ExecInsideCPU p.15. They are not always one per core: several FPUs can be shared across cores ExecInsideCPU p.15.

Which internal accelerator performs the same operation on a vector of data items?

SIMD instructions are data-parallel operations on vectors; NPUs target tensors and AES-NI crypto ExecInsideCPU p.15.

True for floating-point units in modern CPUs, according to the slides?

"Several units shared across cores (not always 1:1!)" ExecInsideCPU p.15.

5 · Instruction sets

CISC vs RISC x86 vs Arm
CISC instructions are complex (micro-code), take variable time and save memory; RISC instructions take predictable time and need more memory, which is no longer an issue ExecInsideCPU p.16. Real chips are "not so different": a 72-core Arm Grace and a 24-core x86 Xeon both sit at 250 W ExecInsideCPU p.17.
RISC-V RV32I / RV64I + M A F D C V
An open, royalty-free RISC ISA with a minimal integer base (no mul/div) and optional extensions; profiles like RVA23 fix standard combinations ExecInsideCPU p.18. Accelerators, NICs, storage controllers and even NVIDIA GPUs ship RISC-V cores ExecInsideCPU pp.18–19.
ISA vs micro-architecture what vs how
The ISA is the instruction set; the micro-architecture is how a chip implements it, from tiny controllers to wide superscalar OoO cores ExecInsideCPU p.18. A simple ISA does not mean a simple CPU: pipelining and speculation apply to RISC too ExecInsideCPU pp.16, 18.
Arm server CPUs NVIDIA Grace
Grace has 72 Arm Neoverse V2 cores and up to 480 GB LPDDR5X; a Superchip couples two chips (144 cores) via NVLink-C2C at 900 GB/s ExecInsideCPU p.19. Arm is now a real server option, so software can no longer assume x86 ExecInsideCPU pp.19, 21.

Which ISA can anyone implement or extend without a licence?

RISC-V is open and royalty-free; x86 is Intel/AMD only and Arm is licensed ExecInsideCPU p.18.

Why can a CISC instruction take a variable number of cycles?

CISC instructions are internally complex (micro-code) and also vary because of speculation under the hood ExecInsideCPU p.16.

6 · Use the keywords: the exam question

For for x in 0..N: if (x%2==0) do A else do B, can a last-time predictor learn the pattern? Which predictor would work, and how? ExecInsideCPU p.21 Try it on paper first, then open each step.

Step 1: Write the branch outcomes

The if alternates: taken, not taken, taken, not taken, … (T, N, T, N).

Step 2: Apply the last-time rule

It predicts the previous outcome. After T it predicts T but sees N; after N it predicts N but sees T. Every prediction is wrong: 0% accuracy ExecInsideCPU p.13.

Step 3: What would work

A predictor that uses history: remember the last outcome(s) of this branch and learn which outcome follows each history. After "T" comes "N" and after "N" comes "T", so it reaches ~100% after a short warm-up. Modern CPUs use exactly this kind of execution history ExecInsideCPU p.13.

Step 4: Alternative in software

Remove the branch: compute both paths as arithmetic and select with x%2, trading compute for no misprediction ExecInsideCPU p.14.

Exam answer pattern State the outcome sequence → simulate the predictor for 3–4 iterations → give the accuracy → name a history-based predictor and say what it stores.

7 · Keyword recall drill

instruction stagesAn instruction is fetched from the cache, decoded into an operation and its inputs, executed, reads memory if needed, and writes its result back to registers.
subscalar CPUThe CPU runs one instruction at a time, so each instruction takes all five stages before the next one starts.
pipeliningDifferent instructions are in different stages at the same time: while one executes, the next decodes and a third is fetched.
superscalar CPUThe core issues several instructions in the same cycle, e.g.
out-of-order executionThe core executes an instruction as soon as its input data is available, not strictly in program order.
data dependencyAn instruction that reads a register written by an earlier one must wait for it; an independent instruction such as r6 ← r7 * r8 may run in parallel or even first.
Hyper-ThreadingModern CPUs build Hyper-Threading on superscalar and OoO execution to keep the core's resources busy.
branch penaltyA jump is only resolved in its execute stage; without prediction, the instructions fetched behind it are thrown away and the target is fetched late.
branch prediction unitHardware that guesses whether the branch at an address is taken and, if so, the target address; CPUs use different logic for loops, jumps and IFs.
last-time predictorA one-bit Branch History Table entry per branch predicts the branch's last outcome and is updated after each execution.
branch-free codeRewrite an if into arithmetic that always runs, e.g.
internal acceleratorsCPUs contain specialised units for heavy workloads: floating-point units, vector (SIMD) instructions, crypto instructions such as Intel AES-NI, and NPUs for tensor operations.
CISC vs RISCCISC instructions are complex (micro-code), take variable time and save memory; RISC instructions take predictable time and need more memory, which is no longer an issue.
RISC-VAn open, royalty-free RISC ISA with a minimal integer base (no mul/div) and optional extensions; profiles like RVA23 fix standard combinations.
ISA vs micro-architectureThe ISA is the instruction set; the micro-architecture is how a chip implements it, from tiny controllers to wide superscalar OoO cores.
Arm server CPUsGrace has 72 Arm Neoverse V2 cores and up to 480 GB LPDDR5X; a Superchip couples two chips (144 cores) via NVLink-C2C at 900 GB/s.

8 · True / False

T / FIn a subscalar CPU, one instruction finishes all its stages before the next one starts.

True. No implicit parallelism: one instruction at a time ExecInsideCPU pp.5–6.

T / FOut-of-order execution means the CPU follows the program order strictly but faster.

False. It runs instructions when their inputs are ready, not in strict program order ExecInsideCPU p.9.

T / FIn the slide's example, r6 ← r7 * r8 may execute before r1 ← r2 / r3.

True. It is independent of the first two instructions ExecInsideCPU p.9.

T / FHyper-Threading is placed and controlled by the programmer, like NUMA pinning.

False. Multi-core and NUMA can be controlled from outside; Hyper-Threading is handled inside the CPU ExecInsideCPU p.22.

T / FA branch prediction unit predicts both whether a branch is taken and its target address.

True ExecInsideCPU p.13.

T / FModern CPUs base branch predictions on a lot of execution history.

True. The 1-bit last-time predictor is only a toy example ExecInsideCPU p.13.

T / FBranch-free code always does less work than the branching version.

False. It trades more compute for having no branches ExecInsideCPU p.14.

T / FThe RISC-V base ISA RV32I includes multiply and divide instructions.

False. Mul/div come with the M extension; the base is integer-only ExecInsideCPU p.18.

T / FBecause RISC-V is a simple ISA, RISC-V CPUs cannot use pipelining or speculation.

False. A simple ISA does not mean a simple CPU ExecInsideCPU p.18.

T / FEvery CPU core has its own private floating-point unit.

False. FPUs can be shared across cores, not always 1:1 ExecInsideCPU p.15.

9 · What is …?

What isthe job of each of the five instruction stages

Show answer

Fetch the instruction from the cache, decode the operation and its inputs, execute it, access memory for inputs if needed, write results back to registers ExecInsideCPU p.4.

What isan n-way superscalar CPU

Show answer

A core that issues up to n instructions in the same cycle, e.g. 4 on a 4-way CPU ExecInsideCPU p.8.

What isthe difference between pipelining and superscalar execution

Show answer

Pipelining overlaps different stages of successive instructions; superscalar issues several instructions in the same cycle ExecInsideCPU pp.7–8.

What isa 1-bit Branch History Table

Show answer

One bit per branch holding its last outcome, updated after each execution; it implements the last-time predictor ExecInsideCPU p.13.

What isAES-NI

Show answer

An Intel instruction-set extension that implements common cryptographic operations (partly) in hardware ExecInsideCPU p.15.

What ismicro-code in a CISC CPU

Show answer

The internal implementation of complex instructions as sequences of simpler steps, which makes their run time variable ExecInsideCPU p.16.

What isthe role of RISC-V extensions and profiles

Show answer

Extensions add features to the integer base (M mul/div, A atomics, F/D floats, C compressed, V vector); profiles such as RVA23 fix standard combinations for binary compatibility ExecInsideCPU p.18.

What isthe GPU System Processor (GSP)

Show answer

A RISC-V core inside NVIDIA GPUs that runs a large part of what used to be the graphics driver; 10–40 RISC-V microcontrollers manage power, clocks and security ExecInsideCPU p.19.

10 · Calculations

ComputeA program has 100 instructions; every instruction needs 5 stages of 1 cycle. How many cycles does it take on a subscalar CPU, and on an ideal 5-stage pipeline? What is the speedup?

Show solution

Subscalar: each instruction takes all 5 stages alone: 100 × 5 = 500 cycles ExecInsideCPU pp.5–6. Pipeline: the first instruction needs 5 cycles, then one finishes per cycle: 5 + (100 − 1) = 104 cycles ExecInsideCPU p.7. Speedup = 500 / 104 ≈ 4.8×, close to the stage count.

ComputeThe slide shows 12 instructions on a 4-way superscalar CPU with 5 stages. Ideally, how many cycles until all 12 finish? Compare with a 1-wide pipeline.

Show solution

4 instructions enter per cycle, so the 12 enter in 12 / 4 = 3 cycles. The last group finishes 5 − 1 cycles later: 5 + (3 − 1) = 7 cycles ExecInsideCPU p.8. A 1-wide pipeline needs 5 + (12 − 1) = 16 cycles, so ≈ 2.3× faster, not 4×, because of the fill time.

ComputeUsing the slides' jmp example, a jump without prediction wastes 2 fetch slots and a correctly predicted jump at decode wastes 1. A pipelined program runs 1 000 instructions, of which 100 are taken jumps. Estimate the cycles in both cases.

Show solution

Base pipeline: 5 + 999 = 1 004 cycles. Without prediction: + 100 × 2 = 1 204 cycles ExecInsideCPU p.11. With correct prediction at decode: + 100 × 1 = 1 104 cycles ExecInsideCPU p.12. Prediction removes about 100 cycles, ~8%.

ComputeA loop runs 10 iterations and is executed many times. Its loop branch is taken 9 times, then not taken once at the exit. What accuracy does a last-time predictor reach on it?

Show solution

Per run it mispredicts the exit (predicts taken, sees not taken) and the first iteration of the next run (predicts not taken, sees taken): 2 misses out of 10. Accuracy = 8 / 10 = 80% ExecInsideCPU p.13.

ComputeGrace C1 has 72 cores and up to 512 GB/s of memory bandwidth; the Xeon Gold 6542Y has 24 cores. Both are rated 250 W. Compute the memory bandwidth per Grace core and the cores per watt of each. Each Grace core has 4 × 128-bit SVE2 units: how many 32-bit float lanes is that per core?

Show solution

Bandwidth per core: 512 / 72 ≈ 7.1 GB/s. Cores per watt: 72 / 250 ≈ 0.29 vs 24 / 250 ≈ 0.10, about 3× ExecInsideCPU p.17. Lanes: 4 × 128 / 32 = 16 float lanes per core ExecInsideCPU p.17.

11 · Exam-style questions (written)

  1. Explain. An n-way superscalar CPU can always execute n instructions in parallel. Is this statement true? Explain why ExecInsideCPU p.21.
  2. Compare. CISC vs RISC: compare instruction timing, memory use and where each is used today, and argue why the slides call them "not so different" ExecInsideCPU pp.16–17.
  3. Argue. Arm CPUs are spreading in server workloads. Explain what limitations, if any, applications need to overcome when running on Arm instead of x86 ExecInsideCPU p.21.
  4. Transfer. A filter loop does if (x[i] < t) count++ over random data. Explain why it runs slowly on a modern core and sketch a branch-free rewrite; what does the rewrite cost? ExecInsideCPU pp.13–14

Bring your answers to the chat and I'll grade them the way an examiner would.

Read next

Primary source: the deck itself (../lectures/Lecture_04_ExecInsideCPU.pdf, pp.4–14 are the core). For depth on predictors, the predictor figure comes from Onur Mutlu's computer-architecture lectures (credited on p.13). Review with the cheat sheet.