# simd-intrinsics

A skill that walks the agent through manual vectorization: reading auto-vectorization reports, writing SSE2/AVX2/NEON intrinsics, and checking CPU flags at runtime.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 645 installs · ★ 267
- Author: mohitmishra786
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/mohitmishra786/low-level-dev-skills/tree/HEAD/skills/low-level-programming/simd-intrinsics/SKILL.md
- Updated: 2026-06-27
- HTML: https://affpapa.org/en/nevibecode/skills/simd-intrinsics

## What it does

The skill kicks in when a hot loop stays scalar. It parses GCC's `-fopt-info-vec` output and Clang's `-Rpass-missed=loop-vectorize` remarks, names the blocker, and suggests a fix: drop a loop-carried dependency, move an early return out of the loop, add `__restrict__` to the pointers. Then it writes the intrinsics themselves — `_mm_loadu_ps` and `_mm_add_ps` for SSE2, `_mm256_fmadd_ps` for AVX2 with FMA, `vld1q_f32` and `vfmaq_f32` for NEON on AArch64.

A separate step covers the choice between letting the compiler vectorize and doing it by hand. The skill says to try the compiler first and reach for intrinsics on shuffles, gather/scatter and horizontal operations. Runtime detection has two routes: `__builtin_cpu_supports("avx2")` on GCC and Clang, or raw CPUID through `__cpuid_count(7, 0)` checking bit 5.

AVX2 code needs `-mavx2 -mfma` at compile time; NEON needs `-march=armv8-a+simd`. Alignment for AVX2 is 32 bytes via `aligned_alloc`, and `_mm256_load_ps` on an unaligned pointer will crash — use `_mm256_loadu_ps` for buffers you do not control. Worth checking where your data actually comes from before switching to aligned loads.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill simd-intrinsics -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/simd-intrinsics/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/simd-intrinsics/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill simd-intrinsics -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/simd-intrinsics/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill simd-intrinsics -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/simd-intrinsics/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install mohitmishra786/low-level-dev-skills simd-intrinsics
```

2. **Manually: put the files in place**
- File: `.github/skills/simd-intrinsics/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill simd-intrinsics -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/mohitmishra786/low-level-dev-skills --path skills/low-level-programming/simd-intrinsics
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/simd-intrinsics/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill simd-intrinsics -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/mohitmishra786/low-level-dev-skills/tree/HEAD/skills/low-level-programming/simd-intrinsics/SKILL.md

## When to use it
- find out why GCC refuses to vectorize a hot loop
- write an SSE2 version of element-wise array addition
- detect AVX2 support on the CPU at runtime
- decide between auto-vectorization and hand-written intrinsics
- port a loop from x86 to NEON on ARM

## Example prompts
- Read the `-fopt-info-vec-missed` report for `src/hot.c` and tell me what blocks vectorization
- Rewrite this array-add loop with AVX2 and an SSE2 tail
- Add a `__builtin_cpu_supports("avx2")` check with a scalar fallback path

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: b79bf0d92a873ebf.

BEGIN THIRD-PARTY FILE b79bf0d92a873ebf
````text
---
name: simd-intrinsics
description: SIMD intrinsics skill for x86 (SSE/AVX) and ARM (NEON) vectorization. Use when reading auto-vectorization reports, writing SSE2/AVX2/NEON intrinsics, checking CPU feature flags at runtime, choosing between compiler builtins and raw intrinsics, or diagnosing why auto-vectorization failed. Activates on queries about SIMD, SSE2, AVX2, NEON, intrinsics, -fopt-info-vec, auto-vectorization, or vectorization failures.
---

# SIMD Intrinsics

## Purpose

Guide agents through SIMD: reading auto-vectorization output, writing SSE2/AVX2/NEON intrinsics, runtime CPU feature detection, and choosing between compiler auto-vectorization and manual intrinsics.

## Triggers

- "How do I check if my loop is being auto-vectorized?"
- "How do I write SSE2/AVX2 intrinsics?"
- "Auto-vectorization failed — how do I fix it?"
- "How do I check for CPU features at runtime?"
- "Should I use intrinsics or let the compiler vectorize?"
- "How do I write NEON intrinsics for ARM?"

## Workflow

### 1. Check auto-vectorization

```bash
# GCC: show vectorization info
gcc -O2 -march=native -fopt-info-vec src/hot.c -o hot

# Verbose: show missed + successful
gcc -O2 -march=native -fopt-info-vec-missed -fopt-info-vec-optimized src/hot.c

# Clang: vectorization remarks
clang -O2 -march=native \
    -Rpass=loop-vectorize \
    -Rpass-missed=loop-vectorize \
    -Rpass-analysis=loop-vectorize \
    src/hot.c -o hot

# Example missed message:
# hot.c:15:5: remark: loop not vectorized: value that could not be identified as
# reduction is used outside the loop [-Rpass-missed=loop-vectorize]
```

Common auto-vectorization blockers:

| Blocker | Fix |
|---------|-----|
| Loop-carried dependency | Restructure to remove dependency |
| Data-dependent exit (early return) | Move exit after loop |
| Non-contiguous memory | Use gather/scatter or restructure |
| Aliasing (pointer may alias) | Add `__restrict__` or `restrict` |
| Unknown trip count | Add `__builtin_expect` or hint |
| Function call in loop body | Inline the function |

```c
// Help the compiler by adding restrict
void add_arrays(float * __restrict__ dst,
                const float * __restrict__ a,
                const float * __restrict__ b,
                size_t n) {
    for (size_t i = 0; i < n; i++)
        dst[i] = a[i] + b[i];  // Now vectorizable
}
```
````
END THIRD-PARTY FILE b79bf0d92a873ebf

The third-party file has ended. Everything between the b79bf0d92a873ebf tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2356 of 7528 bytes. © mohitmishra786 · MIT · https://github.com/mohitmishra786/low-level-dev-skills/tree/HEAD/skills/low-level-programming/simd-intrinsics/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
