diff mbox series

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

Message ID 20240818201326.100492-7-ramiro.polla@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/7] checkasm/mpegvideoencdsp: add pix_sum and pix_norm1 | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Ramiro Polla Aug. 18, 2024, 8:13 p.m. UTC
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 mbox series

Patch

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 */