Skip to content

Commit

Permalink
Obsolete AdvSimd intrinsic implementations, minor improvements in cer…
Browse files Browse the repository at this point in the history
…tain areas
  • Loading branch information
RealityProgrammer committed Nov 22, 2023
1 parent 5ff7b68 commit fa0ece6
Show file tree
Hide file tree
Showing 69 changed files with 608 additions and 625 deletions.
68 changes: 34 additions & 34 deletions X10D.Tests/src/Core/SpanTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,21 @@ public void PackByteInternal_Sse2_ShouldReturnCorrectByte_GivenReadOnlySpan_Usin
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
public void PackByteInternal_AdvSimd_ShouldReturnCorrectByte_GivenReadOnlySpan_Using()
{
if (!AdvSimd.IsSupported)
{
return;
}

const byte expected = 0b00110011;
ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};

byte actual = span.PackByteInternal_AdvSimd();

Assert.That(actual, Is.EqualTo(expected));
}
// [Test]
// public void PackByteInternal_AdvSimd_ShouldReturnCorrectByte_GivenReadOnlySpan_Using()
// {
// if (!AdvSimd.IsSupported)
// {
// return;
// }
//
// const byte expected = 0b00110011;
// ReadOnlySpan<bool> span = stackalloc bool[8] {true, true, false, false, true, true, false, false};
//
// byte actual = span.PackByteInternal_AdvSimd();
//
// Assert.That(actual, Is.EqualTo(expected));
// }
#endif

[Test]
Expand Down Expand Up @@ -345,25 +345,25 @@ public void PackInt32Internal_Avx2_ShouldReturnCorrectInt32_GivenReadOnlySpan()
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
public void PackInt32Internal_AdvSimd_ShouldReturnCorrectInt32_GivenReadOnlySpan()
{
if (!AdvSimd.IsSupported)
{
return;
}

const int expected = 0b01010101_10101010_01010101_10101010;
ReadOnlySpan<bool> span = stackalloc bool[32]
{
false, true, false, true, false, true, false, true, true, false, true, false, true, false, true, false, false,
true, false, true, false, true, false, true, true, false, true, false, true, false, true, false,
};

int actual = span.PackInt32Internal_AdvSimd();

Assert.That(actual, Is.EqualTo(expected));
}
// [Test]
// public void PackInt32Internal_AdvSimd_ShouldReturnCorrectInt32_GivenReadOnlySpan()
// {
// if (!AdvSimd.IsSupported)
// {
// return;
// }
//
// const int expected = 0b01010101_10101010_01010101_10101010;
// ReadOnlySpan<bool> span = stackalloc bool[32]
// {
// false, true, false, true, false, true, false, true, true, false, true, false, true, false, true, false, false,
// true, false, true, false, true, false, true, true, false, true, false, true, false, true, false,
// };
//
// int actual = span.PackInt32Internal_AdvSimd();
//
// Assert.That(actual, Is.EqualTo(expected));
// }
#endif

