Browse Source

Respond to additional feedback

pull/2933/head
James Jackson-South 11 months ago
parent
commit
8355353985
  1. 14
      src/ImageSharp/Common/Helpers/Vector128Utilities.cs
  2. 16
      src/ImageSharp/Formats/Webp/Lossy/Vp8Encoding.cs

14
src/ImageSharp/Common/Helpers/Vector128Utilities.cs

@ -86,11 +86,6 @@ internal static class Vector128_
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector128<int> ShuffleNative(Vector128<int> vector, [ConstantExpected] byte control) public static Vector128<int> ShuffleNative(Vector128<int> vector, [ConstantExpected] byte control)
{ {
if (Sse2.IsSupported)
{
return Sse2.Shuffle(vector, control);
}
// Don't use InverseMMShuffle here as we want to avoid the cast. // Don't use InverseMMShuffle here as we want to avoid the cast.
Vector128<int> indices = Vector128.Create( Vector128<int> indices = Vector128.Create(
control & 0x3, control & 0x3,
@ -529,17 +524,16 @@ internal static class Vector128_
if (AdvSimd.IsSupported) if (AdvSimd.IsSupported)
{ {
Vector128<int> prodLo = AdvSimd.MultiplyWideningLower(left.GetLower(), right.GetLower()); Vector128<int> prodLo = AdvSimd.MultiplyWideningLower(left.GetLower(), right.GetLower());
Vector128<int> prodHi = AdvSimd.MultiplyWideningLower(left.GetUpper(), right.GetUpper()); Vector128<int> prodHi = AdvSimd.MultiplyWideningUpper(left, right);
if (AdvSimd.Arm64.IsSupported) if (AdvSimd.Arm64.IsSupported)
{ {
return AdvSimd.Arm64.AddPairwise(prodLo, prodHi); return AdvSimd.Arm64.AddPairwise(prodLo, prodHi);
} }
Vector128<long> v0 = AdvSimd.AddPairwiseWidening(prodLo); Vector64<int> v0 = AdvSimd.AddPairwise(prodLo.GetLower(), prodLo.GetUpper());
Vector128<long> v1 = AdvSimd.AddPairwiseWidening(prodHi); Vector64<int> v1 = AdvSimd.AddPairwise(prodHi.GetLower(), prodHi.GetUpper());
return Vector128.Create(v0, v1);
return Vector128.Narrow(v0, v1);
} }
{ {

16
src/ImageSharp/Formats/Webp/Lossy/Vp8Encoding.cs

@ -221,10 +221,10 @@ internal static unsafe class Vp8Encoding
ref byte referenceRef = ref MemoryMarshal.GetReference(reference); ref byte referenceRef = ref MemoryMarshal.GetReference(reference);
// Load four bytes/pixels per line. // Load four bytes/pixels per line.
Vector128<byte> ref0 = Vector128.CreateScalar(Unsafe.As<byte, int>(ref referenceRef)).AsByte(); Vector128<byte> ref0 = Vector128.CreateScalar(Unsafe.ReadUnaligned<int>(ref referenceRef)).AsByte();
Vector128<byte> ref1 = Vector128.CreateScalar(Unsafe.As<byte, int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps))).AsByte(); Vector128<byte> ref1 = Vector128.CreateScalar(Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps))).AsByte();
Vector128<byte> ref2 = Vector128.CreateScalar(Unsafe.As<byte, int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps * 2))).AsByte(); Vector128<byte> ref2 = Vector128.CreateScalar(Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps * 2))).AsByte();
Vector128<byte> ref3 = Vector128.CreateScalar(Unsafe.As<byte, int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps * 3))).AsByte(); Vector128<byte> ref3 = Vector128.CreateScalar(Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps * 3))).AsByte();
// Convert to 16b. // Convert to 16b.
ref0 = Vector128_.UnpackLow(ref0, Vector128<byte>.Zero); ref0 = Vector128_.UnpackLow(ref0, Vector128<byte>.Zero);
@ -253,10 +253,10 @@ internal static unsafe class Vp8Encoding
int output2 = ref2.AsInt32().ToScalar(); int output2 = ref2.AsInt32().ToScalar();
int output3 = ref3.AsInt32().ToScalar(); int output3 = ref3.AsInt32().ToScalar();
Unsafe.As<byte, int>(ref outputRef) = output0; Unsafe.WriteUnaligned(ref outputRef, output0);
Unsafe.As<byte, int>(ref Unsafe.Add(ref outputRef, WebpConstants.Bps)) = output1; Unsafe.WriteUnaligned(ref Unsafe.Add(ref outputRef, WebpConstants.Bps), output1);
Unsafe.As<byte, int>(ref Unsafe.Add(ref outputRef, WebpConstants.Bps * 2)) = output2; Unsafe.WriteUnaligned(ref Unsafe.Add(ref outputRef, WebpConstants.Bps * 2), output2);
Unsafe.As<byte, int>(ref Unsafe.Add(ref outputRef, WebpConstants.Bps * 3)) = output3; Unsafe.WriteUnaligned(ref Unsafe.Add(ref outputRef, WebpConstants.Bps * 3), output3);
} }
else else
{ {

Loading…
Cancel
Save