Skip to main content
BuildOfficialCertifiedAI reviewed Aug 27, 2026

vectorization

Design, implement, optimize, and review SIMD code in .NET. USE FOR: vectorizing scalar loops with TensorPrimitives, Vector64/128/256/512, or platform hardware intrinsics; reviewing existing SIMD code, including the generic Vector type, for contract equivalence, tail handling, memory safety, portability, fallbacks, and measured performance. DO NOT USE FOR: performance work unrelated to SIMD or vectorization.

v1.0.11 install

Install this skill

No account required. Pick your tool, or use the command that detects it for you.

Run in your terminal. It detects your AI tool.

npx @skills-hub-ai/cli install dotnet-vectorization
Or get the file:
Browse all CLI commands →
Manual setup by platform

Claude Code

~/.claude/skills/dotnet-vectorization/SKILL.md

Setup guide →

Signing

SignedSLSA L2
Signed by
skills-hub.ai distributor
Method
Distributor-signed by skills-hub.aiSigned with the skills-hub.ai Ed25519 distributor key over this exact slug, version and content. Check it with `npx @skills-hub-ai/cli verify`.
Key
skills-hub-ed25519-2026-11
Signed
0Save

Instructions

.NET SIMD vectorization

Produce a portable optimization that preserves the scalar contract, remains memory-safe at every
length, and earns its complexity with measured results. Read the official
SIMD and hardware-intrinsics guidance first

and follow its comprehensive implementation templates. In particular, use its self-contained
per-width dispatch, dedicated small-input handling, loop, and remainder shapes rather than reducing
them to a chain of width checks. This skill supplies the decision rules and validation checks to
apply while changing real code.

Inputs and prerequisites

Discover these from the repository before asking the user:

InputRequiredWhat to establish
Scalar implementation and testsYesExisting contract, representative call sites, and supported overlap
Target frameworks and platformsYesAvailable SIMD APIs and architectures that must behave consistently
Build and test workflowYesThe repository's normal commands and how to launch separate test processes
Representative workload or benchmarkFor optimizationTypical input sizes and the baseline to beat

Do not add a package merely because an API exists there. First check the target framework and the
project's existing dependency/versioning policy.

Core rules

  1. Use the highest-level API that matches the contract, then stop. Span<T> and string
    operations, TensorPrimitives, and tensor types already accelerate many operations. LINQ
    reductions such as Sum, Min, Max, and Average can also accelerate when the source exposes
    its underlying span. Verify empty-input and floating-point behavior rather than assuming similarly
    named operations are interchangeable. Once an existing API preserves the contract, use it instead
    of continuing into handwritten SIMD. Before writing an explicit loop, name the framework APIs
    considered and why none applies. Fixed-shape System.Numerics types remain appropriate for
    graphics and similar domains.
  2. Start new explicit SIMD loops with Vector128<T>. It is accelerated across the broadest
    hardware set. Add wider fixed-width paths only when measurements justify them.
  3. Keep platforms consistent. Prefer cross-platform operations on the fixed-width vector types;
    they lower to the appropriate target instructions. For example,
    (vector & mask) == Vector128<byte>.Zero becomes ptest on x86/x64. Use
    architecture-specific intrinsics only for a measured gap, guard them with IsSupported, and
    retain equivalent portable or scalar behavior.
  4. Read IsHardwareAccelerated, IsSupported, and Count directly. The JIT treats them as
    constants, so caching them adds no value and obscures which branches disappear.
  5. Prefer operators where they are clear. Parenthesize expressions that mix bitwise and
    comparison operators so precedence is explicit.

If the task is review-only, do not rewrite the code. Report correctness and memory-safety defects
before performance opportunities.

