Browse Source

Add Arm for MultiplyToAverage

pull/2429/head
Stefan Nikolei 3 years ago
parent
commit
c19095153e
  1. 15
      src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs

15
src/ImageSharp/Formats/Jpeg/Components/Encoder/ComponentProcessor.cs

@ -5,6 +5,7 @@ using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Intrinsics; using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.X86;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
@ -201,12 +202,24 @@ internal class ComponentProcessor : IDisposable
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed // Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
nuint count = target.Vector256Count<float>(); nuint count = target.Vector256Count<float>();
var multiplierVector = Vector256.Create(multiplier); Vector256<float> multiplierVector = Vector256.Create(multiplier);
for (nuint i = 0; i < count; i++) for (nuint i = 0; i < count; i++)
{ {
Unsafe.Add(ref targetVectorRef, i) = Avx.Multiply(Unsafe.Add(ref targetVectorRef, i), multiplierVector); Unsafe.Add(ref targetVectorRef, i) = Avx.Multiply(Unsafe.Add(ref targetVectorRef, i), multiplierVector);
} }
} }
else if (AdvSimd.IsSupported)
{
ref Vector128<float> targetVectorRef = ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(target));
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
nuint count = target.Vector128Count<float>();
Vector128<float> multiplierVector = Vector128.Create(multiplier);
for (nuint i = 0; i < count; i++)
{
Unsafe.Add(ref targetVectorRef, i) = AdvSimd.Multiply(Unsafe.Add(ref targetVectorRef, i), multiplierVector);
}
}
else else
{ {
ref Vector<float> targetVectorRef = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(target)); ref Vector<float> targetVectorRef = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(target));

Loading…
Cancel
Save