Branch Prediction and Speculation

Branch prediction and speculation skill for CPU security and performance. Use when explaining branch predictors, mispredict penalties, speculative execution, Spectre/Meltdown mitigations, or branchless patterns. Activates on queries about branch prediction, speculative execution, Spectre, Meltdown, mispredict, or branchless code.

293 stars 36 forksGit & Code Review

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add mohitmishra786/low-level-dev-skills --skill branch-prediction-and-speculation
Manual install
git clone --depth 1 https://github.com/mohitmishra786/low-level-dev-skills.git /tmp/low-level-dev-skills
mkdir -p ~/.claude/skills
cp -r /tmp/low-level-dev-skills/skills/computer-architecture/branch-prediction-and-speculation ~/.claude/skills/branch-prediction-and-speculation

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Branch Prediction and Speculation

## Purpose

Explain how modern CPUs predict branches, execute speculatively, recover on mispredict, and why speculation created side channels (Spectre/Meltdown) — linking performance tuning with security-aware low-level coding.

## When to Use

- Hot loop branchy code underperforms expectations
- Evaluating `likely`/`unlikely` or branchless refactors
- Understanding kernel `retpoline`, IBRS, and similar mitigations
- Secure coding around secret-dependent branches

## Workflow

### 1. Branch predictor basics

```
Fetch sees conditional branch
├── Predict direction (taken / not-taken)
├── Speculatively execute predicted path
└── On resolve:
    ├── Correct → commit, ~0 penalty (deep pipelines still cost on mispredict)
    └── Wrong → squash, refill from correct PC (10–20+ cycles typical)
```

Patterns: backward branches often predicted taken (loops); forward not-taken.

### 2. Performance patterns

```c
/* Predictable — tight loop backward branch */
for (int i = 0; i < n; i++)
    sum += a[i];

/* Unpredictable — data-dependent */
if (data[i] > threshold)  /* hard to predict */
    rare_path();
```

Techniques: branchless `cmov`/select, lookup tables, sorting data to reduce branches, splitting hot/cold paths.

```c
/* Branchless min (integer) */
int m = a < b ? a : b;  /* compiler may lower to cmov */
```

### 3. Compiler hints (use sparingly)
Read the full skill on GitHub

Details

Skill name
branch-prediction-and-speculation
Path
skills/computer-architecture/branch-prediction-and-speculation/SKILL.md
License
MIT
Repo updated
14 November 2026

FAQ

What does the Branch Prediction and Speculation skill do?

Branch prediction and speculation skill for CPU security and performance. Use when explaining branch predictors, mispredict penalties, speculative execution, Spectre/Meltdown mitigations, or branchless patterns. Activates on queries about branch prediction, speculative execution, Spectre, Meltdown, mispredict, or branchless code.

How do I install the Branch Prediction and Speculation skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add mohitmishra786/low-level-dev-skills --skill branch-prediction-and-speculation. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Branch Prediction and Speculation popular?

It lives in mohitmishra786/low-level-dev-skills, which has 293 GitHub stars and 36 forks.

Related skills

Abi and Calling Conventions

293

mohitmishra786/low-level-dev-skills

ABI and calling conventions skill for cross-language boundaries. Use when explaining System V AMD64, ARM AAPCS, RISC-V psABI, stack frames, variadic calls, or FFI register rules. Activates on queries about calling convention, ABI, System V AMD64, AAPCS, stack frame, variadic function, or FFI registers.

Software Development36

Adc Dac Baremetal

293

mohitmishra786/low-level-dev-skills

Bare-metal ADC and DAC skill. Use when configuring analog sampling, DMA-driven ADC, calibration, or DAC output on MCUs. Activates on queries about ADC bare-metal, sampling time, DMA ADC, or DAC channel setup.

Other36

Af Xdp

293

mohitmishra786/low-level-dev-skills

AF_XDP skill for high-performance XDP sockets. Use when creating AF_XDP sockets, configuring UMEM and XSK rings, XDP_REDIRECT programs, copy vs zero-copy mode, or comparing with DPDK. Activates on queries about AF_XDP, xsk_umem, XDP_REDIRECT, libbpf xsk, or zero-copy XDP.

Software Development36

Hardware Counters

293

mohitmishra786/low-level-dev-skills

Hardware performance counter skill for low-level CPU analysis. Use when collecting PMU events with perf stat, using the PAPI library, measuring cache miss rates and branch misprediction ratios, computing IPC, or correlating PMU events to source lines. Activates on queries about hardware counters, PMU events, perf stat -e, PAPI, cache miss rate, branch misprediction, IPC measurement, or CPU performance events.

Git & Code Review36

Maintain Verification Skill

107

Dimon94/skills

Periodic pass that keeps a project's verification skill and feature map honest: parallel source readers per feature, one live session driving every feature, at most one PR of proven corrections. Use for /maintain-verification-skill or "audit the verify skill".

Git & Code ReviewIn 2 lists21

C Github

179

daxaur/openpaw

Interact with GitHub using the `gh` CLI and `jq`. Manage PRs, issues, repositories, and Actions workflows. Make raw API calls with `gh api` for anything not covered by built-in commands.

Git & Code ReviewIn 1 list13

Browse the most popular Claude skills, all git & code review skills, or write your own with the skills generator.