Created
May 6, 2024 08:34
-
-
Save Mrnikbobjeff/794b32528df5463ff63e59654e743ad8 to your computer and use it in GitHub Desktop.
LessThan.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[MethodImpl(MethodImplOptions.AggressiveOptimization)] | |
public unsafe static int GreaterThanSimd_Avx2_u(int boundary,ref ReadOnlySpan<int> array) | |
{ | |
Vector128<int> xmm1 = Vector128.Create(boundary); | |
Vector128<int> xmm2 = Vector128<int>.Zero; | |
Vector128<int> xmm3; | |
Vector128<int> xmm4; | |
ref int start = ref MemoryMarshal.GetReference(array); | |
for (nuint i = 0; i < (nuint)array.Length; i += 4) | |
{ | |
xmm3 = Vector128.LoadUnsafe(ref start, i); | |
xmm4 = Sse2.CompareLessThan(xmm3, xmm1); | |
xmm2 = Avx2.Subtract(xmm2, xmm4); | |
} | |
xmm2 += Vector128.Shuffle(xmm2, Vector128.Create(1, 0, 3, 2)); | |
Vector128<int> shuffle2 = Vector128.Shuffle(xmm2, Vector128.Create(2, 3, 0, 1)); | |
xmm2 += shuffle2; | |
return xmm2[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment