What Every Programmer Should Know about How CPUs Work
summary
Modern CPUs use an in-order front end, out-of-order execution back end and heavy branch prediction, and that matters: a tiny loop in Python runs about 80 ms faster when data is sorted because branch prediction improves; the same loop in C++ compiles to a conditional move and runs ≈8 ms, but forcing branches raises it to ≈39 ms. Replacing a modulus (division) with a power-of-two mask drops a hashed loop from ~148 cycles to ~33 cycles. Randomized pointer chasing turns an 11 ms array walk into ~1.3 s. Measurements use perf counters, Compiler Explorer and llvm-mca for microarchitectural insight.
AI-written summary · about
chapters (15)
- 0:00Intro
- 0:25What to get out of this talk
- 1:13A modern CPU pipeline
- 11:47Branch prediction
- 21:27Demo
- 26:15Execution
- 28:56Demo
- 34:53Can the compiler save us?
- 35:08Demo
- 36:46Memory
- 37:52Results
- 40:11Top-down analysis
- 41:12Perf
- 42:06Conclusion
- 43:11Outro
related talks
01h 00mOut-of-order execution - what can it do for me?
01h 02mMegahertz, Gigahertz, Registers and Instructions: How does a CPU actually work?
01h 05mMegahertz, Gigahertz, Registers and Instructions: How does a CPU actually work?
29mConcurrency and Parallelism From The Ground Up
01h 16mA New Golden Age for Computer Architecture
19mHow NOT To Program an Out-of-order Vector Processor
48m“Is Parallel Programming still hard? PART 2 of 2”
19mDo nothing fast: How to scale idle cpus?