Authoring checklist

  • Contract: identify behavior for empty and short inputs, overlap, overflow, NaN, signed zero,
    ordering, and exceptions before changing the implementation.
  • Framework gate: inspect the target framework and existing package references, then compile or
    probe the highest-level candidate API with the required edge cases. A small contract adapter, such
    as preserving special empty-input behavior, does not justify reimplementing the operation. If the
    API preserves the contract, use it and stop; do not claim it is unavailable without checking.
  • Structure: for new explicit SIMD, implement Vector128<T> and scalar first. Only after
    measurements justify wider paths, check Vector512<T>, then Vector256<T>, optional Vector<T>,
    Vector128<T>, and finally scalar. Omit paths the implementation does not need. Each outer
    fixed-width guard checks only its IsHardwareAccelerated property and, for generic element types,
    IsSupported. Inside that block, run the width-specific helper when the input has at least
    Count elements; otherwise run a dedicated small-input helper, then return. Do not put the length
    check in the outer guard and fall through to repeat dispatch at narrower widths. Keeping each
    supported-width block self-contained lets the JIT remove unsupported blocks and avoids redundant
    work on common small inputs.
  • Loads and stores: prefer span-based Vector128.Create(span) and CopyTo; the JIT keeps them
    efficient and they require no pinning or reference arithmetic. Unsafe loads and stores are largely
    unnecessary. When a path genuinely must walk a buffer by managed reference, use the element-offset
    LoadUnsafe(ref T, nuint) and StoreUnsafe overloads rather than pointers or manually advanced
    references.
  • Empty inputs: in a reference-based path, obtain the starting reference with
    MemoryMarshal.GetReference(span) or MemoryMarshal.GetArrayDataReference(array), not by indexing
    element 0.
  • Unsupported element types: the fixed-width vectors support primitive numeric element types,
    not char or bool. Reinterpret with MemoryMarshal.Cast or As<TFrom, TTo>; reinterpretation
    changes only the type, not the bits. Keep Boolean data as 0 or 1 and characters as valid
    UTF-16, normalizing results before storing when necessary.
  • Offsets: prove the input contains a full vector before subtracting Count or converting an
    index to nuint; otherwise a negative value becomes a huge unsigned offset.
  • Managed references: do not form references before the start or past the end of a span,
    including a one-past-end reference. The runtime permits a non-dereferenced managed pointer exactly
    one past an object or array, but this guidance intentionally prohibits the pattern because it is
    fragile and easy to misuse. Keep the base reference in range and express traversal with an element
    offset.
  • Remainders: cover every length, including 0, Count - 1, Count, Count + 1, and
    nonmultiples of each width. Once the input contains a full vector, keep the tail vectorized by
    reprocessing the last full vector. An idempotent operation can fold that overlap in directly. A
    non-idempotent operation must use ConditionalSelect to replace repeated lanes with the
    operation's identity before folding them in. This is the JIT-recognized general pattern; it can
    reduce a zero-identity selection to a bitwise mask while retaining broader optimization
    opportunities. For in-place transforms, preserve the original tail values before overlapping
    stores and write only valid results.
  • Buffer overlap: choose a traversal direction or staging strategy that prevents stores from
    corrupting values not yet loaded.
  • Numeric behavior: account for floating-point reassociation, NaN and signed-zero semantics,
    checked or unchecked integer overflow, and endianness where the algorithm depends on byte order.
    Native and Estimate operations can intentionally relax precision or IEEE edge-case behavior;
    use them only when the contract permits it and measurements justify them.

The official guidance contains the complete dispatch, small-input, unrolling, and remainder
templates; use those for the full implementation. The following excerpt illustrates only the inner
safe Vector128<T> loop for an in-place elementwise transform, after its self-contained dispatch
block has established at least one full vector. Transform represents the operation being
implemented:

Span<int> tail = data.Slice(data.Length - Vector128<int>.Count);
Vector128<int> end = Vector128.Create<int>(tail);
Span<int> remaining = data;

while (remaining.Length >= Vector128<int>.Count)
{
    Vector128<int> values = Vector128.Create<int>(remaining);
    Transform(values).CopyTo(remaining);
    remaining = remaining.Slice(Vector128<int>.Count);
}

if (!remaining.IsEmpty)
{
    Transform(end).CopyTo(tail);
}

The early end load preserves original values before overlapping stores. For a read-only reduction,
load the same final span after the main loop and use ConditionalSelect to replace already-processed
lanes with the operation's identity. Do not substitute LoadUnsafe/StoreUnsafe or a scalar
epilogue merely to avoid span bounds checks.

Testing checklist

  • Compare the optimized implementation with the scalar contract across boundary lengths,
    randomized values, empty inputs, supported overlap, and numeric edge cases. Cover every
    implemented width and the scalar path with inputs both large enough and too small to benefit.
  • Exercise every implemented width and the scalar fallback in separate processes. On x86/x64
    CoreCLR, DOTNET_EnableAVX2=0 disables AVX2 and DOTNET_EnableHWIntrinsic=0 disables hardware
    intrinsics. Use the repository's normal test command and do not change these process-wide
    settings inside a unit test. These settings do not change code already compiled as ReadyToRun or
    ahead of time, so confirm the target code is JIT-compiled when using them to force a path.
  • For unsafe loads and stores, use guard-page or equivalent boundary tests when available. Put the
    inaccessible page after the buffer for forward iteration and before it for backwards iteration,
    and include nonmultiple lengths. An ordinary array allocation does not reliably expose an
    out-of-bounds read.

Benchmarking

