The full picture
- Predictor anatomy in one breath: BTB (where does this branch go), direction predictor (taken?), pattern/history tables (it alternates! it correlates with that other branch!), return-address stack for call/return — hardware learning your code's habits at run time.
- The software-visible corollary — predictable beats clever: the famous 'why is processing a sorted array faster' (random branch = 50% mispredict; sorted = near-perfect prediction). Branchless tricks (cmov, arithmetic masks) and JIT profile-guided layout exist for exactly the unpredictable cases.
- Spectre's mechanism, precisely: v1 — train the predictor past a bounds check, speculatively read out-of-bounds, encode the secret into which cache line got loaded, measure timings after the squash. Nothing architectural ever 'executed wrong'; the side channel leaked. Meltdown was the eviler cousin (speculating past privilege checks) fixed by KPTI.
- What a platform engineer inherited: KPTI/retpoline/IBRS costs (syscall-heavy workloads lost measurable %), cloud vendors' scramble, per-kernel mitigation toggles (
mitigations=offin trusted single-tenant niches), and browser-level timer coarsening — security now shows up in your latency budget.