Install any skill in seconds. Free to start, no credit card required.
Get Started Free →dotnet/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.
Passed 18 of 23 test cases with the skill, and 11 of 23 without it.
and 7 more in the full report
8 fixed10 passed either way4 still failing1 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 8 test cases the skill fixed. Same model, same prompt, with and without the skill.
I have a C# utility function that checks whether all elements in a byte span fall within a valid boundary range using a standard loop. Please optimize this code using explicit .NET SIMD intrinsics. Ensure the solution checks available vector register widths dynamically, provides fallback logic for remaining elements, and preserves the original function signature.
| Checked | Without skill | With skill |
|---|---|---|
| Uses an if-else if chain to test vector widths. | Missed | Passed |
| Uses Vector128 hardware intrinsics for boundary checks. | Missed | Passed |
| Includes a scalar fallback loop for trailing elements. | Missed | Passed |
The instructions your model reads when the skill loads.
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..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.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.[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 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):
| 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) |
| 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) |
test cases passed, vs 11 / 23 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.