Update BitArray.CopyTo to use cross-platform intrinsics #120627
+19
−82
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #114818 (comment)
This PR updates
BitArray.CopyTo
to use cross-platform intrinsic APIs instead of platform-specific ones, making the code more portable across different hardware architectures.Changes
AVX512 path (Vector512)
Avx512BW.IsSupported
→Vector512.IsHardwareAccelerated
Avx512BW.Shuffle(x, y)
→Vector512.Shuffle(x, y)
Avx512F.And(x, y)
→x & y
Avx512BW.Min(x, y)
→Vector512.Min(x, y)
Avx512F.Store(x, y)
→y.Store(x)
AVX2 path (Vector256)
Avx2.IsSupported
→Vector256.IsHardwareAccelerated
Avx2.Shuffle(x, y)
→Vector256.Shuffle(x, y)
Avx2.And(x, y)
→x & y
Avx2.Min(x, y)
→Vector256.Min(x, y)
Avx.Store(x, y)
→y.Store(x)
Unified Vector128 path
Ssse3.IsSupported
→Vector128.IsHardwareAccelerated
Ssse3.Shuffle(x, y)
→Vector128.Shuffle(x, y)
(internally usesPackedSimd.Swizzle
on WASM andAdvSimd.Arm64.VectorTableLookup
on ARM)Sse2.And(x, y)
/PackedSimd.And(x, y)
/AdvSimd.And(x, y)
→x & y
Sse2.Min(x, y)
/PackedSimd.Min(x, y)
/AdvSimd.Min(x, y)
→Vector128.Min(x, y)
Sse2.Store(x, y)
/PackedSimd.Store(x, y)
/AdvSimd.Arm64.StorePair(x, y, z)
→y.Store(x)
Benefits
VectorTableLookup
instead of manually chainedZipLow
/ZipHigh
instructionsTesting
All existing System.Collections tests pass (33,438 tests, 0 failures).
Fixes #116079
Original prompt
Fixes #116079
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.