diff --git a/src/ImageSharp/Common/Extensions/SimdUtils.cs b/src/ImageSharp/Common/Extensions/SimdUtils.cs
index cb80a672a..d6b2fad09 100644
--- a/src/ImageSharp/Common/Extensions/SimdUtils.cs
+++ b/src/ImageSharp/Common/Extensions/SimdUtils.cs
@@ -17,11 +17,11 @@ namespace SixLabors.ImageSharp
///
/// Indicates AVX2 architecture where both float and integer registers are of size 256 byte.
///
- public static readonly bool IsAvx2 = Vector.Count == 8 && Vector.Count == 8;
+ public static readonly bool IsAvx2CompatibleArchitecture = Vector.Count == 8 && Vector.Count == 8;
internal static void GuardAvx2(string operation)
{
- if (!IsAvx2)
+ if (!IsAvx2CompatibleArchitecture)
{
throw new NotSupportedException($"{operation} is supported only on AVX2 CPU!");
}
diff --git a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
index 6f4f93d87..552ac0a01 100644
--- a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
+++ b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
@@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp
{
GuardSpans(sourceVectors, nameof(sourceVectors), destColors, nameof(destColors), count);
- if (!SimdUtils.IsAvx2)
+ if (!SimdUtils.IsAvx2CompatibleArchitecture)
{
base.PackFromVector4(sourceVectors, destColors, count);
return;
diff --git a/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs b/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs
index 44762a243..e5f2fd5e7 100644
--- a/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs
+++ b/tests/ImageSharp.Tests/Common/SimdUtilsTests.cs
@@ -109,6 +109,16 @@ namespace SixLabors.ImageSharp.Tests.Common
AssertEvenRoundIsCorrect(r, v);
}
+ private bool SkipOnNonAvx2([CallerMemberName] string testCaseName = null)
+ {
+ if (!SimdUtils.IsAvx2CompatibleArchitecture)
+ {
+ this.Output.WriteLine("Skipping AVX2 specific test case: " + testCaseName);
+ return true;
+ }
+ return false;
+ }
+
[Theory]
[InlineData(1, 0)]
[InlineData(1, 8)]
@@ -116,6 +126,11 @@ namespace SixLabors.ImageSharp.Tests.Common
[InlineData(3, 128)]
public void BulkConvertNormalizedFloatToByte_WithRoundedData(int seed, int count)
{
+ if (this.SkipOnNonAvx2())
+ {
+ return;
+ }
+
float[] orig = new Random(seed).GenerateRandomRoundedFloatArray(count, 0, 256);
float[] normalized = orig.Select(f => f / 255f).ToArray();
@@ -135,6 +150,11 @@ namespace SixLabors.ImageSharp.Tests.Common
[InlineData(3, 128)]
public void BulkConvertNormalizedFloatToByte_WithNonRoundedData(int seed, int count)
{
+ if (this.SkipOnNonAvx2())
+ {
+ return;
+ }
+
float[] source = new Random(seed).GenerateRandomFloatArray(count, 0, 1f);
byte[] dest = new byte[count];
@@ -155,6 +175,11 @@ namespace SixLabors.ImageSharp.Tests.Common
[InlineData(3, 128)]
public void BulkConvertNormalizedFloatToByteClampOverflows(int seed, int count)
{
+ if (this.SkipOnNonAvx2())
+ {
+ return;
+ }
+
float[] orig = new Random(seed).GenerateRandomRoundedFloatArray(count, -50, 444);
float[] normalized = orig.Select(f => f / 255f).ToArray();
@@ -185,6 +210,11 @@ namespace SixLabors.ImageSharp.Tests.Common
[Fact]
private void BulkConvertNormalizedFloatToByte_Step()
{
+ if (this.SkipOnNonAvx2())
+ {
+ return;
+ }
+
float[] source = {0, 7, 42, 255, 0.5f, 1.1f, 2.6f, 16f};
byte[] expected = source.Select(f => (byte)Math.Round(f)).ToArray();