Skip to main content
skill CX Codex

cpu-pipelines-and-hazards — Claude Code skill: pipelines and hazards

Walks through CPU pipeline stages, data and control hazards, forwarding and stalls. Useful when a hot loop slows down and the reason is not obvious.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add mohitmishra786/low-level-dev-skills --skill cpu-pipelines-and-hazards -a claude-code
Open on GitHub

What cpu-pipelines-and-hazards does

The skill covers the classic five-stage pipeline IF → ID → EX → MEM → WB and what breaks it. RAW hazards get fixed by forwarding from EX/MEM/WB, while WAR and WAW show up once register renaming enters the picture in out-of-order cores. Control hazards are handled through branch prediction and flushing wrong-path instructions, with the penalty tied to pipeline depth.

Structural hazards get their own section: a single memory port stalls execution even with no dependency in sight. The practical half shows a tight accumulation chain next to a multi-accumulator version that raises ILP, plus a perf stat -e instructions,cycles,stalls-frontend,stalls-backend run and a symptom table. High stalls-frontend points at I-cache misses, no gain from unrolling usually means memory bound, and a wrong cycle model comes from ignoring OoO execution.

Related topics are linked rather than duplicated: branch prediction and speculation, the memory hierarchy, cache-line effects, Intel VTune and AMD uProf, ARM instruction scheduling. One warning stands out — never tune MMIO delays with NOP. Profiling needs perf and access to hardware counters, and those are often unavailable inside VMs and containers, so check the environment before trusting the numbers.

What it helps with

  • explain why instruction order changes throughput
  • trace a RAW dependency in an assembly loop and break it
  • map pipeline stall metrics from VTune to pipeline stages
  • tell a memory-bound loop apart from a data hazard
  • find the cause of a sudden performance cliff in a hot loop

Example prompts for the agent

  • /cpu-pipelines-and-hazards Explain RAW hazard in this ARM assembly loop and how to break it
  • Show me where the data hazard is in this loop and how multiple accumulators fix it
  • What does a high stalls-frontend value in perf stat mean for my app?

How to install cpu-pipelines-and-hazards

1Skills CLI (Vercel)

npx skills add mohitmishra786/low-level-dev-skills --skill cpu-pipelines-and-hazards -a claude-code

2Manually: put the files in place

~/.claude/skills/cpu-pipelines-and-hazards/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/cpu-pipelines-and-hazards/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about cpu-pipelines-and-hazards

How do I install cpu-pipelines-and-hazards in Claude?

Run npx skills add mohitmishra786/low-level-dev-skills --skill cpu-pipelines-and-hazards -a claude-code. The skill lands at ~/.claude/skills/cpu-pipelines-and-hazards/SKILL.md.

What does cpu-pipelines-and-hazards do?

It explains CPU pipeline stages, data and control hazards, forwarding, stalls and branch handling. The goal is linking instruction order to hardware behaviour and profiler counters.

Which skills does it work alongside?

It points to branch prediction and speculation, the memory hierarchy and caches, cache optimization, Intel VTune and AMD uProf, and ARM instruction scheduling.

Source text

SKILL.md · MIT
---
name: cpu-pipelines-and-hazards
description: CPU pipeline skill for hazards, forwarding, and stalls. Use when explaining pipeline stages, data/control hazards, forwarding paths, or branch stalls in performance analysis. Activates on queries about pipeline hazard, data hazard, control hazard, forwarding, pipeline stall, or superscalar basics.
---

# CPU Pipelines and Hazards

## Purpose

Explain classic and modern CPU pipeline concepts: stages, data and control hazards, forwarding/bypassing, stalls, and branch handling — foundational for optimization and understanding microarchitecture counters.

## When to Use

- Interpreting pipeline stall metrics from `skills/profilers/intel-vtune-amd-uprof`
- Teaching why instruction order affects throughput
- Relating assembly scheduling to hardware behavior
- Debugging unexpected performance cliffs in hot loops

## Workflow

### 1. Five-stage classic pipeline (MIPS-style mental model)

```
IF → ID → EX → MEM → WB
```

Overlapped execution: instruction N in EX while N+1 in ID.

### 2. Data hazards

| Type | Example | Mitigation |
|------|---------|------------|
| RAW (true) | `add r1,r2,r3` then `sub r4,r1,r5` | Forwarding from EX/MEM/WB |
| WAR / WAW | Rare in in-order; relevant in OoO rename | Register renaming |

Without forwarding:

```
stall until writeback completes
```

### 3. Control hazards (branches)

```
Branch in ID → target unknown until EX
├── Predict taken/not-taken (static or dynamic)
├── Flush wrong-path instructions on mispredict
└── Penalty = pipeline depth (varies by CPU)
```

See `skills/computer-architecture/branch-prediction-and-speculation`.

### 4. Structural hazards

Limited functional units (single memory port) cause stalls even without dependencies.

### 5. Practical optimization hints

```c
/* Bad — tight dependency chain */
for (int i = 0; i < n; i++)
    acc = acc + data[i];   /* each iter waits on acc */

/* Better — multiple accumulators (ILP) */
acc0 = acc1 = 0;
for (int i = 0; i < n; i += 2) {
    acc0 += data[i];
    acc1 += data[i+1];
}
acc = acc0 + acc1;
```

Pair with `skills/low-level-programming/cpu-cache-opt` — memory often dominates.

### 6. Reading uops / ports (x86)

```bash
perf stat -e instructions,cycles,stalls-frontend,stalls-backend ./app
```

VTune "Microarchitecture Exploration" maps to pipeline slots.

### 7. Agent usage

```
/cpu-pipelines-and-hazards Explain RAW hazard in this ARM assembly loop and how to break it
```

## Common Problems

| Symptom | Cause | Fix |
|---------|-------|-----|
| High `stalls-frontend` | I-cache misses / branch mispredict | Align hot loop; see branch skill |
| No speedup from unroll | Memory bound | Profile loads; prefetch |
| Wrong cycle model | Ignored OoO execution | Use perf hardware counters |
| "NOP fixes it" | Timing-sensitive MMIO | Never tune device delays by NOP |

## Related Skills

- `skills/computer-architecture/branch-prediction-and-speculation` — mispredict cost
- `skills/computer-architecture/memory-hierarchy-and-caches` — load latency
- `skills/low-level-programming/cpu-cache-opt` — cache-line effects
- `skills/profilers/intel-vtune-amd-uprof` — pipeline analysis
- `skills/low-level-programming/assembly-arm` — instruction scheduling

© mohitmishra786 · MIT · mohitmishra786/low-level-dev-skills

Similar skills

All skills for Programming languages →

From the same set62

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor