All episodes · From One Switch to a CPU · Episode 13

How Modern CPUs Got Fast: Branch Prediction, Out-of-Order, Cores

Pressing play loads the video from YouTube.

The first single-chip processors ran about a hundred thousand instructions a second. One core today runs billions. A faster clock is only part of the story.
We see how a processor guesses which way a jump will go (and why it's usually right), how it runs independent instructions out of order but still hands back the results in order, and why clock speeds stopped climbing and chips got many cores instead.

Every animation in this video is drawn by code, and the narration is an AI voice.

Transcript

The first single-chip processors, in the early nineteen-seventies, ran about a hundred thousand instructions per second. A modern processor core runs billions. Faster clocks explain part of that. The rest comes from tricks. Today: three of the biggest. Guessing jumps, running instructions out of order, and using many cores.

Last time, a jump left the pipeline with instructions it had to throw away. So the processor guesses. A small table remembers what each jump did the last few times, and bets it will do the same again. Take our countdown loop. Each time around, the jump to the end is not taken, so the guess is: not taken. It's right every time until the very last, when the loop ends. Seven out of eight correct. Real loops run thousands of times, and real predictors are clever. They're right well over ninety percent of the time.

The second trick. Some instructions are slow. Loading from memory can take hundreds of ticks. The next instruction needs that value, so it has to wait. But the two after it don't need it at all. So the processor runs them first, while the load is still waiting. That's out-of-order execution. The results are still put back in the original order, so the program never notices. And a modern core can start several instructions on the same tick.

The third trick. Around two thousand five, clock speeds stopped climbing. Faster clocks meant too much heat. So chip makers put several complete processors, called cores, on one chip. Each core runs its own stream of instructions. Phones often have six or eight cores. Desktop chips often have eight, sixteen, or more. But more cores only help when the work can be split up. A program has to be written to share its work between them.

So: guess the jumps, run what's ready, and share the work between cores. But every one of these tricks stalls if data arrives slowly from memory. Next time: the small, fast memories that hide the wait. Caches. See you there.

Next episode: caches, the small, fast memories that hide the wait.

Buy the Developer a Coffee

Entirely up to you: it works the same either way.

Every cup turns into the next update.

WeChat Pay QR code
WeChat Pay
Alipay QR code
Alipay
PayPal QR code
PayPal