[FFmpeg-devel] [PATCH 3/4] WIP: lavc/h264dsp: take over looking up TC values

Rémi Denis-Courmont remi at remlab.net
Mon Jul 1 20:08:06 EEST 2024


This moves the look-up of TC values from bS from the generic C loop
filter code to the DSP functions. This (potentially) eliminates a
round-trip to the stack for the looked-up values.

This is work-in-progress. 8 functions need to be updated and this
only updates one of them. Also updating the platform-specific
optimisations is left as an exercise for a future version, as is
updating checkasm.
---
 libavcodec/h264_loopfilter.c  | 8 ++------
 libavcodec/h264dsp.h          | 4 +++-
 libavcodec/h264dsp_template.c | 9 +++++++--
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/libavcodec/h264_loopfilter.c b/libavcodec/h264_loopfilter.c
index 96f572c1d2..8fca08811c 100644
--- a/libavcodec/h264_loopfilter.c
+++ b/libavcodec/h264_loopfilter.c
@@ -108,12 +108,8 @@ static av_always_inline void filter_mb_edgev(uint8_t *pix, int stride,
     if (alpha ==0 || beta == 0) return;
 
     if( bS[0] < 4 || !intra ) {
-        int8_t tc[4];
-        tc[0] = ff_h264_tc0_table[index_a][bS[0]];
-        tc[1] = ff_h264_tc0_table[index_a][bS[1]];
-        tc[2] = ff_h264_tc0_table[index_a][bS[2]];
-        tc[3] = ff_h264_tc0_table[index_a][bS[3]];
-        h->h264dsp.h264_h_loop_filter_luma(pix, stride, alpha, beta, tc);
+        const int8_t *tc = ff_h264_tc0_table[index_a];
+        h->h264dsp.h264_h_loop_filter_luma(pix, stride, alpha, beta, tc, bS);
     } else {
         h->h264dsp.h264_h_loop_filter_luma_intra(pix, stride, alpha, beta);
     }
diff --git a/libavcodec/h264dsp.h b/libavcodec/h264dsp.h
index 13371c59ea..f37ff5414c 100644
--- a/libavcodec/h264dsp.h
+++ b/libavcodec/h264dsp.h
@@ -48,7 +48,9 @@ typedef struct H264DSPContext {
     void (*h264_v_loop_filter_luma)(uint8_t *pix /*align 16*/, ptrdiff_t stride,
                                     int alpha, int beta, int8_t *tc0);
     void (*h264_h_loop_filter_luma)(uint8_t *pix /*align 4 */, ptrdiff_t stride,
-                                    int alpha, int beta, int8_t *tc0);
+                                    int alpha, int beta,
+                                    const int8_t tc0[4] /*align 4*/,
+                                    const int16_t bs[4] /*align 8*/);
     void (*h264_h_loop_filter_luma_mbaff)(uint8_t *pix /*align 16*/, ptrdiff_t stride,
                                           int alpha, int beta, int8_t *tc0);
     /* v/h_loop_filter_luma_intra: align 16 */
diff --git a/libavcodec/h264dsp_template.c b/libavcodec/h264dsp_template.c
index fe23a2cff1..4d4e34cf81 100644
--- a/libavcodec/h264dsp_template.c
+++ b/libavcodec/h264dsp_template.c
@@ -153,9 +153,14 @@ static void FUNCC(h264_v_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride, int a
 {
     FUNCC(h264_loop_filter_luma)(pix, stride, sizeof(pixel), 4, alpha, beta, tc0);
 }
-static void FUNCC(h264_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
+static void FUNCC(h264_h_loop_filter_luma)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, const int8_t tc0[4], const int16_t bS[4])
 {
-    FUNCC(h264_loop_filter_luma)(pix, sizeof(pixel), stride, 4, alpha, beta, tc0);
+    int8_t tc[4];
+
+    for (size_t i = 0; i < 4; i++)
+        tc[i] = tc0[bS[i]];
+
+    FUNCC(h264_loop_filter_luma)(pix, sizeof(pixel), stride, 4, alpha, beta, tc);
 }
 static void FUNCC(h264_h_loop_filter_luma_mbaff)(uint8_t *pix, ptrdiff_t stride, int alpha, int beta, int8_t *tc0)
 {
-- 
2.45.2



More information about the ffmpeg-devel mailing list