Lecture 04 · Code Execution on a CPU
The whole deck on two pages.
Page numbers refer to ../lectures/Lecture_04_ExecInsideCPU.pdf.
Execution models
| Model | What happens | Limit | p. |
|---|---|---|---|
| subscalar | one instruction at a time, all 5 stages | ~10 cycles for 2 instructions | 5–6 |
| pipelining | stages of different instructions overlap | fill time, branches | 7 |
| superscalar (n-way) | n instructions issued per cycle | needs n independent instructions | 8 |
| out-of-order | run when inputs are ready | true data dependencies | 9 |
| Hyper-Threading | built on superscalar + OoO to keep units busy | handled inside the CPU | 8–9, 22 |
- Stages: fetch → decode → execute → mem → write p.4
- Dependency example: r4 ← r1 + r5 waits for r1 ← r2 / r3; r6 ← r7 * r8 is free p.9
Branches
- Jump resolved at execute → 2 wrong-path slots, target fetched in cycle 4 p.11
- Predicted at decode → 1 slot lost, target fetched in cycle 3 p.12
- BPU: taken? and target? Different logic for loops, jumps, IFs; hardware, complex p.13
- Last-time predictor: 1-bit BHT per branch, updated after each execution; toy example p.13
- Modern predictors use long history; some AMD CPUs used NN-based predictors p.13
- Branch-free code: replace the if with arithmetic (m += mdelta); more compute, no mispredictions p.14
Internal accelerators
- FPU (shared across cores, not always 1:1), SIMD, crypto (AES-NI), NPUs for tensors p.15
ISAs
| CISC (x86) | RISC (Arm, RISC-V) | |
|---|---|---|
| Instructions | complex, micro-code | simple |
| Timing | variable | predictable (speculation still exists) |
| Memory / compiling | saves memory, easier to compile to | more memory, harder to compile for — no longer an issue |
p.16
- Not so different: Grace C1 (72 Arm V2 cores, 4×128b SVE2, 114 MB L3, up to 512 GB/s) vs Xeon Gold 6542Y (24 cores / 48 threads, 60 MB, 2.9 GHz); both 250 W p.17
- RISC-V: open, royalty-free (Berkeley ~2010); base RV32I/RV64I without mul/div; extensions M, A, F/D, C, V (2021); profiles e.g. RVA23 p.18
- ISA ≠ micro-architecture: a simple ISA does not mean a simple CPU p.18
- RISC-V inside NVIDIA GPUs: 10–40 MCUs, GSP runs much of the driver, replaced Falcon from 2016 p.19
- Grace (2023): 72 Neoverse V2 cores, ≤480 GB LPDDR5X; Superchip 144 cores via NVLink-C2C 900 GB/s; Grace Hopper/Blackwell = CPU + GPU with coherent unified memory p.19
Summary
- Servers: multiple CPUs, multi-core, hyper-threaded; NUMA controllable from outside, Hyper-Threading internal p.22
- Efficiency depends on correct speculation: prefetching, branch prediction; don't work against the CPU p.22
Exam-style questions from the deck p.21
- An n-way superscalar CPU can always execute n instructions in parallel. True? Explain why.
- Can a "Last Time" branch predictor learn the pattern of
if (x%2==0) A else Bin a loop? Which predictor would work well, and how? - Arm CPUs are becoming widespread in servers. What limitations, if any, must applications overcome on Arm vs x86?