Browse Source

unrelated to PR: Skipping AVX2-tests if the CPU does not support AVX2

pull/329/head
Anton Firszov 9 years ago
parent
commit
63fa1fdbe1
  1. 4
      src/ImageSharp/Common/Extensions/SimdUtils.cs
  2. 2
      src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
  3. 30
      tests/ImageSharp.Tests/Common/SimdUtilsTests.cs

4
src/ImageSharp/Common/Extensions/SimdUtils.cs

@ -17,11 +17,11 @@ namespace SixLabors.ImageSharp
/// <summary>
/// Indicates AVX2 architecture where both float and integer registers are of size 256 byte.
/// </summary>
public static readonly bool IsAvx2 = Vector<float>.Count == 8 && Vector<int>.Count == 8;
public static readonly bool IsAvx2CompatibleArchitecture = Vector<float>.Count == 8 && Vector<int>.Count == 8;
internal static void GuardAvx2(string operation)
{
if (!IsAvx2)
if (!IsAvx2CompatibleArchitecture)
{
throw new NotSupportedException($"{operation} is supported only on AVX2 CPU!");
}

2
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;

30
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();

Loading…
Cancel
Save