Browse Source

Use Ssse3.HorizontalAdd

pull/1814/head
Brian Popow 4 years ago
parent
commit
3cfa040b20
  1. 14
      src/ImageSharp/Formats/Webp/Lossy/LossyUtils.cs
  2. 2
      src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs
  3. 5
      tests/ImageSharp.Tests/Formats/WebP/LossyUtilsTests.cs

14
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<byte> input, Span<uint> dc, Span<ushort> tmp)
public static void Mean16x4(Span<byte> input, Span<uint> dc)
{
#if SUPPORTS_RUNTIME_INTRINSICS
if (Sse2.IsSupported)
@ -966,13 +966,13 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
Vector128<int> e0 = Sse2.Add(d0, d1);
Vector128<int> e1 = Sse2.Add(d2, d3);
Vector128<int> f0 = Sse2.Add(e0, e1);
ref ushort outputRef = ref MemoryMarshal.GetReference(tmp);
Unsafe.As<ushort, Vector128<ushort>>(ref outputRef) = f0.AsUInt16();
Vector128<short> hadd = Ssse3.HorizontalAdd(f0.AsInt16(), f0.AsInt16());
Vector64<short> 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

2
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++)

5
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);

Loading…
Cancel
Save