<div data-ntes="ntes_mail_body_root" style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div id="spnEditorContent"><p style="margin: 0;">Hi <span style="font-family: Helvetica, "Microsoft Yahei", verdana;">Harshitha,</span></p><p style="margin: 0;"><br></p><p style="margin: 0;">Thank for the patch, inline comment.</p><p style="margin: 0;"><br></p><p style="margin: 0;">Regards,</p><p style="margin: 0;">Chen</p></div><div style="position:relative;zoom:1"></div><div id="divNeteaseMailCard"></div><p style="margin: 0;"><br></p><p>At 2024-09-13 17:37:03, "Karam Singh" <karam.singh@multicorewareinc.com> wrote:</p><blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><div dir="ltr"><div dir="ltr"><div>From e5ad11568ec5c7b5a9d624d8f9d8f5810f14f546 Mon Sep 17 00:00:00 2001</div><div>From: Harshitha Suresh <<a href="mailto:harshitha@multicorewareinc.com">harshitha@multicorewareinc.com</a>></div><div>Date: Fri, 13 Sep 2024 13:54:08 +0530</div><div>Subject: [PATCH] AArch64: Add 8bit and 10bit neon intrinsics for intraFilter</div><div> and intrapred DC</div><div><br></div><div>---</div><div> source/common/aarch64/intrapred-prim.cpp | 335 ++++++++++++++++++++++-</div><div> 1 file changed, 321 insertions(+), 14 deletions(-)</div><div><br></div><div>diff --git a/source/common/aarch64/intrapred-prim.cpp b/source/common/aarch64/intrapred-prim.cpp</div><div>index 8624dd2a6..68a9f26ac 100644</div><div>--- a/source/common/aarch64/intrapred-prim.cpp</div><div>+++ b/source/common/aarch64/intrapred-prim.cpp</div><div>@@ -2,7 +2,7 @@</div><div> #include "primitives.h"</div><div> </div><div> </div><div>-#if 1</div><div>+#if HAVE_NEON</div><div> #include "arm64-utils.h"</div><div> #include <arm_neon.h></div><div> </div><div>@@ -12,6 +12,52 @@ namespace</div><div> {</div><div> </div><div> </div><div>+template<int tuSize></div><div>+void intraFilter_neon(const pixel* samples, pixel* filtered) /* 1:2:1 filtering of left and top reference samples */</div><div>+{</div><div>+    const int tuSize2 = tuSize << 1;</div><div>+    pixel topLeft = samples[0], topLast = samples[tuSize2], leftLast = samples[tuSize2 + tuSize2];</div><div>+</div><div>+    uint16x8_t two_vec = vdupq_n_u16(2);</div><div>+#if !HIGH_BIT_DEPTH</div><div>+    {</div><div>+        for(int i = 0; i < tuSize2 + tuSize2; i+=8)</div><div>+         {</div><div>+            uint16x8_t sample1 = vmovl_u8(vld1_u8(&samples[i]));</div><div>+            uint16x8_t sample2 = vmovl_u8(vld1_u8(&samples[i-1]));</div><div>+            uint16x8_t sample3 = vmovl_u8(vld1_u8(&samples[i+1]));</div><div>+</div><div>+            uint16x8_t result1 = vaddq_u16(vshlq_n_u16(sample1,1), sample2 );</div><div>MC: ADDL, SHLL, MULL may reduce vmovl</div><div><br></div><div>+            uint16x8_t result2 = vaddq_u16(sample3, two_vec);</div><div>+            uint16x8_t result3 = vaddq_u16(result1,result2);</div><div>+            vst1_u8(&filtered[i] , vmovn_u16(vshrq_n_u16(result3, 2)));</div><div>MC: VQSHRN, VQSHRUN may reduce '+2' and 'vmovn'</div><div><br></div><div>+        }</div><div>+    }</div><div>+#else</div><div>+    {</div><div>+        for(int i = 0; i < tuSize2 + tuSize2; i+=8)</div><div>+        {</div><div>+            uint16x8_t sample1 = vld1q_u16(&samples[i]);</div><div>+            uint16x8_t sample2 = vld1q_u16(&samples[i-1]);</div><div>+            uint16x8_t sample3 = vld1q_u16(&samples[i+1]);</div><div>+</div><div>+            uint16x8_t result1 = vaddq_u16(vshlq_n_u16(sample1,1), sample2 );</div><div>+            uint16x8_t result2 = vaddq_u16(sample3, two_vec);</div><div>+            uint16x8_t result3 = vaddq_u16(result1,result2);</div><div>+            vst1q_u16(&filtered[i] , vshrq_n_u16(result3, 2));</div><div>MC: vrshrq_n_u16  may reduce '+2'</div><div><br></div><div>+        }</div><div>+    }</div><div>+#endif</div><div>+    // filtering top</div><div>+    filtered[tuSize2] = topLast;</div><div>+</div><div>+    // filtering top-left</div><div>+    filtered[0] = ((topLeft << 1) + samples[1] + samples[tuSize2 + 1] + 2) >> 2;</div><div>+</div><div>+    // filtering left</div><div>+    filtered[tuSize2 + 1] = ((samples[tuSize2 + 1] << 1) + topLeft + samples[tuSize2 + 2] + 2) >> 2;</div><div>+    filtered[tuSize2 + tuSize2] = leftLast;</div><div>+}</div><div> </div><div> template<int width></div><div> void intra_pred_ang_neon(pixel *dst, intptr_t dstStride, const pixel *srcPix0, int dirMode, int bFilter)</div><div>@@ -188,6 +234,7 @@ void intra_pred_ang_neon(pixel *dst, intptr_t dstStride, const pixel *srcPix0, i</div><div>     }</div><div> }</div><div> </div><div>+#endif</div><div> template<int log2Size></div><div> void all_angs_pred_neon(pixel *dest, pixel *refPix, pixel *filtPix, int bLuma)</div><div> {</div><div>@@ -232,6 +279,270 @@ void all_angs_pred_neon(pixel *dest, pixel *refPix, pixel *filtPix, int bLuma)</div><div>         }</div><div>     }</div><div> }</div><div>+</div><div>+template<int log2Size></div><div>+void planar_pred_neon(pixel * dst, intptr_t dstStride, const pixel * srcPix, int /*dirMode*/, int /*bFilter*/)</div><div>MC: we have assembly version for reference, this function need change algorithm to get more performance</div><div><br></div><div>+{</div><div>+    const int blkSize = 1 << log2Size;</div><div>+</div><div>+    const pixel* above = srcPix + 1;</div><div>+    const pixel* left = srcPix + (2 * blkSize + 1);</div><div>+</div><div>+    switch (blkSize) {</div><div>+    case 8:</div><div>+    {</div><div>+        const uint16_t log2SizePlusOne = log2Size + 1;</div><div>+        uint16x8_t blkSizeVec = vdupq_n_u16(blkSize);</div><div>+        uint16x8_t topRight = vdupq_n_u16(above[blkSize]);</div><div>+        uint16_t bottomLeft = left[blkSize];</div><div>+        uint16x8_t oneVec = vdupq_n_u16(1);</div><div>+        uint16x8_t blkSizeSubOneVec = vdupq_n_u16(blkSize - 1);</div><div>+</div><div>+        for (int y = 0; y < blkSize; y++) {</div><div>+            // (blkSize - 1 - y)</div><div>+            uint16x8_t vlkSizeYVec = vdupq_n_u16(blkSize - 1 - y);</div><div>+            // (y + 1) * bottomLeft</div><div>+            uint16x8_t bottomLeftYVec = vdupq_n_u16((y + 1) * bottomLeft);</div><div>+            // left[y]</div><div>+            uint16x8_t leftYVec = vdupq_n_u16(left[y]);</div><div>+</div><div>+            for (int x = 0; x < blkSize; x += 8) {</div><div>+                int idx = y * dstStride + x;</div><div>+                uint16x8_t xvec = { (uint16_t)(x + 0), (uint16_t)(x + 1),</div><div>+                                    (uint16_t)(x + 2), (uint16_t)(x + 3),</div><div>+                                    (uint16_t)(x + 4), (uint16_t)(x + 5),</div><div>+                                    (uint16_t)(x + 6), (uint16_t)(x + 7) };</div><div>MC: above style is very slow and not compatible with different compiler</div><div><br></div><div>+</div><div>+                // (blkSize - 1 - y) * above[x]</div><div>+                uint16x8_t aboveVec = { (uint16_t)(above[x + 0]),</div><div>+                                        (uint16_t)(above[x + 1]),</div><div>+                                        (uint16_t)(above[x + 2]),</div><div>+                                        (uint16_t)(above[x + 3]),</div><div>+                                        (uint16_t)(above[x + 4]),</div><div>+                                        (uint16_t)(above[x + 5]),</div><div>+                                        (uint16_t)(above[x + 6]),</div><div>+                                        (uint16_t)(above[x + 7]) };</div><div>+</div><div>+                aboveVec = vmulq_u16(aboveVec, vlkSizeYVec);</div><div>+</div><div>+                // (blkSize - 1 - x) * left[y]</div><div>+                uint16x8_t first = vsubq_u16(blkSizeSubOneVec, xvec);</div><div>+                first = vmulq_u16(first, leftYVec);</div><div>+</div><div>+                // (x + 1) * topRight</div><div>+                uint16x8_t second = vaddq_u16(xvec, oneVec);</div><div>+                second = vmulq_u16(second, topRight);</div><div>+</div><div>+                uint16x8_t resVec = vaddq_u16(first, second);</div><div>+                resVec = vaddq_u16(resVec, aboveVec);</div><div>+                resVec = vaddq_u16(resVec, bottomLeftYVec);</div><div>+                resVec = vaddq_u16(resVec, blkSizeVec);</div><div>+                resVec = vshrq_n_u16(resVec, log2SizePlusOne);</div><div>+</div><div>+                for (int i = 0; i < 8; i++)</div><div>+                    dst[idx + i] = (pixel)resVec[i];</div><div>+    }</div><div>+}</div><div>+        }</div><div>+    break;</div><div>+    case 4:</div><div>+    case 32:</div><div>+    case 16:</div><div>+    {</div><div>+        const uint32_t log2SizePlusOne = log2Size + 1;</div><div>+        uint32x4_t blkSizeVec = vdupq_n_u32(blkSize);</div><div>+        uint32x4_t topRight = vdupq_n_u32(above[blkSize]);</div><div>+        uint32_t bottomLeft = left[blkSize];</div><div>+        uint32x4_t oneVec = vdupq_n_u32(1);</div><div>+        uint32x4_t blkSizeSubOneVec = vdupq_n_u32(blkSize - 1);</div><div>+</div><div>+        for (int y = 0; y < blkSize; y++) {</div><div>+            // (blkSize - 1 - y)</div><div>+            uint32x4_t vlkSizeYVec = vdupq_n_u32(blkSize - 1 - y);</div><div>+            // (y + 1) * bottomLeft</div><div>+            uint32x4_t bottomLeftYVec = vdupq_n_u32((y + 1) * bottomLeft);</div><div>MC: We are not need Multiplier every loop iteration, it may replace by adder</div><div><br></div><div>+            // left[y]</div><div>+            uint32x4_t leftYVec = vdupq_n_u32(left[y]);</div><div>+</div><div>+            for (int x = 0; x < blkSize; x += 4) {</div><div>MC: not good parallel performance if processing based on 4-pixel</div><div><br></div><div>+                int idx = y * dstStride + x;</div><div>+                uint32x4_t xvec = { (uint32_t)(x + 0), (uint32_t)(x + 1),</div><div>+                                    (uint32_t)(x + 2), (uint32_t)(x + 3) };</div><div>+</div><div>+                // (blkSize - 1 - y) * above[x]</div><div>+                uint32x4_t aboveVec = { (uint32_t)(above[x + 0]),</div><div>+                                        (uint32_t)(above[x + 1]),</div><div>+                                        (uint32_t)(above[x + 2]),</div><div>+                                        (uint32_t)(above[x + 3]) };</div><div>+                aboveVec = vmulq_u32(aboveVec, vlkSizeYVec);</div><div>+</div><div>+                // (blkSize - 1 - x) * left[y]</div><div>+                uint32x4_t first = vsubq_u32(blkSizeSubOneVec, xvec);</div><div>+                first = vmulq_u32(first, leftYVec);</div><div>+</div><div>+                // (x + 1) * topRight</div><div>+                uint32x4_t second = vaddq_u32(xvec, oneVec);</div><div>+                second = vmulq_u32(second, topRight);</div><div>+</div><div>+                uint32x4_t resVec = vaddq_u32(first, second);</div><div>+                resVec = vaddq_u32(resVec, aboveVec);</div><div>+                resVec = vaddq_u32(resVec, bottomLeftYVec);</div><div>+                resVec = vaddq_u32(resVec, blkSizeVec);</div><div>+                resVec = vshrq_n_u32(resVec, log2SizePlusOne);</div><div>+</div><div>+                for (int i = 0; i < 4; i++)</div><div>+                    dst[idx + i] = (pixel)resVec[i];</div><div>MC: Why not store through Vector unit? and the result is 32-bits, dst[] is pixel, need saturation</div><div><br></div><div>+            }</div><div>+        }</div><div>+    }</div><div>+    break;</div><div>+        }</div><div>+}</div><div>+</div><div>+static void dcPredFilter(const pixel* above, const pixel* left, pixel* dst, intptr_t dststride, int size)</div><div>+{</div><div>+    // boundary pixels processing</div><div>+    pixel topLeft = (pixel)((above[0] + left[0] + 2 * dst[0] + 2) >> 2);</div><div>+    pixel * pdst = dst;</div><div>+</div><div>+    switch (size) {</div><div>+    case 32:</div><div>+    case 16:</div><div>+    case 8:</div><div>+    {</div><div>+        uint16x8_t vconst_3 = vdupq_n_u16(3);</div><div>+        uint16x8_t vconst_2 = vdupq_n_u16(2);</div><div>+        for (int x = 0; x < size; x += 8) {</div><div>+            uint16x8_t vabo = { (uint16_t)(above[x + 0]),</div><div>+                                (uint16_t)(above[x + 1]),</div><div>+                                (uint16_t)(above[x + 2]),</div><div>+                                (uint16_t)(above[x + 3]),</div><div>+                                (uint16_t)(above[x + 4]),</div><div>+                                (uint16_t)(above[x + 5]),</div><div>+                                (uint16_t)(above[x + 6]),</div><div>+                                (uint16_t)(above[x + 7]) };</div><div>+</div><div>+            uint16x8_t vdst = { (uint16_t)(dst[x + 0]),</div><div>+                                (uint16_t)(dst[x + 1]),</div><div>+                                (uint16_t)(dst[x + 2]),</div><div>+                                (uint16_t)(dst[x + 3]),</div><div>+                                (uint16_t)(dst[x + 4]),</div><div>+                                (uint16_t)(dst[x + 5]),</div><div>+                                (uint16_t)(dst[x + 6]),</div><div>+                                (uint16_t)(dst[x + 7]) };</div><div>+            //  dst[x] = (pixel)((above[x] +  3 * dst[x] + 2) >> 2);</div><div>+            vdst = vmulq_u16(vdst, vconst_3);</div><div>+            vdst = vaddq_u16(vdst, vabo);</div><div>+            vdst = vaddq_u16(vdst, vconst_2);</div><div>+            vdst = vshrq_n_u16(vdst, 2);</div><div>MC: uqrshrun</div><div>...</div><div> </div><div> </div><div>-- </div><div>2.36.0.windows.1</div><div><br></div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><b>__________________________</b></div><div><b>Karam Singh</b></div><div><b>Ph.D. IIT Guwahati</b></div><div><font size="1">Senior Software (Video Coding) Engineer  </font></div><div><font size="1">Mobile: +91 8011279030</font></div><div><font size="1">Block 9A, 6th floor, DLF Cyber City</font></div><div><font size="1">Manapakkam, Chennai 600 089</font></div></div></div></div></div></div>
</blockquote></div>