[FFmpeg-devel] [PATCH 7/7] avcodec/mpegvideoencdsp: speed up draw_edges_8_c by inlining it for all used edge widths

Ramiro Polla ramiro.polla at gmail.com
Sun Aug 18 23:13:26 EEST 2024


This commit also restricts w to 4, 8, or 16.

Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz:
                           before    after
draw_edges_8_1724_4_c:    45074.5   7144.7  ( 6.31x)
draw_edges_8_1724_8_c:    41716.5   7216.0  ( 5.78x)
draw_edges_8_1724_16_c:   45282.7  16026.2  ( 2.83x)
draw_edges_128_407_4_c:   10863.2   4153.0  ( 2.62x)
draw_edges_128_407_8_c:   10273.0   4392.7  ( 2.34x)
draw_edges_128_407_16_c:  11606.0   4614.0  ( 2.52x)
draw_edges_1080_31_4_c:    1238.5    971.7  ( 1.27x)
draw_edges_1080_31_8_c:    1712.2   1035.2  ( 1.65x)
draw_edges_1080_31_16_c:   4281.5   3774.7  ( 1.13x)
draw_edges_1920_4_4_c:      920.5    731.0  ( 1.26x)
draw_edges_1920_4_8_c:     2861.0   2749.5  ( 1.04x)
draw_edges_1920_4_16_c:    6416.7   6334.5  ( 1.01x)
---
 libavcodec/mpegvideoencdsp.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/libavcodec/mpegvideoencdsp.c b/libavcodec/mpegvideoencdsp.c
index a96f0b6436..89fde7edf0 100644
--- a/libavcodec/mpegvideoencdsp.c
+++ b/libavcodec/mpegvideoencdsp.c
@@ -114,19 +114,31 @@ static int pix_norm1_c(const uint8_t *pix, int line_size)
     return s;
 }
 
+static av_always_inline void draw_edges_lr(uint8_t *ptr, int wrap, int width, int height, int w)
+{
+    for (int i = 0; i < height; i++) {
+        memset(ptr - w, ptr[0], w);
+        memset(ptr + width, ptr[width - 1], w);
+        ptr += wrap;
+    }
+}
+
 /* draw the edges of width 'w' of an image of size width, height */
 // FIXME: Check that this is OK for MPEG-4 interlaced.
 static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
                            int w, int h, int sides)
 {
-    uint8_t *ptr = buf, *last_line;
+    uint8_t *last_line;
     int i;
 
     /* left and right */
-    for (i = 0; i < height; i++) {
-        memset(ptr - w, ptr[0], w);
-        memset(ptr + width, ptr[width - 1], w);
-        ptr += wrap;
+    if (w == 16) {
+        draw_edges_lr(buf, wrap, width, height, 16);
+    } else if (w == 8) {
+        draw_edges_lr(buf, wrap, width, height, 8);
+    } else {
+        av_assert1(w == 4);
+        draw_edges_lr(buf, wrap, width, height, 4);
     }
 
     /* top and bottom + corners */
-- 
2.30.2



More information about the ffmpeg-devel mailing list