Foundations of ComputingDeeper

Kayavak / Foundations of Computing / CS·07 Computer Architecture / Deeper

Deeper · Foundations of Computing

Computer Architecture

The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.

Why does this exist?

Processors got faster much more quickly than memory. By the mid-1990s a CPU could finish dozens of instructions in the time one value arrived from RAM; William Wulf and Sally McKee called it "the memory wall" in 1995. Most of modern computer architecture is the response to that gap and to the limits of making one instruction stream faster.

The ideas arrived one by one. Pipelining, overlapping the stages of successive instructions, appeared in IBM's Stretch (1961). Maurice Wilkes proposed small fast "slave memories" in 1965, and IBM's System/360 Model 85 (1968) shipped the first commercial cache. In the late 1970s and early 1980s, IBM's 801 research machine, David Patterson's Berkeley RISC and John Hennessy's Stanford MIPS argued for RISC: simple, regular instructions a compiler can schedule and hardware can pipeline deeply. Around 2005 the old trick of raising the clock speed stopped working, because power and heat no longer fell as transistors shrank (the end of Dennard scaling), so chips turned to multiple cores and wider vector units instead.

The mental model

Try it yourself first: write your own model in the Mental Model Explorer, then compare.

A CPU is a very fast worker starved for data. Everything between it and memory (registers, caches, prefetchers, predictors) exists to guess what it will need next and have it ready.

Question Answer
What is it? An instruction set implemented by a pipeline of stages, fed by a hierarchy of memories
Problem it solves Running as many instructions per second as possible despite slow memory
Parts Registers, ALUs, a pipeline, branch predictor, caches (L1–L3), memory controller, cores, vector units
How it works Fetch–decode–execute, overlapped and reordered; data moves in 64-byte lines kept coherent across cores
Assumptions Programs reuse recent data (temporal locality) and read nearby data (spatial locality); branches are predictable
When they change Random access and unpredictable branches drop a core from several instructions per cycle to a small fraction of one
Where it fails Shared data written by several cores (coherence traffic, false sharing); speculation that leaks secrets (Spectre)
Related ideas Data layout decides cache behaviour (ch03); the OS shares cores (ch08); compilers schedule instructions (ch10)

What if?

What if there were no caches?

Reason it through, then open

Every load would go to main memory, about 100 ns away. A 3 GHz core runs 300 cycles in that time, so a loop that reads memory each iteration would be one or two hundred times slower. Clever instruction scheduling wouldn't help much: almost every instruction would be waiting. The derivation below shows how much a cache with even a modest hit rate buys.

What if the branch predictor were always right?

Reason it through, then open

The pipeline would never be flushed, so code with unpredictable ifs (sorting-dependent filters, parsing, interpreters) would speed up noticeably, and tricks like branchless code would lose their point. The branch-based Spectre attacks would stop working too, because they depend on training the predictor to guess wrong and then reading what the wrongly speculated code left in the cache. Other speculation attacks, such as Meltdown and speculative store bypass, don't involve branch prediction, so a perfect predictor wouldn't stop them.

Where the boundary is

Aspect Instruction set architecture (ISA) Microarchitecture
What it is The contract: instructions, registers, memory model How one chip implements that contract
Examples x86-64, ARM64, RISC-V Pipeline depth, cache sizes, number of execution units
Changes Rarely, and compatibly Every chip generation
Visible to programs Always Only as speed (and in side channels)
Confused because "Faster CPU" usually means a better microarchitecture of the same ISA

Derive it

Average memory access time. Each access first tries the cache; misses go on to memory.

  1. Every access pays the cache's hit time, say 1 ns.
  2. A fraction of accesses miss (the miss rate, say 5%) and each pays an extra miss penalty, say 100 ns.
  3. So the average is AMAT = hit time + miss rate × miss penalty = 1 + 0.05 × 100 = 6 ns.
  4. Without the cache every access costs 100 ns: the cache makes memory look about 16 times faster, even though it misses one access in twenty.
  5. The formula nests: an L2 miss penalty is itself an AMAT of L3 and memory. And it shows why a miss rate going from 2% to 10%, often just a change of traversal order, multiplies average cost.

How sure are we?

Claim How it's known Where from
AMAT = hit time + miss rate × miss penalty Model Standard in architecture texts; ignores overlapping misses and prefetching
Column-order traversal of a row-major array is about 10× slower Measured The chapter's lab, on its machine; the ratio varies by hardware
Cache lines are 64 bytes on x86 Convention Chosen by chip designers; Apple's M-series report 128 bytes
Clock speeds stopped rising around 2005 because of power Historical The end of Dennard scaling, widely documented

Still open

Where performance comes from next is open: more specialised accelerators (GPUs, tensor units), processing near or inside memory, chiplets, and new security designs after Spectre. How to make speculation safe without losing its speed is still an active research and engineering problem.

What would change your mind? If memory latency caught up with processor speed, most of the chapter's advice about locality would stop mattering. Every generation so far has widened the gap instead.

Recall

What is the average memory access time formula?

Hit time + miss rate × miss penalty.

What's the difference between an ISA and a microarchitecture?

The ISA is the contract programs see; the microarchitecture is how a particular chip implements it.

Why did processors turn to multiple cores around 2005?

Raising clock speed stopped being possible within power and heat limits (the end of Dennard scaling).

Which two kinds of locality do caches rely on?

Temporal (reusing recent data) and spatial (using nearby data).

Would a perfect branch predictor prevent every speculation attack?

No; it would stop the branch-based Spectre variants, but attacks like Meltdown and speculative store bypass don't rely on branch prediction.

Reflect

Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.