CAComputer Architecture · Lesson 7 of 7

Architecture Cheatsheet

The numbers and mental models worth memorizing, on one page.

Text
── Number representation ────────────────
bit=0/1   byte=8 bits=256 values   0xFF = 255
binary 1011 = 8+2+1 = 11   |  1 hex digit = 4 bits
two's complement: negate = flip bits + 1
  signed 8-bit range: -128..127; overflow wraps
floats (IEEE 754): sign × fraction × 2^exp
  -> 0.1 + 0.2 != 0.3 in every language

── The CPU loop ─────────────────────────
fetch -> decode -> execute, billions/sec
registers: ~16 slots, where all work happens
pipeline: overlap stages | superscalar: >1 instr/cycle
branch predictor ~95%+ right; miss = ~15-20 cycles
out-of-order: hardware reorders independent work

── Memory hierarchy (approx.) ───────────
registers   0 cyc
L1          ~4 cyc      64 KB      cache line = 64 bytes
L2          ~12 cyc     ~1 MB
L3          ~40 cyc     ~32 MB
RAM         ~200 cyc    GBs
SSD         ~100K cyc
network     millions

sequential access >> random access, every level
arrays beat linked lists: locality, not big-O
Text
── Latency numbers to memorize ──────────
L1 ref               1 ns
branch mispredict    3 ns
RAM ref            100 ns
SSD random read     16 µs
datacenter RTT     500 µs
disk seek            2 ms
US<->EU packet     150 ms

rule: batch network/disk work; N+1 queries kill apps

── How code runs ────────────────────────
AOT compiled (C/Rust/Go):  source -> machine code, fastest
JIT (JS/Java/C#):  interpret, compile hot paths at runtime
interpreted (Python/Ruby):  ~30-100x slower tight loops
x86-64 (desktop/server) vs ARM64 (phones, Apple, Graviton)
  = different instruction sets, binaries not portable

── Parallelism ──────────────────────────
clock speeds stalled ~2005 (power wall) -> more cores
Amdahl: speedup capped by serial fraction
  90% parallel -> max 10x, ever
counter++ = load,add,store -> data race without locks
SIMD: one instruction, 8-16 values (NumPy, codecs)
GPU: thousands of simple cores, uniform work
false sharing: two cores fighting over one cache line

── Tools ────────────────────────────────
godbolt.org         see your code's assembly
lscpu / sysctl      your CPU's specs
perf / Instruments  where time actually goes