Skip to content

Commit d6aeba1

Browse files
committed
Switched from for-loop to if + do-while in Vp8LHistogram
1 parent a95ab17 commit d6aeba1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,14 +513,14 @@ private static void AddVector(Span<uint> a, Span<uint> b, Span<uint> output, int
513513
DebugGuard.MustBeGreaterThanOrEqualTo(b.Length, count, nameof(b.Length));
514514
DebugGuard.MustBeGreaterThanOrEqualTo(output.Length, count, nameof(output.Length));
515515

516-
if (Avx2.IsSupported)
516+
if (Avx2.IsSupported && count >= 32)
517517
{
518518
ref uint aRef = ref MemoryMarshal.GetReference(a);
519519
ref uint bRef = ref MemoryMarshal.GetReference(b);
520520
ref uint outputRef = ref MemoryMarshal.GetReference(output);
521-
nuint idx;
522521

523-
for (idx = 0; idx <= (uint)count - 32; idx += 32)
522+
nuint idx = 0;
523+
do
524524
{
525525
// Load values.
526526
Vector256<uint> a0 = Unsafe.As<uint, Vector256<uint>>(ref Unsafe.Add(ref aRef, idx));
@@ -538,7 +538,9 @@ private static void AddVector(Span<uint> a, Span<uint> b, Span<uint> output, int
538538
Unsafe.As<uint, Vector256<uint>>(ref Unsafe.Add(ref outputRef, idx + 8)) = Avx2.Add(a1, b1);
539539
Unsafe.As<uint, Vector256<uint>>(ref Unsafe.Add(ref outputRef, idx + 16)) = Avx2.Add(a2, b2);
540540
Unsafe.As<uint, Vector256<uint>>(ref Unsafe.Add(ref outputRef, idx + 24)) = Avx2.Add(a3, b3);
541+
idx += 32;
541542
}
543+
while (idx <= (uint)count - 32);
542544

543545
int i = (int)idx;
544546
for (; i < count; i++)

0 commit comments

Comments
 (0)