[PR] avcodec/x86/h264_intrapred: various mprovements (PR #23933)

mkver via ffmpeg-devel <[email protected]> Mon, 27 Jul 2026 22:20:00 -0000
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <178519080178.51.5080668553167926434@29965ddac10e>
PR #23933 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23933
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23933.patch


>From 2610aa84bb0e89a19b5f9e3bc7717d8d1403a5c2 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 27 Jul 2026 22:16:26 +0200
Subject: [PATCH 1/3] avcodec/x86/h264_intrapred: Report accurate number of
 registers used

The pred{8x8,16x16}_plane functions only use five xmm register.
The inflated number of seven (which leads to saving and restoring
xmm6 on Win64) has been introduced in
d20f133ef962da71326bc3635e086696f45ab64e, probably because
the mmx version of these functions used seven mmx register.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/x86/h264_intrapred.asm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/x86/h264_intrapred.asm b/libavcodec/x86/h264_intrapred.asm
index 4a785d480f..d6b0335c54 100644
--- a/libavcodec/x86/h264_intrapred.asm
+++ b/libavcodec/x86/h264_intrapred.asm
@@ -240,7 +240,7 @@ cglobal pred16x16_tm_vp8_8, 2, 4, 5, dst, stride, stride3, iteration
 ;-----------------------------------------------------------------------------
 
 %macro H264_PRED16x16_PLANE 1
-cglobal pred16x16_plane_%1_8, 2,9,7
+cglobal pred16x16_plane_%1_8, 2,9,5
     mov          r2, r1           ; +stride
     neg          r1               ; -stride
 
@@ -448,7 +448,7 @@ H264_PRED16x16_PLANE svq3
 ;-----------------------------------------------------------------------------
 
 %macro H264_PRED8x8_PLANE 0
-cglobal pred8x8_plane_8, 2,9,7
+cglobal pred8x8_plane_8, 2,9,5
     mov          r2, r1           ; +stride
     neg          r1               ; -stride
 
-- 
2.52.0


>From a3bb060218a3165e648fa897428b3a976fb6fe4d Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 27 Jul 2026 22:44:21 +0200
Subject: [PATCH 2/3] avcodec/x86/h264_intrapred: Reduce number of regs in
 pred4x4_tm_vp8_8

Avoids saving and restoring volatile xmm registers on Windows;
no change in benchmarks here (on Unix64).

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/x86/h264_intrapred.asm | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/libavcodec/x86/h264_intrapred.asm b/libavcodec/x86/h264_intrapred.asm
index d6b0335c54..a78a0b0e92 100644
--- a/libavcodec/x86/h264_intrapred.asm
+++ b/libavcodec/x86/h264_intrapred.asm
@@ -1699,24 +1699,24 @@ cglobal pred4x4_tm_vp8_8, 3,6,4
     RET
 
 INIT_XMM ssse3
-cglobal pred4x4_tm_vp8_8, 3,3,8
+cglobal pred4x4_tm_vp8_8, 3,3,6
     sub         r0, r2
-    movq        m6, [tm_shuf]
-    pxor        m1, m1
+    movq        m1, [tm_shuf]
     movd        m0, [r0]
-    punpcklbw   m0, m1
-    movd        m7, [r0-4]
-    pshufb      m7, m6
+    movd        m5, [r0-4]
     lea         r1, [r0+r2*2]
+    pxor        m4, m4
+    punpcklbw   m0, m4
+    pshufb      m5, m1
     movd        m2, [r0+r2*1-4]
     movd        m3, [r0+r2*2-4]
     movd        m4, [r1+r2*1-4]
+    psubw       m0, m5
     movd        m5, [r1+r2*2-4]
-    pshufb      m2, m6
-    pshufb      m3, m6
-    pshufb      m4, m6
-    pshufb      m5, m6
-    psubw       m0, m7
+    pshufb      m2, m1
+    pshufb      m3, m1
+    pshufb      m4, m1
+    pshufb      m5, m1
     paddw       m2, m0
     paddw       m3, m0
     paddw       m4, m0
-- 
2.52.0


>From 4d665cebdd41e2e9164b19e24338e742554ae451 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 27 Jul 2026 23:09:58 +0200
Subject: [PATCH 3/3] avcodec/x86/h264_intrapred: Avoid shuffles

We only need the shuffle a byte in the lower quadword;
also notice that we don't need the clamping provided
by packuswb as these values are averages of byte values.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/x86/h264_intrapred.asm | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavcodec/x86/h264_intrapred.asm b/libavcodec/x86/h264_intrapred.asm
index a78a0b0e92..a6aebd56ac 100644
--- a/libavcodec/x86/h264_intrapred.asm
+++ b/libavcodec/x86/h264_intrapred.asm
@@ -848,8 +848,8 @@ cglobal pred8x8l_top_dc_8, 4,4,6
     psadbw   m4, m3
     paddw    m4, [pw_4]
     psrlw    m4, 3
-    SPLATW   m4, m4, 0
-    packuswb m4, m4
+    punpcklbw m4, m4
+    pshuflw  m4, m4, 0
 %rep 3
     movq [r0+r3*1], m4
     movq [r0+r3*2], m4
@@ -940,9 +940,8 @@ cglobal pred8x8l_dc_8, 4,5,6
     paddw        m3, m2
     lea          r4, [r2+r3*2]
     psrlw        m3, 4
+    punpcklbw    m3, m3
     pshuflw      m3, m3, 0
-    punpcklqdq   m3, m3
-    packuswb     m3, m3
     movq  [r0+r3*1], m3
     movq  [r0+r3*2], m3
     movq  [r1+r3*1], m3
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]