[FFmpeg-cvslog] aarch64/hevcdsp_idct_neon: Optimize idct dc

Zhao Zhili git at videolan.org
Tue Mar 4 11:03:12 EET 2025


ffmpeg | branch: master | Zhao Zhili <zhilizhao at tencent.com> | Thu Feb 20 00:50:23 2025 +0800| [5977bff569b1e1feecf681059472f4106c1573cb] | committer: Zhao Zhili

aarch64/hevcdsp_idct_neon: Optimize idct dc

clang does better than the assembly code before the patch, especially
for small size:

hevc_idct_4x4_dc_8_c:                                   11.2 ( 1.00x)
hevc_idct_4x4_dc_8_neon:                                15.5 ( 0.73x)
hevc_idct_4x4_dc_10_c:                                  12.0 ( 1.00x)
hevc_idct_4x4_dc_10_neon:                               15.2 ( 0.79x)
hevc_idct_8x8_dc_8_c:                                   13.2 ( 1.00x)
hevc_idct_8x8_dc_8_neon:                                18.2 ( 0.73x)
hevc_idct_8x8_dc_10_c:                                  13.5 ( 1.00x)
hevc_idct_8x8_dc_10_neon:                               17.2 ( 0.78x)
hevc_idct_16x16_dc_8_c:                                 41.8 ( 1.00x)
hevc_idct_16x16_dc_8_neon:                              37.8 ( 1.11x)
hevc_idct_16x16_dc_10_c:                                41.8 ( 1.00x)
hevc_idct_16x16_dc_10_neon:                             37.8 ( 1.11x)
hevc_idct_32x32_dc_8_c:                                130.2 ( 1.00x)
hevc_idct_32x32_dc_8_neon:                             132.2 ( 0.98x)
hevc_idct_32x32_dc_10_c:                               130.2 ( 1.00x)
hevc_idct_32x32_dc_10_neon:                            132.2 ( 0.98x)

This patch basically clone what the compiler does, so the performance
is the same.

Reviewed-by: Martin Storsjö <martin at martin.st>
Signed-off-by: Zhao Zhili <zhilizhao at tencent.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5977bff569b1e1feecf681059472f4106c1573cb
---

 libavcodec/aarch64/hevcdsp_idct_neon.S | 59 ++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/libavcodec/aarch64/hevcdsp_idct_neon.S b/libavcodec/aarch64/hevcdsp_idct_neon.S
index 3cac6e6db9..2337ed8ba3 100644
--- a/libavcodec/aarch64/hevcdsp_idct_neon.S
+++ b/libavcodec/aarch64/hevcdsp_idct_neon.S
@@ -888,38 +888,41 @@ function ff_hevc_transform_luma_4x4_neon_8, export=1
         ret
 endfunc
 
+.macro idct_8x8_dc_store offset
+.irp    i, 0x0, 0x20, 0x40, 0x60
+        stp             q0, q0, [x0, #(\offset + \i)]
+.endr
+.endm
+
+.macro idct_16x16_dc_store
+.irp    index, 0x0, 0x80, 0x100, 0x180
+        idct_8x8_dc_store offset=\index
+.endr
+.endm
+
 // void ff_hevc_idct_NxN_dc_DEPTH_neon(int16_t *coeffs)
 .macro idct_dc size, bitdepth
 function ff_hevc_idct_\size\()x\size\()_dc_\bitdepth\()_neon, export=1
-        ld1r            {v4.8h}, [x0]
-        srshr           v4.8h,  v4.8h,  #1
-        srshr           v0.8h,  v4.8h,  #(14 - \bitdepth)
-        srshr           v1.8h,  v4.8h,  #(14 - \bitdepth)
-.if \size > 4
-        srshr           v2.8h,  v4.8h,  #(14 - \bitdepth)
-        srshr           v3.8h,  v4.8h,  #(14 - \bitdepth)
-.if \size > 16 /* dc 32x32 */
-        mov             x2,  #4
+        ldrsh           w1, [x0]
+        add             w1, w1, #1
+        asr             w1, w1, #1
+        add             w1, w1, #(1 << (13 - \bitdepth))
+        asr             w1, w1, #(14 - \bitdepth)
+        dup             v0.8h, w1
+
+.if \size < 8
+        stp             q0, q0, [x0]
+.elseif \size < 16
+        idct_8x8_dc_store 0x0
+.elseif \size < 32
+        idct_16x16_dc_store
+.else
+        add             x2, x0, #(32 * 32 * 2)
 1:
-        subs            x2,  x2, #1
-.endif
-        add             x12,  x0, #64
-        mov             x13,  #128
-.if \size > 8 /* dc 16x16 */
-        st1             {v0.8h-v3.8h},  [x0], x13
-        st1             {v0.8h-v3.8h}, [x12], x13
-        st1             {v0.8h-v3.8h},  [x0], x13
-        st1             {v0.8h-v3.8h}, [x12], x13
-        st1             {v0.8h-v3.8h},  [x0], x13
-        st1             {v0.8h-v3.8h}, [x12], x13
-.endif /* dc 8x8 */
-        st1             {v0.8h-v3.8h},  [x0], x13
-        st1             {v0.8h-v3.8h}, [x12], x13
-.if \size > 16 /* dc 32x32 */
-        bne             1b
-.endif
-.else /* dc 4x4 */
-        st1             {v0.8h-v1.8h},  [x0]
+        idct_16x16_dc_store
+        add             x0, x0, #(16 * 16 * 2)
+        cmp             x0, x2
+        b.lt            1b
 .endif
         ret
 endfunc



More information about the ffmpeg-cvslog mailing list