[FFmpeg-cvslog] avcodec/x86/mpegvideoencdsp: speed up draw_edges_mmx by using memcpy()

Ramiro Polla git at videolan.org
Mon Aug 26 13:54:29 EEST 2024


ffmpeg | branch: master | Ramiro Polla <ramiro.polla at gmail.com> | Wed Aug 21 16:55:54 2024 +0200| [3bfce2a10447abc3d72107fd9b86ab23c9e3a3ba] | committer: Ramiro Polla

avcodec/x86/mpegvideoencdsp: speed up draw_edges_mmx by using memcpy()

The mmx memory copy code is not nearly as efficient as memcpy(), which
would make draw_edges_mmx much slower than draw_edges_8_c.

Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz:
                                      before    after
draw_edges_8_1724_4_mmx:              8700.5   8751.8  ( 0.99x)
draw_edges_8_1724_8_mmx:             10441.7  10558.0  ( 0.99x)
draw_edges_8_1724_16_mmx:            10660.7  10799.5  ( 0.99x)
draw_edges_128_407_4_mmx:             4202.2   4099.3  ( 1.03x)
draw_edges_128_407_8_mmx:             4579.0   4511.3  ( 1.02x)
draw_edges_128_407_16_mmx:            5479.7   4729.5  ( 1.16x)
draw_edges_1080_31_4_mmx:             1546.7    658.0  ( 2.35x)
draw_edges_1080_31_8_mmx:             2745.5   1442.5  ( 1.90x)
draw_edges_1080_31_16_mmx:           12511.5   4901.0  ( 2.55x)
draw_edges_1920_4_4_mmx:              2659.0    705.0  ( 3.77x)
draw_edges_1920_4_4_negstride_mmx:    2643.0    729.0  ( 3.63x)
draw_edges_1920_4_8_mmx:              7845.0   2819.0  ( 2.78x)
draw_edges_1920_4_8_negstride_mmx:    7777.0   2747.3  ( 2.83x)
draw_edges_1920_4_16_mmx:            24583.7   6358.3  ( 3.87x)
draw_edges_1920_4_16_negstride_mmx:  24589.0   6367.0  ( 3.86x)

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

 libavcodec/x86/mpegvideoencdsp_init.c | 52 ++++++++---------------------------
 1 file changed, 11 insertions(+), 41 deletions(-)

diff --git a/libavcodec/x86/mpegvideoencdsp_init.c b/libavcodec/x86/mpegvideoencdsp_init.c
index f199b23299..5d23169450 100644
--- a/libavcodec/x86/mpegvideoencdsp_init.c
+++ b/libavcodec/x86/mpegvideoencdsp_init.c
@@ -102,7 +102,6 @@ static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
     uint8_t *ptr, *last_line;
     int i;
 
-    last_line = buf + (height - 1) * wrap;
     /* left and right */
     ptr = buf;
     if (w == 8) {
@@ -166,46 +165,17 @@ static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
               "r" (ptr + wrap * height));
     }
 
-    /* top and bottom (and hopefully also the corners) */
-    if (sides & EDGE_TOP) {
-        for (i = 0; i < h; i += 4) {
-            ptr = buf - (i + 1) * wrap - w;
-            __asm__ volatile (
-                "1:                             \n\t"
-                "movq (%1, %0), %%mm0           \n\t"
-                "movq    %%mm0, (%0)            \n\t"
-                "movq    %%mm0, (%0, %2)        \n\t"
-                "movq    %%mm0, (%0, %2, 2)     \n\t"
-                "movq    %%mm0, (%0, %3)        \n\t"
-                "add        $8, %0              \n\t"
-                "cmp        %4, %0              \n\t"
-                "jb         1b                  \n\t"
-                : "+r" (ptr)
-                : "r" ((x86_reg) buf - (x86_reg) ptr - w),
-                  "r" ((x86_reg) - wrap), "r" ((x86_reg) - wrap * 3),
-                  "r" (ptr + width + 2 * w));
-        }
-    }
-
-    if (sides & EDGE_BOTTOM) {
-        for (i = 0; i < h; i += 4) {
-            ptr = last_line + (i + 1) * wrap - w;
-            __asm__ volatile (
-                "1:                             \n\t"
-                "movq (%1, %0), %%mm0           \n\t"
-                "movq    %%mm0, (%0)            \n\t"
-                "movq    %%mm0, (%0, %2)        \n\t"
-                "movq    %%mm0, (%0, %2, 2)     \n\t"
-                "movq    %%mm0, (%0, %3)        \n\t"
-                "add        $8, %0              \n\t"
-                "cmp        %4, %0              \n\t"
-                "jb         1b                  \n\t"
-                : "+r" (ptr)
-                : "r" ((x86_reg) last_line - (x86_reg) ptr - w),
-                  "r" ((x86_reg) wrap), "r" ((x86_reg) wrap * 3),
-                  "r" (ptr + width + 2 * w));
-        }
-    }
+    /* top and bottom + corners */
+    buf -= w;
+    last_line = buf + (height - 1) * wrap;
+    if (sides & EDGE_TOP)
+        for (i = 0; i < h; i++)
+            // top
+            memcpy(buf - (i + 1) * wrap, buf, width + w + w);
+    if (sides & EDGE_BOTTOM)
+        for (i = 0; i < h; i++)
+            // bottom
+            memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
 }
 
 #endif /* HAVE_INLINE_ASM */



More information about the ffmpeg-cvslog mailing list