Use SIMD (Single Instruction, Multiple Data) to write high-performance vectorized .NET code. Covers System.Numerics.Vector<T> for portable cross-platform SIMD, System.Runtime.Intrinsics.Vector128/256/512<T> for explicit-width control, TensorPrimitives for ready-made span operations, and the canonical span iteration patterns (MemoryMarshal.Cast, bounds-check elimination, remainder handling). Trigger whenever the user wants to speed up loops over large arrays or spans, asks about vectorization, hardware intrinsics, Vector<T>, Vector128/Vector256/Vector512, TensorPrimitives, SIMD, auto-vectorization, or high-performance numeric processing in C# — even if they don't mention SIMD by name. Prefer this skill over guessing; SIMD in .NET has several subtleties that are easy to get wrong (hardware guards, type support checks, remainder handling, span casting rules).
설치
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
Use SIMD (Single Instruction, Multiple Data) to write high-performance vectorized .NET code. Covers System.Numerics.Vector<T> for portable cross-platform SIMD, System.Runtime.Intrinsics.Vector128/256/512<T> for explicit-width control, TensorPrimitives for ready-made span operations, and the canonical span iteration patterns (MemoryMarshal.Cast, bounds-check elimination, remainder handling). Trigger whenever the user wants to speed up loops over large arrays or spans, asks about vectorization, hardware intrinsics, Vector<T>, Vector128/Vector256/Vector512, TensorPrimitives, SIMD, auto-vectorization, or high-performance numeric processing in C# — even if they don't mention SIMD by name. Prefer this skill over guessing; SIMD in .NET has several subtleties that are easy to get wrong (hardware guards, type support checks, remainder handling, span casting rules).
C# SIMD Skill
SIMD ("Single Instruction, Multiple Data") executes one operation on many elements at once using dedicated CPU registers. The JIT eliminates dead code paths when SIMD is unavailable, so you pay no penalty on unsupported hardware.
.NET exposes SIMD through two complementary layers:
Layer
Namespace
Best for
Vector<T>
System.Numerics
Portable, generic, automatic width — start here
Vector128/256/512<T>
System.Runtime.Intrinsics
Explicit width, platform-specific instructions
Both layers cooperate with Span<T> via MemoryMarshal.Cast<>.
if (Vector256.IsHardwareAccelerated)
{
// 256-bit path
}
Performance principles
Use Span<T> / ReadOnlySpan<T>, not arrays or IEnumerable<T> — SIMD requires contiguous memory; spans provide it without copies.
Eliminate bounds checks using MemoryMarshal.GetReference() + Unsafe.Add() in hot loops (details in span-patterns.md).
Handle remainders — span lengths rarely divide evenly by Vector<T>.Count. Always process the tail with a scalar loop.
Reach List<T> via CollectionsMarshal.AsSpan() to avoid paying the IEnumerable overhead.
Measure with BenchmarkDotNet — compare Scalar / Vector128 / Vector256 / Vector512 jobs to confirm gains. See span-patterns.md for a job config example.