Use BenchmarkDotNet to measure representative small and large inputs before keeping the added
complexity. Compare scalar, Vector128<T>, and each wider implemented path in the same run. Small
inputs can be slower because setup dominates, and speedups are rarely the theoretical vector-width
multiple because memory throughput, alignment, and latency still apply. Report throughput or time
with noise context and, when relevant, generated code size or instruction counts. Control allocation
alignment for stable measurements or randomize it to observe the distribution. A wider vector is
not automatically faster.

If the project cannot target the required framework, run the relevant architecture, or execute the
fallback configuration, state exactly which path remains unverified. Do not claim success from a
default-hardware test alone.

Completion contract

  • Authoring: leave the scalar contract covered by tests; identify the framework or SIMD layer
    selected; report measurements for the representative workload; name any architecture or fallback
    path that could not be exercised.
  • Review: report only concrete findings, ordered by correctness, memory safety, portability,
    tests, then performance evidence. If none remain, say so directly.
  • Do not call an optimization complete when it only builds, only passes on the current machine, or
    has no comparison against the scalar baseline.

Review checklist

Review in this order:

  1. Scalar-contract equivalence, including signed zero, NaN, overflow, and relevant endianness
  2. Reuse of an existing accelerated framework API
  3. Tail correctness for idempotent versus non-idempotent work
  4. Memory safety, unsigned offset arithmetic, empty inputs, and overlapping buffers
  5. Portable dispatch and behaviorally equivalent fallbacks
  6. Tests that force each width and the scalar path
  7. Benchmarks that justify explicit SIMD and additional widths
This skill doesn’t include stateful context yet, instructions only. Learn about stateful skills.

Security

Loading security scan...

Reviews (0)

Browse all →
system-text-json-net11Imperative guidance for the System.Text.Json APIs added in .NET 11: the built-in `JsonNamingPolicy.PascalCase` naming policy, and the strongly-typed generic `JsonSerializerOptions.GetTypeInfo` and `JsonSerializerOptions.TryGetTypeInfo` metadata accessors (generic overloads that return a typed `JsonTypeInfo`). USE ONLY when the user is targeting net11.0 or later and needs PascalCase JSON property or dictionary-key names without writing a custom naming policy, a strongly-typed generic `JsonTypeInfo` instead of the non-generic `JsonTypeInfo`, or a no-throw way to probe whether a type's serialization metadata is resolved. DO NOT USE when the target is earlier than net11.0, the requested behavior uses an established pre-net11 naming policy, or the user explicitly selected another JSON library.2 installsmicrobenchmarkingActivate this skill when BenchmarkDotNet (BDN) is involved in the task — creating, running, configuring, or reviewing BDN benchmarks. Also activate when microbenchmarking .NET code would be useful and BenchmarkDotNet is the likely tool. Consider activating when answering a .NET performance question requires measurement and BenchmarkDotNet may be needed. Covers microbenchmark design, BDN configuration and project setup, how to run BDN microbenchmarks efficiently and effectively, and using BDN for side-by-side performance comparisons. Do NOT use for profiling/tracing .NET code (dotnet-trace, PerfView), production telemetry, or load/stress testing (Crank, k6).2 installsmsbuild-serverGuide for using MSBuild Server to improve CLI build performance. Activate when developers report slow incremental builds from the command line, or when CLI builds are noticeably slower than IDE builds. Covers MSBUILDUSESERVER=1 environment variable for persistent server-based caching. Do not activate for IDE-based builds (Visual Studio already uses a long-lived process).2 installsmigrate-xunit-to-xunit-v3Migrate .NET test projects from xUnit.net v2 to xunit.v3 and fix v3 breaks. Use for package/CPM conversion, OutputType=Exe, preserving the VSTest or MTP runner (including projects currently using YTest.MTP.XUnit2), incompatible TFMs, async void tests, string-to-Type attributes, custom Fact/Theory/BeforeAfterTest attributes, Xunit.SkippableFact, xunit.abstractions/extensibility consolidation, and Xunit.Combinatorial/StaFact compatibility. Do not use for framework conversion or a runner-only migration. For xUnit v3 MTP filter syntax, also use migrate-vstest-to-mtp.2 installsmigrate-nullable-referencesEnable nullable reference types in a C# project and systematically resolve all warnings. USE FOR: adopting NRTs in existing codebases, file-by-file or project-wide migration, fixing CS8602/CS8618/CS86xx warnings, annotating APIs for nullability, cleaning up null-forgiving operators, upgrading dependencies with new nullable annotations. DO NOT USE FOR: projects already fully migrated with zero warnings (unless auditing suppressions), fixing a handful of nullable warnings in code that already has NRTs enabled, suppressing warnings without fixing them, C# 7.3 or earlier projects. INVOKES: Get-NullableReadiness.ps1 scanner script.2 installsbuild-perf-baselineEstablish MSBuild/.NET baselines before optimizing. USE FOR: unranked slow builds; cold/warm/incremental/no-op measurements; before/after comparisons; CI caching; static graph, artifacts output, dependency graph trimming. DO NOT USE FOR: measured bottlenecks (build-perf-diagnostics), known repeated restores (eliminate-redundant-restores), within-build duplicate calls (find-repeated-work-within-one-build), non-MSBuild builds.2 installs

