diff --git a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs index 7c262a30e..5b27af821 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs @@ -942,7 +942,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy FilterLoop24(v, offsetPlus4, 1, stride, 8, thresh, ithresh, hevThresh); } - public static void Mean16x4(Span input, Span dc, Span tmp) + public static void Mean16x4(Span input, Span dc) { #if SUPPORTS_RUNTIME_INTRINSICS if (Sse2.IsSupported) @@ -966,13 +966,13 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy Vector128 e0 = Sse2.Add(d0, d1); Vector128 e1 = Sse2.Add(d2, d3); Vector128 f0 = Sse2.Add(e0, e1); - ref ushort outputRef = ref MemoryMarshal.GetReference(tmp); - Unsafe.As>(ref outputRef) = f0.AsUInt16(); + Vector128 hadd = Ssse3.HorizontalAdd(f0.AsInt16(), f0.AsInt16()); + Vector64 lower = hadd.GetLower(); - dc[0] = (uint)(tmp[1] + tmp[0]); - dc[1] = (uint)(tmp[3] + tmp[2]); - dc[2] = (uint)(tmp[5] + tmp[4]); - dc[3] = (uint)(tmp[7] + tmp[6]); + dc[0] = (uint)lower.GetElement(0); + dc[1] = (uint)lower.GetElement(1); + dc[2] = (uint)lower.GetElement(2); + dc[3] = (uint)lower.GetElement(3); } else #endif diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs index 57e18832e..6279aef65 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs @@ -363,7 +363,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy uint m2; for (k = 0; k < 16; k += 4) { - LossyUtils.Mean16x4(this.YuvIn.AsSpan(YOffEnc + (k * WebpConstants.Bps)), dc.Slice(k, 4), tmp); + LossyUtils.Mean16x4(this.YuvIn.AsSpan(YOffEnc + (k * WebpConstants.Bps)), dc.Slice(k, 4)); } for (m = 0, m2 = 0, k = 0; k < 16; k++) diff --git a/tests/ImageSharp.Tests/Formats/WebP/LossyUtilsTests.cs b/tests/ImageSharp.Tests/Formats/WebP/LossyUtilsTests.cs index 16b8e1166..09727293c 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/LossyUtilsTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/LossyUtilsTests.cs @@ -25,11 +25,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP 173, 175, 166, 155, 155, 159, 159, 158 }; uint[] dc = new uint[4]; - ushort[] tmp = new ushort[8]; uint[] expectedDc = { 1940, 2139, 2252, 1813 }; // act - LossyUtils.Mean16x4(input, dc, tmp); + LossyUtils.Mean16x4(input, dc); // assert Assert.True(dc.SequenceEqual(expectedDc)); @@ -73,7 +72,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP public void Mean16x4_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunMean16x4Test, HwIntrinsics.AllowAll); [Fact] - public void Mean16x4_WithoutSSE2_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunMean16x4Test, HwIntrinsics.DisableSSE2); + public void Mean16x4_WithoutHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunMean16x4Test, HwIntrinsics.DisableHWIntrinsic); [Fact] public void HadamardTransform_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunHadamardTransformTest, HwIntrinsics.AllowAll);