Skip to content

Commit

Permalink
Fix source validator's code reports, remove 95% of AdvSimd implementa…
Browse files Browse the repository at this point in the history
…tion to prevent future consequences
  • Loading branch information
RealityProgrammer committed Mar 14, 2023
1 parent ec8e60c commit 8b8aeb3
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 122 deletions.
2 changes: 1 addition & 1 deletion X10D/src/Collections/BoolListExtensions.cs
Expand Up @@ -26,7 +26,7 @@ public static byte PackByte(this IReadOnlyList<bool> source)
throw new ArgumentNullException(nameof(source));
}
#endif

if (source.Count > 8)
{
throw new ArgumentException("Source cannot contain more than than 8 elements.", nameof(source));
Expand Down
2 changes: 1 addition & 1 deletion X10D/src/Collections/ByteExtensions.cs
Expand Up @@ -47,7 +47,7 @@ public static void Unpack(this byte value, Span<bool> destination)
return;
}
#endif

FallbackImplementation(value, destination);

#if NETCOREAPP3_0_OR_GREATER
Expand Down
20 changes: 10 additions & 10 deletions X10D/src/Collections/Int32Extensions.cs
Expand Up @@ -42,7 +42,7 @@ public static void Unpack(this int value, Span<bool> destination)

#if NETCOREAPP3_0_OR_GREATER
// TODO: AdvSimd support.

// https://stackoverflow.com/questions/24225786/fastest-way-to-unpack-32-bits-to-a-32-byte-simd-vector
if (Avx2.IsSupported)
{
Expand All @@ -64,15 +64,15 @@ unsafe static void Avx2Implementation(int value, Span<bool> destination)
fixed (bool* pDestination = destination)
{
var mask1 = Vector256.Create(
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03
).AsByte();
var mask2 = Vector256.Create(
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
);

Expand All @@ -81,7 +81,7 @@ unsafe static void Avx2Implementation(int value, Span<bool> destination)
var and = Avx2.AndNot(shuffle, mask2);
var cmp = Avx2.CompareEqual(and, Vector256<byte>.Zero);
var correctness = Avx2.And(cmp, Vector256.Create((byte)0x01));

Avx.Store((byte*)pDestination, correctness);
}
}
Expand All @@ -103,9 +103,9 @@ unsafe static void Ssse3Implementation(int value, Span<bool> destination)
var and = Sse2.AndNot(shuffle, mask2);
var cmp = Sse2.CompareEqual(and, Vector128<byte>.Zero);
var correctness = Sse2.And(cmp, one);

Sse2.Store((byte*)pDestination, correctness);

shuffle = Ssse3.Shuffle(vec, mask1Hi);
and = Sse2.AndNot(shuffle, mask2);
cmp = Sse2.CompareEqual(and, Vector128<byte>.Zero);
Expand Down
3 changes: 2 additions & 1 deletion X10D/src/Core/IntrinsicExtensions.cs
Expand Up @@ -5,7 +5,8 @@
namespace X10D.Core;

/// <summary>
/// Extension methods for SIMD vectors, namely <see cref="Vector64{T}"/>, <see cref="Vector128{T}"/> and <see cref="Vector256{T}"/>.
/// Extension methods for SIMD vectors, namely <see cref="Vector64{T}"/>, <see cref="Vector128{T}"/> and
/// <see cref="Vector256{T}"/>.
/// </summary>
public static class IntrinsicExtensions
{
Expand Down

0 comments on commit 8b8aeb3

Please sign in to comment.