[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M756G0WVVFKMKB9A7PCEWYAK":3,"skill-same:01M756G0WVVFKMKB9A7PCEWYAK":45},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":29,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M756G0WVVFKMKB9A7PCEWYAK","exp-simd-vectorization",null,"Optimizes hot-path scalar loops in .NET 8+ with cross-platform Vector128\u002FVector256\u002FVector512 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\u002Fdouble math operations.","weiflycc-cmd\u002Fskills","weiflycc-cmd","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F250846518?v=4","01M756C4PFGZJWKK04WFB9S5XF","威飛工作室","01M756C4QJJ66QDXN2RN6SXY87",0,"MIT","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-experimental\u002Fskills\u002Fexp-simd-vectorization\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: exp-simd-vectorization\ndescription: \"Optimizes hot-path scalar loops in .NET 8+ with cross-platform Vector128\u002FVector256\u002FVector512 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\u002Fdouble math operations.\"\nlicense: MIT\n---\n\n# SIMD Vectorization\n\n## Decision Gate\n1. **Check `Span\u003CT>` and `MemoryExtensions` first.** If the operation can be expressed using built-in `Span\u003CT>` 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.\n2. **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: `\u003CPackageReference Include=\"System.Numerics.Tensors\" \u002F>` (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.\n3. **Scalar loop over contiguous array\u002Fspan** of `byte`, `sbyte`, `short`, `ushort`, `int`, `uint`, `long`, `ulong`, `nint`, `nuint`, `float`, `double` (and `char` via reinterpretation as `ushort`)? → Implement with explicit `Vector128\u003CT>` \u002F `Vector256\u003CT>` \u002F `Vector512\u003CT>` intrinsics using the patterns below.\n4. **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.\n\n## TensorPrimitives API Reference\nTensorPrimitives APIs are generic and work for any primitive type that satisfies the method's generic constraints — not just `float`\u002F`double`. For example, `Sum` requires `IAdditionOperators\u003CT,T,T>` + `IAdditiveIdentity\u003CT,T>` and works for all primitive numeric types, while `CosineSimilarity` requires `IRootFunctions\u003CT>` and only works for `float`\u002F`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):\n\n### Reductions (span → scalar)\n| Operation | API |\n|-----------|-----|\n| Sum | `TensorPrimitives.Sum(span)` |\n| Sum of squares | `TensorPrimitives.SumOfSquares(span)` |\n| Sum of magnitudes (L1 norm) | `TensorPrimitives.SumOfMagnitudes(span)` |\n| L2 norm | `TensorPrimitives.Norm(span)` |\n| Product of all elements | `TensorPrimitives.Product(span)` |\n| Min value | `TensorPrimitives.Min(span)` |\n| Max value | `TensorPrimitives.Max(span)` |\n| Index of max | `TensorPrimitives.IndexOfMax(span)` |\n| Index of min | `TensorPrimitives.IndexOfMin(span)` |\n| Dot product | `TensorPrimitives.Dot(a, b)` |\n| Cosine similarity | `TensorPrimitives.CosineSimilarity(a, b)` |\n| Euclidean distance | `TensorPrimitives.Distance(a, b)` |\n\n### Element-wise transforms (span → span)\n| Operation | API |\n|-----------|-----|\n| Negate | `TensorPrimitives.Negate(src, dst)` |\n| Abs | `TensorPrimitives.Abs(src, dst)` |\n| Sqrt | `TensorPrimitives.Sqrt(src, dst)` |\n| Exp | `TensorPrimitives.Exp(src, dst)` |\n| Log | `TensorPrimitives.Log(src, dst)` |\n| Log2 | `TensorPrimitives.Log2(src, dst)` |\n| Tanh | `TensorPrimitives.Tanh(src, dst)` |\n| Sigmoid | `TensorPrimitives.Sigmoid(src, dst)` |\n| SoftMax | `TensorPrimitives.SoftMax(src, dst)` |\n| Sinh | `TensorPrimitives.Sinh(src, dst)` |\n| Cosh | `TensorPrimitives.Cosh(src, dst)` |\n| Round | `TensorPrimitives.Round(src, dst)` |\n| Floor | `TensorPrimitives.Floor(src, dst)` |\n| Ceiling | `TensorPrimitives.Ceiling(src, dst)` |\n| CopySign | `TensorPrimitives.CopySign(src, sign, dst)` |\n| Pow | `TensorPrimitives.Pow(bases, exponents, dst)` |\n\n### Two-span operations (a, b → dst)\n| Operation | API |\n|-----------|-----|\n| Add | `TensorPrimitives.Add(a, b, dst)` |\n| Subtract | `TensorPrimitives.Subtract(a, b, dst)` |\n| Multiply | `TensorPrimitives.Multiply(a, b, dst)` |\n| Divide | `TensorPrimitives.Divide(a, b, dst)` |\n| Element-wise Min | `TensorPrimitives.Min(a, b, dst)` |\n| Element-wise Max | `TensorPrimitives.Max(a, b, dst)` |\n\n### Three-span fused operations\n| Operation | API |\n|-----------|-----|\n| (x+y)*z | `TensorPrimitives.AddMultiply(x, y, z, dst)` |\n| x*y+z | `TensorPrimitives.MultiplyAdd(x, y, z, dst)` |\n| fma(x,y,z) | `TensorPrimitives.FusedMultiplyAdd(x, y, z, dst)` |\n\n> `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.\n\n## Manual SIMD with Vector128\u002FVector256\u002FVector512\n\nUse 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.\n\n### Required imports\n```csharp\nusing System.Runtime.CompilerServices;\nusing System.Runtime.InteropServices;\nusing System.Runtime.Intrinsics;\n```\nPrefer 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.\n\n### Three-tier dispatch pattern\nAlways include all three tiers. Use `if`\u002F`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:\n```csharp\nref var src = ref MemoryMarshal.GetReference(span);\nuint i = 0;\nuint length = (uint)span.Length;\n\nif (Vector512.IsHardwareAccelerated && Vector512\u003CT>.IsSupported)\n{\n    uint vec512Count = (uint)Vector512\u003CT>.Count;\n    while (i + vec512Count \u003C= length)\n    {\n        var vec = Vector512.LoadUnsafe(ref src, i);\n        \u002F\u002F ... process vec ...\n        i += vec512Count;\n    }\n}\nelse if (Vector256.IsHardwareAccelerated && Vector256\u003CT>.IsSupported)\n{\n    uint vec256Count = (uint)Vector256\u003CT>.Count;\n    while (i + vec256Count \u003C= length)\n    {\n        var vec = Vector256.LoadUnsafe(ref src, i);\n        \u002F\u002F ... process vec ...\n        i += vec256Count;\n    }\n}\nelse if (Vector128.IsHardwareAccelerated && Vector128\u003CT>.IsSupported)\n{\n    uint vec128Count = (uint)Vector128\u003CT>.Count;\n    while (i + vec128Count \u003C= length)\n    {\n        var vec = Vector128.LoadUnsafe(ref src, i);\n        \u002F\u002F ... process vec ...\n        i += vec128Count;\n    }\n}\n\u002F\u002F Scalar fallback for remaining elements (and the only loop hit for small inputs)\nfor (; i \u003C length; i++)\n{\n    \u002F\u002F ... scalar processing ...\n}\n```\n\n### Core SIMD operations\n- **Load\u002FStore:** `Vector128.LoadUnsafe(ref src, offset)` \u002F `.StoreUnsafe(ref dst, offset)`\n- **Arithmetic:** `+`, `-`, `*`, `\u002F` operators on vector types\n- **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)`.\n- **Comparison:** `Vector128.Equals`, `.LessThan`, `.GreaterThan` — returns mask vector\n- **Mask ops:** `Vector128.All(mask)`, `.Any(mask)`, `.None(mask)`, `.Count(mask)`, `.CountWhereAllBitsSet(mask)`\n- **Horizontal:** `Vector128.Sum(vec)` for reduction; `.Min(a,b)`, `.Max(a,b)` element-wise\n- **Broadcast:** `Vector128.Create(scalarValue)` — fill all lanes with one value\n- **Bitwise:** `&`, `|`, `^`, `~` operators; `Vector128.ShiftLeft`, `.ShiftRightLogical`\n- **Widening:** `Vector128.WidenLower(v)` \u002F `.WidenUpper(v)` for byte→short, short→int\n- **Narrowing:** `Vector128.Narrow(lower, upper)` for int→short, short→byte\n- **Type convert:** `Vector128.ConvertToSingle(intVec)`, `.ConvertToInt32(floatVec)`\n- **Shuffle:** `Vector128.Shuffle(vec, indices)` — lookup table \u002F permutation\n- **Conditional:** `Vector128.ConditionalSelect(mask, trueVec, falseVec)`\n\n### Pattern: Unsigned range check (byte-range validation)\nFor checking if all bytes are in range [lo, hi]:\n```csharp\nvar vLo = Vector128.Create((byte)lo);\nvar vRange = Vector128.Create((byte)(hi - lo));\n\u002F\u002F (b - lo) > range means out-of-range (unsigned wraparound catches b \u003C lo)\nvar shifted = Vector128.Subtract(vec, vLo);\nvar inRange = Vector128.LessThanOrEqual(shifted, vRange);\nif (!Vector128.All(inRange.AsByte())) return false; \u002F\u002F for validation\n\u002F\u002F or: count += Vector128.CountWhereAllBitsSet(inRange); \u002F\u002F for counting\n```\n\n### Pattern: Nibble-lookup counting (character classes, popcount, etc.)\nFor counting bytes matching a sparse set of values (vowels, digits, punctuation, bit counts) — build two 16-byte lookup tables indexed by low\u002Fhigh nibble:\n```csharp\nvar lo_lut = Vector128.Create(\u002F* 16 bytes: bit pattern for low nibble match *\u002F);\nvar hi_lut = Vector128.Create(\u002F* 16 bytes: bit pattern for high nibble match *\u002F);\nvar nibbleMask = Vector128.Create((byte)0x0F);\n\nvar lo_nibble = vec & nibbleMask;\nvar hi_nibble = Vector128.ShiftRightLogical(vec.AsUInt16(), 4).AsByte() & nibbleMask;\nvar lo_match = Vector128.Shuffle(lo_lut, lo_nibble);\nvar hi_match = Vector128.Shuffle(hi_lut, hi_nibble);\nvar match = lo_match & hi_match;\ncount += Vector128.CountWhereAllBitsSet(~Vector128.Equals(match, Vector128\u003Cbyte>.Zero));\n```\nThis same technique works for popcount (LUT = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4}).\nFor simpler cases (single byte value, adjacent range), use `Equals` + `Count` or range check instead.\n\n### Pattern: Cross-type conversion (widening chains)\nWhen the source and destination types differ (e.g., byte→float for dequantization, short→byte for narrowing):\n```csharp\n\u002F\u002F Widen: byte → short → int → float\nvar bytes = Vector128.LoadUnsafe(ref src, offset);\nvar (lo16, hi16) = Vector128.Widen(bytes);\nvar (lo32a, lo32b) = Vector128.Widen(lo16);\nvar f0 = Vector128.ConvertToSingle(lo32a.AsInt32());\n\n\u002F\u002F Narrow: int → short → byte (with saturation via Min\u002FMax clamping)\nvar clamped = Vector128.Min(Vector128.Max(vec, Vector128\u003Cshort>.Zero), Vector128.Create((short)255));\nvar narrowed = Vector128.Narrow(clamped.AsUInt16(), nextVec.AsUInt16());\n```\n\n### Trailing elements\n- **Idempotent ops** (validation, search): overlap last vector — re-processing is safe\n- **Aggregations** (sum, count, min\u002Fmax): scalar loop for remainder to avoid double-counting\n- **Store ops** (transform in-place): use `ConditionalSelect` to merge with last stored vector\n\n## Key Rules\n- Preserve original method signature — drop-in replacement\n- Keep scalar code as fallback — never delete it\n- Use `Vector128\u003CT>` \u002F `Vector256\u003CT>` \u002F `Vector512\u003CT>` explicitly — never `Vector\u003CT>`\n- Prefer portable `Vector128\u003CT>`\u002F`Vector256\u003CT>`\u002F`Vector512\u003CT>` APIs over platform-specific intrinsics (`Avx2`, `Sse42`, `AdvSimd`, `Fma`) unless there is a significant performance advantage\n- Testing: use `dotnet run` (NOT `dotnet test`) — xunit.v3 is an in-process runner\n","# SIMD Vectorization\n\n## Decision Gate\n1. **Check `Span\u003CT>` and `MemoryExtensions` first.** If the operation can be expressed using built-in `Span\u003CT>` 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.\n2. **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: `\u003CPackageReference Include=\"System.Numerics.Tensors\" \u002F>` (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.\n3. **Scalar loop over contiguous array\u002Fspan** of `byte`, `sbyte`, `short`, `ushort`, `int`, `uint`, `long`, `ulong`, `nint`, `nuint`, `float`, `double` (and `char` via reinterpretation as `ushort`)? → Implement with explicit `Vector128\u003CT>` \u002F `Vector256\u003CT>` \u002F `Vector512\u003CT>` intrinsics using the patterns below.\n4. **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.\n\n## TensorPrimitives API Reference\nTensorPrimitives APIs are generic and work for any primitive type that satisfies the method's generic constraints — not just `float`\u002F`double`. For example, `Sum` requires `IAdditionOperators\u003CT,T,T>` + `IAdditiveIdentity\u003CT,T>` and works for all primitive numeric types, while `CosineSimilarity` requires `IRootFunctions\u003CT>` and only works for `float`\u002F`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):\n\n### Reductions (span → scalar)\n| Operation | API |\n|-----------|-----|\n| Sum | `TensorPrimitives.Sum(span)` |\n| Sum of squares | `TensorPrimitives.SumOfSquares(span)` |\n| Sum of magnitudes (L1 norm) | `TensorPrimitives.SumOfMagnitudes(span)` |\n| L2 norm | `TensorPrimitives.Norm(span)` |\n| Product of all elements | `TensorPrimitives.Product(span)` |\n| Min value | `TensorPrimitives.Min(span)` |\n| Max value | `TensorPrimitives.Max(span)` |\n| Index of max | `TensorPrimitives.IndexOfMax(span)` |\n| Index of min | `TensorPrimitives.IndexOfMin(span)` |\n| Dot product | `TensorPrimitives.Dot(a, b)` |\n| Cosine similarity | `TensorPrimitives.CosineSimilarity(a, b)` |\n| Euclidean distance | `TensorPrimitives.Distance(a, b)` |\n\n### Element-wise transforms (span → span)\n| Operation | API |\n|-----------|-----|\n| Negate | `TensorPrimitives.Negate(src, dst)` |\n| Abs | `TensorPrimitives.Abs(src, dst)` |\n| Sqrt | `TensorPrimitives.Sqrt(src, dst)` |\n| Exp | `TensorPrimitives.Exp(src, dst)` |\n| Log | `TensorPrimitives.Log(src, dst)` |\n| Log2 | `TensorPrimitives.Log2(src, dst)` |\n| Tanh | `TensorPrimitives.Tanh(src, dst)` |\n| Sigmoid | `TensorPrimitives.Sigmoid(src, dst)` |\n| SoftMax | `TensorPrimitives.SoftMax(src, dst)` |\n| Sinh | `TensorPrimitives.Sinh(src, dst)` |\n| Cosh | `TensorPrimitives.Cosh(src, dst)` |\n| Round | `TensorPrimitives.Round(src, dst)` |\n| Floor | `TensorPrimitives.Floor(src, dst)` |\n| Ceiling | `TensorPrimitives.Ceiling(src, dst)` |\n| CopySign | `TensorPrimitives.CopySign(src, sign, dst)` |\n| Pow | `TensorPrimitives.Pow(bases, exponents, dst)` |\n\n### Two-span operations (a, b → dst)\n| Operation | API |\n|-----------|-----|\n| Add | `TensorPrimitives.Add(a, b, dst)` |\n| Subtract | `TensorPrimitives.Subtract(a, b, dst)` |\n| Multiply | `TensorPrimitives.Multiply(a, b, dst)` |\n| Divide | `TensorPrimitives.Divide(a, b, dst)` |\n| Element-wise Min | `TensorPrimitives.Min(a, b, dst)` |\n| Element-wise Max | `TensorPrimitives.Max(a, b, dst)` |\n\n### Three-span fused operations\n| Operation | API |\n|-----------|-----|\n| (x+y)*z | `TensorPrimitives.AddMultiply(x, y, z, dst)` |\n| x*y+z | `TensorPrimitives.MultiplyAdd(x, y, z, dst)` |\n| fma(x,y,z) | `TensorPrimitives.FusedMultiplyAdd(x, y, z, dst)` |\n\n> `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.\n\n## Manual SIMD with Vector128\u002FVector256\u002FVector512\n\nUse 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.\n\n### Required imports\n```csharp\nusing System.Runtime.CompilerServices;\nusing System.Runtime.InteropServices;\nusing System.Runtime.Intrinsics;\n```\nPrefer 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.\n\n### Three-tier dispatch pattern\nAlways include all three tiers. Use `if`\u002F`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:\n```csharp\nref var src = ref MemoryMarshal.GetReference(span);\nuint i = 0;\nuint length = (uint)span.Length;\n\nif (Vector512.IsHardwareAccelerated && Vector512\u003CT>.IsSupported)\n{\n    uint vec512Count = (uint)Vector512\u003CT>.Count;\n    while (i + vec512Count \u003C= length)\n    {\n        var vec = Vector512.LoadUnsafe(ref src, i);\n        \u002F\u002F ... process vec ...\n        i += vec512Count;\n    }\n}\nelse if (Vector256.IsHardwareAccelerated && Vector256\u003CT>.IsSupported)\n{\n    uint vec256Count = (uint)Vector256\u003CT>.Count;\n    while (i + vec256Count \u003C= length)\n    {\n        var vec = Vector256.LoadUnsafe(ref src, i);\n        \u002F\u002F ... process vec ...\n        i += vec256Count;\n    }\n}\nelse if (Vector128.IsHardwareAccelerated && Vector128\u003CT>.IsSupported)\n{\n    uint vec128Count = (uint)Vector128\u003CT>.Count;\n    while (i + vec128Count \u003C= length)\n    {\n        var vec = Vector128.LoadUnsafe(ref src, i);\n        \u002F\u002F ... process vec ...\n        i += vec128Count;\n    }\n}\n\u002F\u002F Scalar fallback for remaining elements (and the only loop hit for small inputs)\nfor (; i \u003C length; i++)\n{\n    \u002F\u002F ... scalar processing ...\n}\n```\n\n### Core SIMD operations\n- **Load\u002FStore:** `Vector128.LoadUnsafe(ref src, offset)` \u002F `.StoreUnsafe(ref dst, offset)`\n- **Arithmetic:** `+`, `-`, `*`, `\u002F` operators on vector types\n- **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)`.\n- **Comparison:** `Vector128.Equals`, `.LessThan`, `.GreaterThan` — returns mask vector\n- **Mask ops:** `Vector128.All(mask)`, `.Any(mask)`, `.None(mask)`, `.Count(mask)`, `.CountWhereAllBitsSet(mask)`\n- **Horizontal:** `Vector128.Sum(vec)` for reduction; `.Min(a,b)`, `.Max(a,b)` element-wise\n- **Broadcast:** `Vector128.Create(scalarValue)` — fill all lanes with one value\n- **Bitwise:** `&`, `|`, `^`, `~` operators; `Vector128.ShiftLeft`, `.ShiftRightLogical`\n- **Widening:** `Vector128.WidenLower(v)` \u002F `.WidenUpper(v)` for byte→short, short→int\n- **Narrowing:** `Vector128.Narrow(lower, upper)` for int→short, short→byte\n- **Type convert:** `Vector128.ConvertToSingle(intVec)`, `.ConvertToInt32(floatVec)`\n- **Shuffle:** `Vector128.Shuffle(vec, indices)` — lookup table \u002F permutation\n- **Conditional:** `Vector128.ConditionalSelect(mask, trueVec, falseVec)`\n\n### Pattern: Unsigned range check (byte-range validation)\nFor checking if all bytes are in range [lo, hi]:\n```csharp\nvar vLo = Vector128.Create((byte)lo);\nvar vRange = Vector128.Create((byte)(hi - lo));\n\u002F\u002F (b - lo) > range means out-of-range (unsigned wraparound catches b \u003C lo)\nvar shifted = Vector128.Subtract(vec, vLo);\nvar inRange = Vector128.LessThanOrEqual(shifted, vRange);\nif (!Vector128.All(inRange.AsByte())) return false; \u002F\u002F for validation\n\u002F\u002F or: count += Vector128.CountWhereAllBitsSet(inRange); \u002F\u002F for counting\n```\n\n### Pattern: Nibble-lookup counting (character classes, popcount, etc.)\nFor counting bytes matching a sparse set of values (vowels, digits, punctuation, bit counts) — build two 16-byte lookup tables indexed by low\u002Fhigh nibble:\n```csharp\nvar lo_lut = Vector128.Create(\u002F* 16 bytes: bit pattern for low nibble match *\u002F);\nvar hi_lut = Vector128.Create(\u002F* 16 bytes: bit pattern for high nibble match *\u002F);\nvar nibbleMask = Vector128.Create((byte)0x0F);\n\nvar lo_nibble = vec & nibbleMask;\nvar hi_nibble = Vector128.ShiftRightLogical(vec.AsUInt16(), 4).AsByte() & nibbleMask;\nvar lo_match = Vector128.Shuffle(lo_lut, lo_nibble);\nvar hi_match = Vector128.Shuffle(hi_lut, hi_nibble);\nvar match = lo_match & hi_match;\ncount += Vector128.CountWhereAllBitsSet(~Vector128.Equals(match, Vector128\u003Cbyte>.Zero));\n```\nThis same technique works for popcount (LUT = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4}).\nFor simpler cases (single byte value, adjacent range), use `Equals` + `Count` or range check instead.\n\n### Pattern: Cross-type conversion (widening chains)\nWhen the source and destination types differ (e.g., byte→float for dequantization, short→byte for narrowing):\n```csharp\n\u002F\u002F Widen: byte → short → int → float\nvar bytes = Vector128.LoadUnsafe(ref src, offset);\nvar (lo16, hi16) = Vector128.Widen(bytes);\nvar (lo32a, lo32b) = Vector128.Widen(lo16);\nvar f0 = Vector128.ConvertToSingle(lo32a.AsInt32());\n\n\u002F\u002F Narrow: int → short → byte (with saturation via Min\u002FMax clamping)\nvar clamped = Vector128.Min(Vector128.Max(vec, Vector128\u003Cshort>.Zero), Vector128.Create((short)255));\nvar narrowed = Vector128.Narrow(clamped.AsUInt16(), nextVec.AsUInt16());\n```\n\n### Trailing elements\n- **Idempotent ops** (validation, search): overlap last vector — re-processing is safe\n- **Aggregations** (sum, count, min\u002Fmax): scalar loop for remainder to avoid double-counting\n- **Store ops** (transform in-place): use `ConditionalSelect` to merge with last stored vector\n\n## Key Rules\n- Preserve original method signature — drop-in replacement\n- Keep scalar code as fallback — never delete it\n- Use `Vector128\u003CT>` \u002F `Vector256\u003CT>` \u002F `Vector512\u003CT>` explicitly — never `Vector\u003CT>`\n- Prefer portable `Vector128\u003CT>`\u002F`Vector256\u003CT>`\u002F`Vector512\u003CT>` APIs over platform-specific intrinsics (`Avx2`, `Sse42`, `AdvSimd`, `Fma`) unless there is a significant performance advantage\n- Testing: use `dotnet run` (NOT `dotnet test`) — xunit.v3 is an in-process runner\n",{"name":5,"license":15,"description":7},"main","5810d492c9b301d8227f932bf87b5c954c4fa4d6","plugins\u002Fdotnet-experimental\u002Fskills\u002Fexp-simd-vectorization","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd","weiflycc.com","2026-11-10 03:26:55",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add weiflycc-cmd\u002Fskills --skill exp-simd-vectorization",{"tool":37,"command":38},"bunx","bunx skills add weiflycc-cmd\u002Fskills --skill exp-simd-vectorization",{"tool":40,"command":41},"pnpm","pnpm dlx skills add weiflycc-cmd\u002Fskills --skill exp-simd-vectorization","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-experimental\u002Fskills\u002Fexp-simd-vectorization\u002FSKILL.md",true,[],[46,53,60,67,74,81],{"skillNo":47,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":19},"01M76SGT4WG5682JQJ0V3NSK6X","system-text-json-net11","Provides guidance on new System.Text.Json APIs introduced in .NET 11. It covers typed JsonTypeInfo access via GetTypeInfo\u003CT> and TryGetTypeInfo\u003CT> on JsonSerializerOptions, and the new JsonNamingPolicy.PascalCase static property. Use when serializing or deserializing JSON in .NET 11 applications and needing typed metadata access or PascalCase property naming.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet11\u002Fskills\u002Fsystem-text-json-net11\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M76SGPNZYYV9BCZJW7BF7J8A","nuget-trusted-publishing","Set up NuGet trusted publishing (OIDC) on a GitHub Actions repo — replaces long-lived API keys with short-lived tokens. USE FOR: trusted publishing, NuGet OIDC, keyless NuGet publish, migrate from NuGet API key, NuGet\u002Flogin, secure NuGet publishing. DO NOT USE FOR: publishing to private feeds or Azure Artifacts (OIDC is nuget.org only). INVOKES: shell (powershell or bash), edit, create, ask_user for guided repo setup.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet\u002Fskills\u002Fnuget-trusted-publishing\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":19},"01M76SGHVNBNVM1DMVDYTMAE5G","dotnet-pinvoke","Correctly call native (C\u002FC++) libraries from .NET using P\u002FInvoke and LibraryImport. Covers function signatures, string marshalling, memory lifetime, SafeHandle, and cross-platform patterns. USE FOR: writing new P\u002FInvoke or LibraryImport declarations, reviewing or debugging existing native interop code, wrapping a C or C++ library for use in .NET, diagnosing crashes, memory leaks, or corruption at the managed\u002Fnative boundary. DO NOT USE FOR: COM interop, C++\u002FCLI mixed-mode assemblies, or pure managed code with no native dependencies.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet\u002Fskills\u002Fdotnet-pinvoke\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":19},"01M76SGDB9Z3GSB1CFW314NC84","csharp-scripts","Run file-based C# apps with the .NET CLI when the user explicitly wants C#\u002F.NET code without creating a project. Use for C# language\u002FAPI experiments, one-file C# apps, small multi-file C# apps composed with `#:include`\u002F`#:exclude`, or C# file-based apps linked with `#:ref`. Do not use for language-agnostic throwaway scripts, generic computations, Python\u002FPowerShell-style automation, full projects, or existing app integration.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet\u002Fskills\u002Fcsharp-scripts\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":19},"01M76SG805T8W764WAKB1NP3CJ","thread-abort-migration","Guides migration of .NET Framework Thread.Abort usage to cooperative cancellation in modern .NET. USE FOR: modernizing code that calls Thread.Abort, catching ThreadAbortException, replacing Thread.ResetAbort, replacing Thread.Interrupt for thread termination, resolving PlatformNotSupportedException or SYSLIB0006 after retargeting to .NET 6+, migrating ASP.NET Response.End or Response.Redirect(url, true) which internally call Thread.Abort. DO NOT USE FOR: code that only uses Thread.Join, Thread.Sleep, or Thread.Start without any abort, interrupt, or ThreadAbortException usage — these APIs work identically in modern .NET and need no migration. Also not for projects staying on .NET Framework, or Thread.Abort usage inside third-party libraries you do not control.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-upgrade\u002Fskills\u002Fthread-abort-migration\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":19},"01M76SG2588ZJBE5C51HYJJSKV","migrate-nullable-references","Enable 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\u002FCS8618\u002FCS86xx 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.","https:\u002F\u002Fgithub.com\u002Fweiflycc-cmd\u002Fskills\u002Fblob\u002Fmain\u002Fplugins\u002Fdotnet-upgrade\u002Fskills\u002Fmigrate-nullable-references\u002FSKILL.md",[],[]]