Skip to content

Commit 8355353

Browse files
Respond to additional feedback
1 parent 3627073 commit 8355353

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/ImageSharp/Common/Helpers/Vector128Utilities.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ public static Vector128<float> ShuffleNative(Vector128<float> vector, [ConstantE
8686
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8787
public static Vector128<int> ShuffleNative(Vector128<int> vector, [ConstantExpected] byte control)
8888
{
89-
if (Sse2.IsSupported)
90-
{
91-
return Sse2.Shuffle(vector, control);
92-
}
93-
9489
// Don't use InverseMMShuffle here as we want to avoid the cast.
9590
Vector128<int> indices = Vector128.Create(
9691
control & 0x3,
@@ -529,17 +524,16 @@ public static Vector128<int> MultiplyAddAdjacent(Vector128<short> left, Vector12
529524
if (AdvSimd.IsSupported)
530525
{
531526
Vector128<int> prodLo = AdvSimd.MultiplyWideningLower(left.GetLower(), right.GetLower());
532-
Vector128<int> prodHi = AdvSimd.MultiplyWideningLower(left.GetUpper(), right.GetUpper());
527+
Vector128<int> prodHi = AdvSimd.MultiplyWideningUpper(left, right);
533528

534529
if (AdvSimd.Arm64.IsSupported)
535530
{
536531
return AdvSimd.Arm64.AddPairwise(prodLo, prodHi);
537532
}
538533

539-
Vector128<long> v0 = AdvSimd.AddPairwiseWidening(prodLo);
540-
Vector128<long> v1 = AdvSimd.AddPairwiseWidening(prodHi);
541-
542-
return Vector128.Narrow(v0, v1);
534+
Vector64<int> v0 = AdvSimd.AddPairwise(prodLo.GetLower(), prodLo.GetUpper());
535+
Vector64<int> v1 = AdvSimd.AddPairwise(prodHi.GetLower(), prodHi.GetUpper());
536+
return Vector128.Create(v0, v1);
543537
}
544538

545539
{

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ public static void ITransformOne(Span<byte> reference, Span<short> input, Span<b
221221
ref byte referenceRef = ref MemoryMarshal.GetReference(reference);
222222

223223
// Load four bytes/pixels per line.
224-
Vector128<byte> ref0 = Vector128.CreateScalar(Unsafe.As<byte, int>(ref referenceRef)).AsByte();
225-
Vector128<byte> ref1 = Vector128.CreateScalar(Unsafe.As<byte, int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps))).AsByte();
226-
Vector128<byte> ref2 = Vector128.CreateScalar(Unsafe.As<byte, int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps * 2))).AsByte();
227-
Vector128<byte> ref3 = Vector128.CreateScalar(Unsafe.As<byte, int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps * 3))).AsByte();
224+
Vector128<byte> ref0 = Vector128.CreateScalar(Unsafe.ReadUnaligned<int>(ref referenceRef)).AsByte();
225+
Vector128<byte> ref1 = Vector128.CreateScalar(Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps))).AsByte();
226+
Vector128<byte> ref2 = Vector128.CreateScalar(Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps * 2))).AsByte();
227+
Vector128<byte> ref3 = Vector128.CreateScalar(Unsafe.ReadUnaligned<int>(ref Unsafe.Add(ref referenceRef, WebpConstants.Bps * 3))).AsByte();
228228

229229
// Convert to 16b.
230230
ref0 = Vector128_.UnpackLow(ref0, Vector128<byte>.Zero);
@@ -253,10 +253,10 @@ public static void ITransformOne(Span<byte> reference, Span<short> input, Span<b
253253
int output2 = ref2.AsInt32().ToScalar();
254254
int output3 = ref3.AsInt32().ToScalar();
255255

256-
Unsafe.As<byte, int>(ref outputRef) = output0;
257-
Unsafe.As<byte, int>(ref Unsafe.Add(ref outputRef, WebpConstants.Bps)) = output1;
258-
Unsafe.As<byte, int>(ref Unsafe.Add(ref outputRef, WebpConstants.Bps * 2)) = output2;
259-
Unsafe.As<byte, int>(ref Unsafe.Add(ref outputRef, WebpConstants.Bps * 3)) = output3;
256+
Unsafe.WriteUnaligned(ref outputRef, output0);
257+
Unsafe.WriteUnaligned(ref Unsafe.Add(ref outputRef, WebpConstants.Bps), output1);
258+
Unsafe.WriteUnaligned(ref Unsafe.Add(ref outputRef, WebpConstants.Bps * 2), output2);
259+
Unsafe.WriteUnaligned(ref Unsafe.Add(ref outputRef, WebpConstants.Bps * 3), output3);
260260
}
261261
else
262262
{

0 commit comments

Comments
 (0)