More from .NET

View source →
analyzing-dotnet-performanceScans .NET code for ~50 performance anti-patterns across async, memory, strings, collections, LINQ, regex, serialization, and I/O with tiered severity classification. Use when analyzing .NET code for optimization opportunities, reviewing hot paths, or auditing allocation-heavy patterns.14 installscreate-skillScaffolds new agent skills for the dotnet/skills repository. Use when creating a new skill, generating SKILL.md files, writing a skill description that the runtime will actually route to, or setting up skill directory structures. Handles frontmatter generation, section templates, and validation guidance. Do not use for fixing a skill that already fails its evaluation (use improve-skill-quality) or for writing eval.yaml (use create-skill-test).8 installscsharp-scriptsRun file-based C# apps with the .NET CLI when the user explicitly wants C#/.NET code without creating a project. Use for C# language/API experiments, one-file C# apps, small multi-file C# apps composed with `#:include`/`#:exclude`, or C# file-based apps linked with `#:ref`. Do not use for language-agnostic throwaway scripts, generic computations, Python/PowerShell-style automation, full projects, or existing app integration.5 installscode-testing-extensionsProvides file paths to language-specific extension files for the code-testing pipeline. Read this reference-only catalog for extension guidance files (e.g., dotnet.md for .NET, cpp.md for C++). Agents and skills read its bundled files directly; do not invoke this catalog through the model's skill tool.4 installscreate-blazor-projectCreate a new ASP.NET Core web application or web site using Blazor. USE FOR: creating a new Blazor web app, scaffolding a new web project, starting a new web site, choosing render modes (Static SSR, Interactive Server, Interactive WebAssembly, Auto), running dotnet new blazor with the right options, setting up initial project structure. DO NOT USE FOR: adding features to existing projects, changing how an existing app renders, or component authoring (use author-component).3 installscode-testing-agentLegacy compatibility alias for the code-testing skill. Do not self-activate for user requests and do not treat this name as a custom agent. When invoked explicitly by older instructions, load code-testing and follow it instead.2 installs

More Build skills

Browse category →
senior-frontendBuild and review React, Next.js, TypeScript or Tailwind frontends: components, scaffolding, performance and bundle size. Use whenever the user wants a new component or app, a page feels slow, the bundle is too big, or asks for a frontend code review.638 installsui-design-systemUse when building a design system: tokens, component docs, responsive scales or developer handoff. Generates tokens with design_token_generator.py.539 installsfrontend-designGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.349 installssenior-backendBuild and fix backend services: REST or GraphQL APIs, auth, microservices, PostgreSQL queries, migrations and load tests. Use whenever the user's API is slow or broken, needs login or auth added, a schema change, or a new endpoint or service scaffolded.248 installsself-improving-agentCurate what the agent has learned into durable project knowledge. Reviews Claude Code auto-memory (MEMORY.md and its topic files) for learnings worth keeping, promotes proven ones into CLAUDE.md or .claude/rules/, records a correction as a lesson that persists across sessions, prunes stale or duplicate entries, and turns a recurring fix into a reusable skill. Use whenever the user asks what you have learned or saved about the project, which memories should become permanent rules, to remember a lesson or stop repeating a mistake, or to clean up, audit or check memory health.176 installsusing-superpowersUse when starting any conversation - establishes how to find and use skills, requiring skill invocation before ANY response including clarifying questions145 installs

Frequently asked questions about vectorization

What does the vectorization skill do?

Design, implement, optimize, and review SIMD code in .NET. USE FOR: vectorizing scalar loops with TensorPrimitives, Vector64/128/256/512, or platform hardware intrinsics; reviewing existing SIMD code, including the generic Vector type, for contract equivalence, tail handling, memory safety, portability, fallbacks, and measured performance. DO NOT USE FOR: performance work unrelated to SIMD or vectorization. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.

How do I install the vectorization skill?

Run `npx @skills-hub-ai/cli install dotnet-vectorization` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/dotnet-vectorization/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.

Which AI tools does vectorization work with?

vectorization runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.

Is the vectorization skill free?

Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.

How do I use vectorization after installing it?

In Claude Code, type `/dotnet-vectorization` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.

Can I share the vectorization skill with my team?

Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.