[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75JBDE0E6J0ZZ3WACS3YYMN":3,"skill-same:01M75JBDE0E6J0ZZ3WACS3YYMN":46},{"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":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":6,"updatedAt":31,"install":32,"resources":45},"01M75JBDE0E6J0ZZ3WACS3YYMN","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.","stanfish06\u002Fskillquarium","stanfish06","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F93099613?v=4","01M75F1CK4ZW109ZK3T26VN52F","Zhiyuan","01M75F1CM53VH6F79DZ8GXKKES",12,"MIT","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\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},"master","49e49abf2f670d429e0b7e2c0349739c3fdd5cbe","skills\u002Fexp-simd-vectorization",5,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium","https:\u002F\u002Fgithub.com\u002Fstanfish06","https:\u002F\u002Fwww.stanfish.dev\u002F","2026-11-14 21:31:37",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add stanfish06\u002Fskillquarium --skill exp-simd-vectorization",{"tool":38,"command":39},"bunx","bunx skills add stanfish06\u002Fskillquarium --skill exp-simd-vectorization",{"tool":41,"command":42},"pnpm","pnpm dlx skills add stanfish06\u002Fskillquarium --skill exp-simd-vectorization","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fexp-simd-vectorization\u002FSKILL.md",true,[],[47,54,63,70,77,84],{"skillNo":48,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":51,"categories":52,"keywords":53,"publishedAt":19},"01M76ZJTRVA456GD7K8Y3EP82H","zarr-python","Stores and queries chunked N-D scientific arrays with Zarr-Python 3, including codecs, sharding, S3\u002FGCS storage, and NumPy\u002FDask\u002FXarray integration. Use for array layout, bounded I\u002FO, format migration, or scientific metadata preservation.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":55,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":58,"licenseFileUrl":59,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":19},"01M76ZJQZ15Q1HKC5V85NHE325","yeet","Publish local changes to GitHub by confirming scope, committing intentionally, pushing the branch, and opening a draft PR through the GitHub app from this plugin, with `gh` used only as a fallback where connector coverage is insufficient.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fyeet\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fyeet\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":58,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":19},"01M76ZJ8ASZ4QYQ70Y6SBA4Z4S","xarray","N-dimensional labeled arrays and datasets in Python. Built on top of NumPy and Dask. It introduces labels in the form of dimensions, coordinates, and attributes on top of raw NumPy-like arrays, making data analysis in physical sciences more intuitive and less error-prone. Use for working with multi-dimensional scientific data, NetCDF\u002FGRIB\u002FZarr files, climate\u002Fweather\u002Foceanographic datasets, remote sensing, geospatial imaging, large out-of-memory datasets with Dask, and labeled array operations.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fxarray\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M76ZHFBXD6VXPQ02VCEG202B","writing-mstest-tests","Use when asked to fix, rewrite, update, improve, modernize, show corrected code for, or explain existing MSTest tests or MSTest-specific configuration. Use for \"review\" when corrected code or edits are wanted, even for one pasted assertion or passing tests with bad failure output. Covers expected\u002Factual labels; generic Boolean, collection, string, numeric, null, identity, exception, hard-cast, and object[] checks; TestContext\u002Flifecycle; timeout\u002Fcancellation; OS\u002FCI conditions, retry, cleanup, parallelization, MSTest.Sdk project setup, and MSTESTxxxx. Honor the installed MSTest version. DO NOT USE to design new test cases (code-testing), perform report-only audits, create project files rather than explain MSTest setup, run tests, migrate frameworks, or handle non-MSTest\u002Fnon-.NET code.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwriting-mstest-tests\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M76ZDFDF4N88RH6HSYGS7GP2","wgs-prs","End-to-end WGS to polygenic risk score pipeline. Takes paired-end FASTQ files (or a pre-existing VCF) through nf-core\u002Fsarek for variant calling, applies VCF QC (normalisation, hard filtering, Ti\u002FTv and Het\u002FHom checks), then computes polygenic risk scores via the PGS Catalog. Fills the FASTQ to VCF gap upstream of the gwas-prs skill.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwgs-prs\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":58,"licenseFileUrl":88,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":19},"01M76ZCC1SC68J42QK4MDC8RCG","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[]]