Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix size used for vectorization check in BitArray (#111558) #111564

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AnsBalin
Copy link

@AnsBalin AnsBalin commented Jan 18, 2025

This PR resolves #111558 by correcting the vector size used in the vectorization check within BitArray.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 18, 2025
@@ -885,7 +885,7 @@ public unsafe void CopyTo(Array array, int index)
}
}
}
else if (Ssse3.IsSupported && ((uint)m_length >= Vector512<byte>.Count * 2u))
else if (Ssse3.IsSupported && ((uint)m_length >= Vector128<byte>.Count * 2u))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think while you're on it, we can also replace various Sse2.And with just plain operators, e.g.

Vector128<byte> extractedLower = Sse2.And(shuffledLower, bitMask128);

to

Vector128<byte> extractedLower = shuffledLower & bitMask128;

but that's optional

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkotas
Copy link
Member

jkotas commented Jan 18, 2025

Run a quick perf test that shows this is a perf improvement for all affected sizes?

@MihaZupan
Copy link
Member

MihaZupan commented Jan 18, 2025

FWIW this would only affect pre-AVX2 X86 CPUs (or NAOT as I was informed we don't do Avx2 checks :/)

else if (Avx2.IsSupported && (uint)m_length >= Vector256<byte>.Count)
...
else if (Ssse3.IsSupported && ((uint)m_length >= Vector128<byte>.Count * 2u))
...
else if (AdvSimd.Arm64.IsSupported)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Collections community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong size used for vectorization check in BitArray
5 participants