branch-prediction-and-speculation

Solid

Use when explaining branch predictors, mispredict penalties, speculative execution, Spectre or Meltdown mitigations, or branchless code. Not for pipeline stage theory: use cpu-pipelines-and-hazards.

AI & Automation 54 stars 10 forks Updated today Apache-2.0

Install

View on GitHub

Quality Score: 84/100

Stars 20%
58
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# Branch prediction and speculation ## Contract | Field | Bound contract | |---|---| | Trigger | Branchy hot code underperforms, a `likely` or branchless refactor needs judgment, a kernel mitigation such as retpoline or KPTI needs explaining, or code branches on secret data. | | Authority | Read-only. The skill runs `perf stat` on a user-named binary, reads sysfs, and answers in chat. Nothing on disk changes, so there is nothing to roll back. No remote mutation. | | Side effect | Chat output only. `perf stat` writes counters to stdout. | | Done | The answer names the branch that mispredicts or the speculation path that leaks, gives a measured `branch-misses` count where a binary exists, and states the fix with the condition under which it helps. | ## Inputs - Code or hot loop (required): the source or disassembly around the branch in question. - Binary and workload (optional): needed for a measured verdict. Without them the answer is a hypothesis. - Threat model (optional): whether the question is performance only or also side-channel safety. ## Procedure 1. Explain the mechanism in one pass. The front end predicts a direction for each conditional branch, executes the predicted path, and on resolve either commits or squashes the wrong-path work and refetches from the correct address. The squash cost grows with the distance from fetch to resolve, so a deeper pipeline pays more per mispredict. Backward branches are usually loop closers and predict taken; a data-dependent ...

Details

Author
OutlineDriven
Repository
OutlineDriven/outline-driven-development
Created
10 months ago
Last Updated
today
Language
Python
License
Apache-2.0

Similar Skills

Semantically similar based on skill content — not just same category