Skip to content

Commit c190951

Browse files
committed
Add Arm for MultiplyToAverage
1 parent 3cafdcb commit c190951

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Runtime.CompilerServices;
66
using System.Runtime.InteropServices;
77
using System.Runtime.Intrinsics;
8+
using System.Runtime.Intrinsics.Arm;
89
using System.Runtime.Intrinsics.X86;
910
using SixLabors.ImageSharp.Memory;
1011

@@ -201,12 +202,24 @@ static void MultiplyToAverage(Span<float> target, float multiplier)
201202

202203
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
203204
nuint count = target.Vector256Count<float>();
204-
var multiplierVector = Vector256.Create(multiplier);
205+
Vector256<float> multiplierVector = Vector256.Create(multiplier);
205206
for (nuint i = 0; i < count; i++)
206207
{
207208
Unsafe.Add(ref targetVectorRef, i) = Avx.Multiply(Unsafe.Add(ref targetVectorRef, i), multiplierVector);
208209
}
209210
}
211+
else if (AdvSimd.IsSupported)
212+
{
213+
ref Vector128<float> targetVectorRef = ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(target));
214+
215+
// Spans are guaranteed to be multiple of 8 so no extra 'remainder' steps are needed
216+
nuint count = target.Vector128Count<float>();
217+
Vector128<float> multiplierVector = Vector128.Create(multiplier);
218+
for (nuint i = 0; i < count; i++)
219+
{
220+
Unsafe.Add(ref targetVectorRef, i) = AdvSimd.Multiply(Unsafe.Add(ref targetVectorRef, i), multiplierVector);
221+
}
222+
}
210223
else
211224
{
212225
ref Vector<float> targetVectorRef = ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(target));

0 commit comments

Comments
 (0)