From 427a39213e2e7429667d376a8b86c09b47f6da62 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 23 Nov 2021 23:11:06 +0100 Subject: [PATCH] Add VectorMismatch tests --- .../Formats/WebP/LosslessUtilsTests.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs b/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs index 97567ba218..b6f15e5376 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/LosslessUtilsTests.cs @@ -10,6 +10,24 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp [Trait("Format", "Webp")] public class LosslessUtilsTests { + private static void RunVectorMismatchTest() + { + uint[] array1 = { 4278193152, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896 }; + uint[] array2 = { 4278193152, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896, 4278192896 }; + int expected1 = 18; + + // Test unroll first two loops path also. + uint[] array3 = { 4279238656, 4278714368, 4279238656, 4279238656, 4279238656, 4279238656, 4279238896, 4279238896, 4279238884 }; + uint[] array4 = { 4279238656, 4278714368, 4279238656, 4279238656, 4278190080, 4278190080, 4278190080, 4278190080, 4278190080 }; + int expected2 = 4; + + int actual1 = LosslessUtils.VectorMismatch(array1, array2, 18); + int actual2 = LosslessUtils.VectorMismatch(array3, array4, 9); + + Assert.Equal(expected1, actual1); + Assert.Equal(expected2, actual2); + } + private static void RunSubtractGreenTest() { uint[] pixelData = @@ -193,6 +211,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp } } + [Fact] + public void VectorMismatch_Works() => RunVectorMismatchTest(); + [Fact] public void Predictor11_Works() => RunPredictor11Test(); @@ -215,6 +236,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp public void TransformColorInverse_Works() => RunTransformColorInverseTest(); #if SUPPORTS_RUNTIME_INTRINSICS + [Fact] + public void VectorMismatch_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunVectorMismatchTest, HwIntrinsics.AllowAll); + + [Fact] + public void VectorMismatch_WithoutSSE2_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunVectorMismatchTest, HwIntrinsics.DisableSSE2); + [Fact] public void Predictor11_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunPredictor11Test, HwIntrinsics.AllowAll);