exp-simd-vectorization
Optimizes hot-path scalar loops in .NET 8+ with cross-platform Vector128/Vector256/Vector512 SIMD intrinsics, or replaces manual math loops with single TensorPrimitives API calls. Covers byte-range validation, character counting, bulk bitwise ops, cross-type conversion, fused multi-array computations, and float/double math operations.
What this skill does
# SIMD Vectorization
## Decision Gate
1. **Check `Span<T>` and `MemoryExtensions` first.** If the operation can be expressed using built-in `Span<T>` methods (e.g., `Contains`, `IndexOf`, `CopyTo`, `SequenceEqual`) or `MemoryExtensions`, use them — no additional dependency is needed and the runtime already vectorizes many of these internally.
2. **Check for TensorPrimitives next.** If one or more TensorPrimitives methods cover the operation → use them. If the `.csproj` does NOT already reference `System.Numerics.Tensors`, **add the package**, for example: `<PackageReference Include="System.Numerics.Tensors" />` (or use the versioning approach already used by your solution). Then replace the scalar loop with TP calls and stop. See the full API table below. Compose multiple TP calls when needed (e.g., finding both min and max → `TensorPrimitives.Min(span)` + `TensorPrimitives.Max(span)` as two calls). Do NOT write manual Vector128 code for operations TP already handles.
3. **Scalar loop over contiguous array/span** of `byte`, `sbyte`, `short`, `ushort`, `int`, `uint`, `long`, `ulong`, `nint`, `nuint`, `float`, `double` (and `char` via reinterpretation as `ushort`)? → Implement with explicit `Vector128<T>` / `Vector256<T>` / `Vector512<T>` intrinsics using the patterns below.
4. **No contiguous numeric arrays to process** (dictionary lookups, tree traversals, linked lists, state machines, string formatting, small collections, enum comparisons, recursive algorithms, decimal arithmetic)? → Report `[NO SIMD OPPORTUNITY]` and write a **full paragraph** explaining WHY, referencing the specific code characteristics that prevent vectorization (e.g., "State machines require sequential branching on enum values — there are no contiguous numeric arrays to process in parallel, and each transition depends on the previous state"). This explanation is graded.
## TensorPrimitives API Reference
TensorPrimitives APIs are generic and work for any primitive type that satisfies the method's generic constraints — not just `float`/`double`. For example, `Sum` requires `IAdditionOperators<T,T,T>` + `IAdditiveIdentity<T,T>` and works for all primitive numeric types, while `CosineSimilarity` requires `IRootFunctions<T>` and only works for `float`/`double`. If the project doesn't already reference `System.Numerics.Tensors`, add it to the `.csproj`. Replace the entire manual loop with **one or more** `TensorPrimitives` calls as needed (prefer a single call when possible):
### Reductions (span → scalar)
| Operation | API |
|-----------|-----|
| Sum | `TensorPrimitives.Sum(span)` |
| Sum of squares | `TensorPrimitives.SumOfSquares(span)` |
| Sum of magnitudes (L1 norm) | `TensorPrimitives.SumOfMagnitudes(span)` |
| L2 norm | `TensorPrimitives.Norm(span)` |
| Product of all elements | `TensorPrimitives.Product(span)` |
| Min value | `TensorPrimitives.Min(span)` |
| Max value | `TensorPrimitives.Max(span)` |
| Index of max | `TensorPrimitives.IndexOfMax(span)` |
| Index of min | `TensorPrimitives.IndexOfMin(span)` |
| Dot product | `TensorPrimitives.Dot(a, b)` |
| Cosine similarity | `TensorPrimitives.CosineSimilarity(a, b)` |
| Euclidean distance | `TensorPrimitives.Distance(a, b)` |
### Element-wise transforms (span → span)
| Operation | API |
|-----------|-----|
| Negate | `TensorPrimitives.Negate(src, dst)` |
| Abs | `TensorPrimitives.Abs(src, dst)` |
| Sqrt | `TensorPrimitives.Sqrt(src, dst)` |
| Exp | `TensorPrimitives.Exp(src, dst)` |
| Log | `TensorPrimitives.Log(src, dst)` |
| Log2 | `TensorPrimitives.Log2(src, dst)` |
| Tanh | `TensorPrimitives.Tanh(src, dst)` |
| Sigmoid | `TensorPrimitives.Sigmoid(src, dst)` |
| SoftMax | `TensorPrimitives.SoftMax(src, dst)` |
| Sinh | `TensorPrimitives.Sinh(src, dst)` |
| Cosh | `TensorPrimitives.Cosh(src, dst)` |
| Round | `TensorPrimitives.Round(src, dst)` |
| Floor | `TensorPrimitives.Floor(src, dst)` |
| Ceiling | `TensorPrimitives.Ceiling(src, dst)` |
| CopySign | `TensorPrimitives.CopySign(src, sign, dst)` |
| Pow | `TensorPrimitives.Pow(bases, exponents, dst)` |
### Two-span operations (a, b → dst)
| Operation | API |
|-----------|-----|
| Add | `TensorPrimitives.Add(a, b, dst)` |
| Subtract | `TensorPrimitives.Subtract(a, b, dst)` |
| Multiply | `TensorPrimitives.Multiply(a, b, dst)` |
| Divide | `TensorPrimitives.Divide(a, b, dst)` |
| Element-wise Min | `TensorPrimitives.Min(a, b, dst)` |
| Element-wise Max | `TensorPrimitives.Max(a, b, dst)` |
### Three-span fused operations
| Operation | API |
|-----------|-----|
| (x+y)*z | `TensorPrimitives.AddMultiply(x, y, z, dst)` |
| x*y+z | `TensorPrimitives.MultiplyAdd(x, y, z, dst)` |
| fma(x,y,z) | `TensorPrimitives.FusedMultiplyAdd(x, y, z, dst)` |
> `AddMultiply` and `MultiplyAdd` are distinct — they optimize differently depending on whether the dependency chain flows from the addend or the multiplier. `FusedMultiplyAdd` is the IEEE 754 fused form of (x*y)+z with a single rounding step.
## Manual SIMD with Vector128/Vector256/Vector512
Use this when TensorPrimitives doesn't have a single API for the operation. This is required for byte-level operations, character class counting, range validation, bitwise bulk ops, cross-type conversions, and custom patterns.
### Required imports
```csharp
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
```
Prefer cross-platform APIs (`System.Runtime.Intrinsics`). Only use platform-specific intrinsics (`System.Runtime.Intrinsics.X86`, `.Arm`) when there is a significant performance advantage that justifies the increased code complexity of maintaining separate code paths.
### Three-tier dispatch pattern
Always include all three tiers. Use `if`/`else if` so that small inputs hit only one branch before reaching the scalar fallback — a fallthrough pattern (sequential `if`s) pessimizes the scalar case by requiring up to three not-taken branches that may mispredict. The `IsHardwareAccelerated` checks are JIT-time constants, so dead paths are eliminated at compile time:
```csharp
ref var src = ref MemoryMarshal.GetReference(span);
uint i = 0;
uint length = (uint)span.Length;
if (Vector512.IsHardwareAccelerated && Vector512<T>.IsSupported)
{
uint vec512Count = (uint)Vector512<T>.Count;
while (i + vec512Count <= length)
{
var vec = Vector512.LoadUnsafe(ref src, i);
// ... process vec ...
i += vec512Count;
}
}
else if (Vector256.IsHardwareAccelerated && Vector256<T>.IsSupported)
{
uint vec256Count = (uint)Vector256<T>.Count;
while (i + vec256Count <= length)
{
var vec = Vector256.LoadUnsafe(ref src, i);
// ... process vec ...
i += vec256Count;
}
}
else if (Vector128.IsHardwareAccelerated && Vector128<T>.IsSupported)
{
uint vec128Count = (uint)Vector128<T>.Count;
while (i + vec128Count <= length)
{
var vec = Vector128.LoadUnsafe(ref src, i);
// ... process vec ...
i += vec128Count;
}
}
// Scalar fallback for remaining elements (and the only loop hit for small inputs)
for (; i < length; i++)
{
// ... scalar processing ...
}
```
### Core SIMD operations
- **Load/Store:** `Vector128.LoadUnsafe(ref src, offset)` / `.StoreUnsafe(ref dst, offset)`
- **Arithmetic:** `+`, `-`, `*`, `/` operators on vector types
- **Multiply-add (approximate):** `Vector128.MultiplyAddEstimate(a, b, c)` — performs a multiply-add with implementation-defined approximation; not guaranteed to be a strict IEEE fused multiply-add. For precise fused semantics, use `Vector128.FusedMultiplyAdd(a, b, c)`.
- **Comparison:** `Vector128.Equals`, `.LessThan`, `.GreaterThan` — returns mask vector
- **Mask ops:** `Vector128.All(mask)`, `.Any(mask)`, `.None(mask)`, `.Count(mask)`, `.CountWhereAllBitsSet(mask)`
- **Horizontal:** `Vector128.Sum(vec)` for reduction; `.Min(a,b)`, `.Max(a,b)` element-wise
- **Broadcast:** `Vector128.Create(scalarValue)` — fill all lanes with one value
- **Bitwise:** `&`, `|`, Related in Ads & Marketing
ads
IncludedMulti-platform paid advertising audit and optimization skill. Analyzes Google, Meta, YouTube, LinkedIn, TikTok, Microsoft, and Apple Ads. 250+ checks with scoring, parallel agents, industry templates, and AI creative generation.
banana
IncludedAI image generation Creative Director powered by Google Gemini Nano Banana models. Use this skill for ANY request involving image creation, editing, visual asset production, or creative direction. Triggers on: generate an image, create a photo, edit this picture, design a logo, make a banner, visual for my anything, and all /banana commands. Handles text-to-image, image editing, multi-turn creative sessions, batch workflows, and brand presets.
rpg-migration-analyzer
IncludedAnalyzes legacy RPG (Report Program Generator) programs from AS/400 and IBM i systems for migration to modern Java applications. Extracts business logic from RPG III/IV/ILE source code, identifies data structures (D-specs), file operations (F-specs), program dependencies (CALLB/CALLP), and converts RPG constructs to Java equivalents. Generates migration reports, complexity estimates, and Java implementation strategies with POJO classes, JPA entities, and service methods. Use when modernizing AS/400 or IBM i legacy systems, analyzing RPG source files (.rpg, .rpgle, .RPGLE), converting RPG to Java, mapping data specifications to Java classes, planning legacy system migration, or when user mentions RPG analysis, Report Program Generator, RPG III/IV/ILE, AS/400 modernization, IBM i migration, packed decimal conversion, or mainframe application rewrite.
brand-library-architect
IncludedBuild a complete brand library for a product — visual asset render pipeline, brand documentation set (BRAND, COPY, MANIFESTO, BIOS, FAQ, GLOSSARY, TONE, PRICING), open-source convention files (README, CONTRIBUTING, SECURITY, CODE_OF_CONDUCT), and a self-contained press kit. This skill should be used when the user asks to "build a brand library / brand kit / press kit / brand assets" for a product, "set up a brand library workflow," "create a positioning manifesto plus visual identity," or any combination of brand documentation + visual asset pipeline. Apply phase-by-phase or run end-to-end. Templates are product-agnostic and use {{TOKEN}} placeholders the skill prompts the user to fill.
writing-tech-post
IncludedAuthors engineering blog posts end-to-end: launch deep-dives, incident postmortems, architecture migrations, performance case studies, tutorials, AI/agent system writeups, security disclosures, and research-to-product translations. Picks the correct archetype, plans the abstraction ladder, enforces an evidence cadence (diagrams, benchmarks, profiles, traces, code, ablations), tunes voice against publisher house styles (Datadog, Vercel, GitHub, AWS, Meta, Cloudflare, Jane Street), and runs a pre-publish gate for narrative momentum and disclosure ethics. Use when drafting a new engineering post, restructuring a draft that feels flat, deciding which evidence form belongs where, validating that depth and product context are balanced, or preparing a postmortem, migration, or performance narrative for external publication. Do not use for API reference documentation, README authoring, marketing copy, release notes, generic SEO content, ghost-written executive thought leadership, or non-engineering long-form essays.
blog-google
IncludedGoogle API integration for blog performance: PageSpeed Insights, CrUX Core Web Vitals with 25-week history, Search Console performance, URL Inspection, Indexing API, GA4 organic traffic, NLP entity analysis for E-E-A-T, YouTube video search for embedding, and Google Ads Keyword Planner. Progressive feature availability based on credential tier (API key, OAuth/service account, GA4, Ads). Shares config with claude-seo at ~/.config/claude-seo/google-api.json. Use when user says "google data", "page speed", "core web vitals", "search console", "indexation", "GA4", "keyword research", "nlp entities", "blog performance", "youtube search", "google api setup".