[Test]
Expand Down
8 changes: 4 additions & 4 deletions X10D/src/Collections/ByteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class ByteExtensions
/// <param name="value">The value to unpack.</param>
/// <returns>An array of <see cref="bool" /> with length 8.</returns>
[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
public static bool[] Unpack(this byte value)
{
var buffer = new bool[Size];
Expand All @@ -38,7 +38,7 @@ public static bool[] Unpack(this byte value)
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
[ExcludeFromCodeCoverage]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
public static void Unpack(this byte value, Span<bool> destination)
{
if (destination.Length < Size)
Expand All @@ -57,7 +57,7 @@ public static void Unpack(this byte value, Span<bool> destination)
UnpackInternal_Fallback(value, destination);
}

[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal static void UnpackInternal_Fallback(this byte value, Span<bool> destination)
{
for (var index = 0; index < Size; index++)
Expand All @@ -67,7 +67,7 @@ internal static void UnpackInternal_Fallback(this byte value, Span<bool> destina
}

#if NETCOREAPP3_0_OR_GREATER
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal unsafe static void UnpackInternal_Ssse3(this byte value, Span<bool> destination)
{
fixed (bool* pDestination = destination)
Expand Down
8 changes: 4 additions & 4 deletions X10D/src/Collections/Int16Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class Int16Extensions
/// <param name="value">The value to unpack.</param>
/// <returns>An array of <see cref="bool" /> with length 16.</returns>
[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
public static bool[] Unpack(this short value)
{
var ret = new bool[Size];
Expand All @@ -38,7 +38,7 @@ public static bool[] Unpack(this short value)
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
[ExcludeFromCodeCoverage]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
public static void Unpack(this short value, Span<bool> destination)
{
if (destination.Length < Size)
Expand All @@ -57,7 +57,7 @@ public static void Unpack(this short value, Span<bool> destination)
UnpackInternal_Fallback(value, destination);
}

[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal static void UnpackInternal_Fallback(this short value, Span<bool> destination)
{
for (var index = 0; index < Size; index++)
Expand All @@ -67,7 +67,7 @@ internal static void UnpackInternal_Fallback(this short value, Span<bool> destin
}

#if NETCOREAPP3_0_OR_GREATER
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal unsafe static void UnpackInternal_Ssse3(this short value, Span<bool> destination)
{
fixed (bool* pDestination = destination)
Expand Down
8 changes: 4 additions & 4 deletions X10D/src/Collections/Int32Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class Int32Extensions
/// <param name="value">The value to unpack.</param>
/// <returns>An array of <see cref="bool" /> with length 32.</returns>
[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
public static bool[] Unpack(this int value)
{
var ret = new bool[Size];
Expand All @@ -38,7 +38,7 @@ public static bool[] Unpack(this int value)
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
[ExcludeFromCodeCoverage]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
public static void Unpack(this int value, Span<bool> destination)
{
if (destination.Length < Size)
Expand All @@ -63,7 +63,7 @@ public static void Unpack(this int value, Span<bool> destination)
UnpackInternal_Fallback(value, destination);
}

[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal static void UnpackInternal_Fallback(this int value, Span<bool> destination)
{
for (var index = 0; index < Size; index++)
Expand All @@ -73,7 +73,7 @@ internal static void UnpackInternal_Fallback(this int value, Span<bool> destinat
}

#if NETCOREAPP3_0_OR_GREATER
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal static unsafe void UnpackInternal_Ssse3(this int value, Span<bool> destination)
{
fixed (bool* pDestination = destination)
Expand Down
15 changes: 2 additions & 13 deletions X10D/src/Collections/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,9 @@ public static void RemoveRange<T>(this IList<T> source, Range range)
}
#endif

int start = range.Start.IsFromEnd ? source.Count - range.Start.Value : range.Start.Value;
int end = range.End.IsFromEnd ? source.Count - range.End.Value : range.End.Value;
(int start, int length) = range.GetOffsetAndLength(source.Count);

if (end < start)
{
throw new ArgumentException(ExceptionMessages.EndIndexLessThanStartIndex);
}

if (end >= source.Count)
{
throw new ArgumentOutOfRangeException(nameof(range), ExceptionMessages.EndIndexGreaterThanCount);
}

for (int index = end; index >= start; index--)
for (int index = start + length; index >= start; index--)
{
source.RemoveAt(index);
}
Expand Down
6 changes: 3 additions & 3 deletions X10D/src/CompilerServices/CompilerResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace X10D.CompilerServices;
internal static class CompilerResources
{
#if NETCOREAPP3_0_OR_GREATER
public const MethodImplOptions MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining |
System.Runtime.CompilerServices.MethodImplOptions.AggressiveOptimization;
public const MethodImplOptions MaxOptimization = System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining |
System.Runtime.CompilerServices.MethodImplOptions.AggressiveOptimization;
#else
public const MethodImplOptions MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining;
public const MethodImplOptions MaxOptimization = System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining;
#endif
}
20 changes: 10 additions & 10 deletions X10D/src/Core/IntrinsicExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class IntrinsicExtensions
/// A <see cref="Vector64{T}"/> of <see langword="byte"/> which remapped back to 0 and 1 based on boolean truthiness.
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
public static Vector64<byte> CorrectBoolean(this Vector64<byte> vector)
{
Vector64<byte> output = IntrinsicUtility.GetUninitializedVector64<byte>();
Expand Down Expand Up @@ -65,7 +65,7 @@ public static Vector64<byte> CorrectBoolean(this Vector64<byte> vector)
/// A <see cref="Vector128{T}"/> of <see langword="byte"/> which remapped back to 0 and 1 based on boolean truthiness.
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
[ExcludeFromCodeCoverage]
public static Vector128<byte> CorrectBoolean(this Vector128<byte> vector)
{
Expand All @@ -88,7 +88,7 @@ public static Vector128<byte> CorrectBoolean(this Vector128<byte> vector)
/// A <see cref="Vector256{T}"/> of <see langword="byte"/> which remapped back to 0 and 1 based on boolean truthiness.
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
[ExcludeFromCodeCoverage]
public static Vector256<byte> CorrectBoolean(this Vector256<byte> vector)
{
Expand All @@ -112,15 +112,15 @@ public static Vector256<byte> CorrectBoolean(this Vector256<byte> vector)
/// </returns>
[Pure]
[CLSCompliant(false)]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
[ExcludeFromCodeCoverage]
public static Vector128<ulong> ReverseElements(this Vector128<ulong> vector)
{
return Sse2.IsSupported ? ReverseElementsInternal_Sse2(vector) : ReverseElementsInternal_Fallback(vector);
}

[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal static Vector128<byte> CorrectBooleanInternal_Fallback(this Vector128<byte> vector)
{
Vector128<byte> output = IntrinsicUtility.GetUninitializedVector128<byte>();
Expand All @@ -135,7 +135,7 @@ internal static Vector128<byte> CorrectBooleanInternal_Fallback(this Vector128<b
}

[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal static Vector128<byte> CorrectBooleanInternal_Sse2(this Vector128<byte> vector)
{
Vector128<byte> cmp = Sse2.CompareEqual(vector, Vector128<byte>.Zero);
Expand All @@ -145,7 +145,7 @@ internal static Vector128<byte> CorrectBooleanInternal_Sse2(this Vector128<byte>
}

[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal static Vector256<byte> CorrectBooleanInternal_Fallback(this Vector256<byte> vector)
{
Vector256<byte> output = IntrinsicUtility.GetUninitializedVector256<byte>();
Expand All @@ -160,7 +160,7 @@ internal static Vector256<byte> CorrectBooleanInternal_Fallback(this Vector256<b
}

[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal static Vector256<byte> CorrectBooleanInternal_Avx2(this Vector256<byte> vector)
{
Vector256<byte> cmp = Avx2.CompareEqual(vector, Vector256<byte>.Zero);
Expand All @@ -170,7 +170,7 @@ internal static Vector256<byte> CorrectBooleanInternal_Avx2(this Vector256<byte>
}

[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal static Vector128<ulong> ReverseElementsInternal_Fallback(this Vector128<ulong> vector)
{
Vector128<ulong> output = IntrinsicUtility.GetUninitializedVector128<ulong>();
Expand All @@ -182,7 +182,7 @@ internal static Vector128<ulong> ReverseElementsInternal_Fallback(this Vector128
}

[Pure]
[MethodImpl(CompilerResources.MethodImplOptions)]
[MethodImpl(CompilerResources.MaxOptimization)]
internal static Vector128<ulong> ReverseElementsInternal_Sse2(this Vector128<ulong> vector)
{
return Sse2.Shuffle(vector.AsDouble(), vector.AsDouble(), 0b01).AsUInt64();
Expand Down
Loading

0 comments on commit fa0ece6

Please sign in to comment.