Just a blog

Computer CPU architectures

A CPU does one thing over and over: fetch an instruction, decode it, execute it, next. Billions of times per second. How it does that is its architecture, and the word covers two layers:

  • the instruction set architecture (ISA): the contract with the software. Which instructions exist, which registers, how memory is addressed. x86-64, ARM and RISC-V are ISAs.
  • the microarchitecture: how one chip implements that contract. Pipelines, caches, predictors… An AMD core and an Intel core both run the same x86-64 programs, but they are very different machines inside.

Where does the program live? Von Neumann vs Harvard

Von Neumann: one memory and one bus for instructions and data. Harvard: separate instruction and data memories, each with its own bus.

In a von Neumann machine, the program and its data sit in the same memory, behind the same bus. Simple and flexible (a program is just data: it can be loaded, or even generated), but the CPU can’t fetch its next instruction while it reads or writes data. That’s the von Neumann bottleneck.

A Harvard machine gives instructions and data their own memories and buses, so both happen at once. Many microcontrollers work like this, like the AVR of the Arduino Uno.

Your PC is a modified Harvard mix: one RAM for everything, but separate L1 caches for instructions and for data, right next to the core.

CISC vs RISC

  • CISC (complex instruction set): many instructions, of variable length, some doing a lot at once: load from memory, add, store back, in a single instruction. x86 is the famous one, it goes back to the Intel 8086 of 1978.
  • RISC (reduced instruction set): fewer, simpler, fixed-length instructions, and only loads and stores touch memory (a load–store architecture). Easier to decode and to pipeline. John Hennessy and David Patterson, who led the early RISC projects at Stanford and Berkeley, received the 2017 Turing Award for this work.

Today the line is blurry: x86 chips translate their instructions into simple RISC-like micro-operations internally, and ARM kept growing its instruction set.

The big families

Timeline: Intel 4004 in 1971, x86 in 1978, ARM in 1985, MIPS and SPARC in 1985-86, PowerPC in 1992, x86-64 in 2003, AArch64 in 2011, RISC-V in 2014, Apple M1 in 2020.
ISA Type Since Where you meet it
x86 / x86-64 CISC 1978 / 2003 PCs, laptops, servers, PS4/PS5, Xbox One/Series
ARM / AArch64 RISC 1985 / 2011 almost every phone, Apple silicon Macs, Raspberry Pi, AWS Graviton servers
RISC-V RISC 2014 microcontrollers (like the ESP32-C3), embedded, research. Open and royalty-free
MIPS RISC 1985 routers, PlayStation 1 and 2, Nintendo 64
PowerPC RISC 1992 Macs before 2006, GameCube, Wii, Xbox 360, PS3
SPARC RISC 1986 Sun / Oracle servers

Pipelining: an assembly line for instructions

Five instructions going through the five stages IF, ID, EX, MEM and WB, each one starting a cycle after the previous one. At cycle 5 all five stages are busy.

Running one instruction takes several steps. The classic RISC pipeline has five: fetch (IF), decode (ID), execute (EX), memory access (MEM), write back (WB). Rather than waiting for an instruction to finish, the CPU starts the next one a cycle later, like an assembly line: each instruction still takes 5 cycles, but once the line is full, one finishes every cycle. That’s instruction pipelining.

The catch is hazards: an instruction that needs the result of the one just before it, or a branch whose direction isn’t known yet, stalls the line. So modern cores add:

  • branch prediction: guess which way the branch goes and keep going (speculative execution). A wrong guess throws the work away, and the traces it leaves in the caches gave us Spectre.
  • superscalar execution: several pipelines side by side, so more than one instruction per cycle (IPC above 1).
  • out-of-order execution: run whichever instructions have their inputs ready, not strictly in program order, then retire them in order.

The memory wall

Memory hierarchy: registers, L1, L2 and L3 caches, RAM and SSD, each level bigger and slower than the one above.

A core adds two numbers in a fraction of a nanosecond, but a trip to RAM costs around 100 ns: hundreds of cycles doing nothing. So between the core and the RAM sit caches: small and fast close to the core, bigger and slower further away. That’s the memory hierarchy. It works because programs tend to reuse the same data, and the data right next to it. Code that walks memory in order flies, code that jumps around at random spends its time waiting.

More cores, wider cores

Around 2005, clock speeds stopped climbing: Dennard scaling ended, and a faster clock meant too much heat. So the transistors went elsewhere:

  • multi-core: several complete cores on one chip. Often mixed, big fast cores next to small efficient ones (big.LITTLE on phones, Apple M-series, Intel since Alder Lake).
  • simultaneous multithreading (Hyper-Threading at Intel): one core runs two threads, to fill its idle units.
  • SIMD: one instruction working on a whole vector of values. SSE and AVX on x86, NEON and SVE on ARM. Great for graphics, audio, physics, AI.

Further reading

  • Computer architecture on Wikipedia, and every link above.
  • Computer Organization and Design and Computer Architecture: A Quantitative Approach, by Hennessy & Patterson: the classic books.