exp-simd-vectorization

Optimizes .NET scalar loops with TensorPrimitives APIs or Vector128/Vector256/Vector512 SIMD intrinsics.

1|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/D1ssolve/craft-agents --skill exp-simd-vectorization-d1ssolve
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: exp-simd-vectorization
Source: https://github.com/D1ssolve/craft-agents/tree/main/skills/exp-simd-vectorization
Command: npx skills add https://github.com/D1ssolve/craft-agents --skill exp-simd-vectorization-d1ssolve

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires System.Numerics.Tensors.

What problem does it solve? Hot-path scalar loops in .NET applications leave significant performance on the table when they process contiguous numeric arrays element by element. This Skill guides the conversion of those loops into hardware-accelerated vectorized code, choosing the right approach for each situation. ## Core Features & Use Cases - Decision-gated optimization: Checks built-in Span<T>/MemoryExtensions methods first, then TensorPrimitives APIs, and only falls back to manual SIMD intrinsics when necessary. - TensorPrimitives API reference: Complete tables for reductions, element-wise transforms, two-span operations, and fused three-span operations like AddMultiply and FusedMultiplyAdd. - Manual SIMD patterns: Three-tier Vector512/Vector256/Vector128 dispatch, unsigned range validation, nibble-lookup character counting, and cross-type widening/narrowing conversions. - Use Case: Given a scalar loop that validates whether all bytes in a buffer fall within a range, the Skill rewrites it using Vector128 unsigned comparison tricks with a scalar fallback, preserving the original method signature. ## Quick Start Optimize the scalar loop in my .NET 8 project that sums a float array using SIMD vectorization.

Frequently Asked Questions about exp-simd-vectorization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I vectorize a scalar loop in C# with SIMD?

First check if Span<T> or MemoryExtensions methods cover the operation, then try TensorPrimitives APIs like Sum or Dot. If neither fits, implement explicit Vector128/Vector256/Vector512 intrinsics with a three-tier dispatch pattern and a scalar fallback for remaining elements.

When should I use TensorPrimitives instead of manual Vector128 code?

Use TensorPrimitives whenever one or more of its APIs cover the operation, such as reductions, element-wise transforms, or fused multiply-add. Only write manual Vector128/Vector256/Vector512 code for byte-level operations, character class counting, range validation, or custom patterns TensorPrimitives does not handle.

Does System.Numerics.Tensors need a separate package reference?

Yes, if the .csproj does not already reference System.Numerics.Tensors, add a PackageReference for it before using TensorPrimitives APIs. The TensorPrimitives methods are generic and work for primitive numeric types satisfying their generic constraints.

Should I use Vector<T> or Vector128<T> for cross-platform SIMD in .NET?

Use explicit Vector128<T>, Vector256<T>, or Vector512<T> rather than Vector<T>. Prefer the portable System.Runtime.Intrinsics APIs over platform-specific intrinsics like Avx2 or AdvSimd unless there is a significant performance advantage justifying separate code paths.

When is SIMD vectorization not applicable to .NET code?

SIMD does not apply to dictionary lookups, tree traversals, linked lists, state machines, string formatting, small collections, or decimal arithmetic, since these lack contiguous numeric arrays to process in parallel. In such cases the Skill reports no SIMD opportunity with an explanation.