From 169e98bbcd15c42424f710b557a1471a88c150a5 Mon Sep 17 00:00:00 2001 From: Dmitry Pentin Date: Fri, 28 May 2021 11:47:16 +0300 Subject: [PATCH] Simplified Block8x8F.DivideRoundAll() method --- .../Formats/Jpeg/Components/Block8x8F.cs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs index 340d8e5c57..0acc6408e2 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs @@ -68,6 +68,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components public Vector4 V7R; #if SUPPORTS_RUNTIME_INTRINSICS + /// + /// A number of rows of 8 scalar coefficients each in + /// + public const int RowCount = 8; + [FieldOffset(0)] public Vector256 V0; [FieldOffset(32)] @@ -557,19 +562,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components var vadd = Vector256.Create(.5F); var vone = Vector256.Create(1f); - ref Vector256 aBase = ref a.V0; - ref Vector256 bBase = ref b.V0; - ref Vector256 aEnd = ref Unsafe.Add(ref aBase, 8); - - do + for (int i = 0; i < RowCount; i++) { - Vector256 voff = Avx.Multiply(Avx.Min(Avx.Max(vnegOne, aBase), vone), vadd); - Unsafe.Add(ref aBase, 0) = Avx.Add(Avx.Divide(aBase, bBase), voff); - - aBase = ref Unsafe.Add(ref aBase, 1); - bBase = ref Unsafe.Add(ref bBase, 1); + ref Vector256 aRow = ref Unsafe.Add(ref a.V0, i); + ref Vector256 bRow = ref Unsafe.Add(ref b.V0, i); + Vector256 voff = Avx.Multiply(Avx.Min(Avx.Max(vnegOne, aRow), vone), vadd); + aRow = Avx.Add(Avx.Divide(aRow, bRow), voff); } - while (Unsafe.IsAddressLessThan(ref aBase, ref aEnd)); } else #endif