PR #26044 opened by zuxy
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26044
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26044.patch

Converts the remaining 16-bit VC-1 motion-compensation filters from MMX/MMXEXT 
to SSE2 and cleans up the leftover MMX references. All filters now use the full 
16-byte XMM width with no MMX registers left.

1. avcodec/x86/vc1: convert 16b shift2 filters MMX to SSE2
 converts the shift2 vertical/horizontal filters in 
libavcodec/x86/vc1dsp_mc.asm plus its wrappers in libavcodec/x86/vc1dsp_mmx.c: 
one movu load per tap, 8 outputs per register, and full-width constants/rounder.
2. avcodec/x86/vc1: convert 16b shift1/3 filters MMX to SSE2
 converts the shift1/shift3 filters in libavcodec/x86/vc1dsp_mmx.c from inline 
MMX to inline SSE2, renames the init to SSE2 in libavcodec/x86/vc1dsp.h and 
libavcodec/x86/vc1dsp_init.c, and drops emms from the test in 
tests/checkasm/vc1dsp.c.
3. avcodec/x86/vc1: clean up remaining references to MMX
 cleanup only with no generated-code change: gates the SSE2 asm block on 
HAVE_SSE2_INLINE, drops the _MMX macro suffixes, and removes dead NASM macros.

Testing: checkasm --test=vc1dsp passes on x86-64 and i686, and fate-vc1 passes 
on both. Benchmarks show shift2 ~25–37% faster on x86-64 and shift1/shift3 ~50% 
faster on x86-64 8-wide, with smaller gains on i686.


From 6bd5e9cf35f6825afe72694ebecfbdd1c77c9688 Mon Sep 17 00:00:00 2001
From: Zuxy Meng <[email protected]>
Date: Mon, 2 Nov 2026 19:43:12 -0800
Subject: [PATCH 1/3] avcodec/x86/vc1: convert 16b shift2 filters MMX to SSE2

Convert ff_vc1_put_ver_16b_shift2 and ff_vc1_put/avg_hor_16b_shift2
from MMX/MMXEXT to SSE2. Memory-operand SIMD ops are split into an
explicit load plus a register op, and no MMX registers remain in
these functions.

The filters operate on the full 16-byte width of the XMM registers:

- The horizontal filter loads each tap once with movu (16 bytes, 8
  int16 values), computes all 8 outputs in one register, and
  packs/stores them with a single 8-byte store. The loads cover
  bytes 0..21 of each row, exactly the tapped range. Constants
  and the rounder are full-width: pw_9 is read with mova, pw_128
  is broadcast with punpcklqdq (it is only 8 bytes), and the
  rounder is broadcast with pshufd so all 8 lanes get the low
  dword of rndd.
- The vertical filter unpacks 8 pixels per row. Its 8 calls are
  factored into VER_PASS, run twice: the first pass stores all 8
  int16 results with movu, the second stores the low 4 (cols 8-11)
  with movq. The rounder and pw_9 are read full-width, as above.

This is the first VC-1 diff: the shift1/shift3 inline-asm filters in
vc1dsp_mmx.c still use MMX and are converted by the next diff.

Benchmarks (checkasm, Zen 4, pinned, median of 5 interleaved
rounds, --duration=20000, cycles; MMX parent vs this commit, put/avg.
mc11 is the control: identical code in both builds):

  x86-64, 8-wide          mmx       sse2
    mc12                  73.1/73.6  54.7/55.1
    mc21                  87.5/88.7  75.6/75.4
    mc22                  63.3/64.1  39.8/41.6
    mc23                  87.6/88.7  75.3/75.9
    mc32                  73.1/73.7  54.2/54.8
    mc11 (control)        97.5/98.5  97.5/98.4
  x86-64, 16-wide mc22   259.5/264.6 161.4/169.6

  i686, 8-wide            mmx       sse2
    mc12                  72.7/73.3  57.2/59.2
    mc21                  87.7/87.6  76.2/76.0
    mc22                  62.7/62.9  49.3/51.5
    mc23                  87.7/87.7  75.3/76.1
    mc32                  72.6/73.3  58.0/59.3
    mc11 (control)        97.6/98.8  97.6/98.3
  i686, 16-wide mc22     252.2/258.6 197.7/206.6

checkasm --test=vc1dsp passes (109/109 on x86-64, 107/107 on
i686, 5 seeds each); fate-vc1 passes on both ABIs.

Signed-off-by: Zuxy Meng <[email protected]>
---
 libavcodec/x86/vc1dsp_mc.asm | 167 +++++++++++++++++++----------------
 libavcodec/x86/vc1dsp_mmx.c  |  24 ++---
 2 files changed, 102 insertions(+), 89 deletions(-)

diff --git a/libavcodec/x86/vc1dsp_mc.asm b/libavcodec/x86/vc1dsp_mc.asm
index e4f626bd7a0..35a790811b4 100644
--- a/libavcodec/x86/vc1dsp_mc.asm
+++ b/libavcodec/x86/vc1dsp_mc.asm
@@ -46,7 +46,8 @@ SECTION .text
 %endmacro
 
 %macro OP_AVG 2 ; dst, src
-    pavgb           %1, %2
+    movq            m0, %2
+    pavgb           %1, m0
 %endmacro
 
 %macro NORMALIZE_MMX 1 ; shift
@@ -58,15 +59,19 @@ SECTION .text
 
 %macro TRANSFER_DO_PACK 2 ; op, dst
     packuswb        m3, m4
+    ; Only the low 4 words of m3/m4 hold valid data; the second and
+    ; fourth dwords of the packed result are garbage. Shuffle the two
+    ; valid dwords together so a single 8-byte store writes them.
+    pshufd          m3, m3, 0x08
     %1              m3, [%2]
-    mova          [%2], m3
+    movq          [%2], m3
 %endmacro
 
 %macro TRANSFER_DONT_PACK 2 ; op, dst
     %1              m3, [%2]
-    %1              m3, [%2 + mmsize]
-    mova          [%2], m3
-    mova [mmsize + %2], m4
+    %1              m3, [%2 + 8]
+    movq          [%2], m3
+    movq      [8 + %2], m4
 %endmacro
 
 ; see MSPEL_FILTER13_CORE for use as UNPACK macro
@@ -83,7 +88,7 @@ SECTION .text
     punpckldq m7, m7
 %endmacro
 
-%macro SHIFT2_LINE 5 ; off, r0, r1, r2, r3
+%macro SHIFT2_LINE 6 ; off, r0, r1, r2, r3, store
     paddw          m%3, m%4
     movh           m%2, [srcq + stride_neg2]
     pmullw         m%3, m6
@@ -94,100 +99,108 @@ SECTION .text
     paddw          m%3, m7
     psubw          m%3, m%5
     psraw          m%3, shift
-    movu   [dstq + %1], m%3
+    %6     [dstq + %1], m%3
     add           srcq, strideq
 %endmacro
 
-INIT_MMX mmx
-; void ff_vc1_put_ver_16b_shift2_mmx(int16_t *dst, const uint8_t *src,
-;                                    x86_reg stride, int rnd, int64_t shift)
-; Sacrificing m6 makes it possible to pipeline loads from src
-%if ARCH_X86_32
-cglobal vc1_put_ver_16b_shift2, 3,6,0, dst, src, stride
-    DECLARE_REG_TMP     3, 4, 5
-    %define rnd r3mp
-    %define shift qword r4m
-%else ; X86_64
-cglobal vc1_put_ver_16b_shift2, 4,7,0, dst, src, stride
-    DECLARE_REG_TMP     4, 5, 6
-    %define   rnd r3d
-    ; We need shift either in memory or in a mm reg as it's used in psraw
-    ; On WIN64, the arg is already on the stack
-    ; On UNIX64, m5 doesn't seem to be used
-%if WIN64
-    %define shift r4mp
-%else ; UNIX64
-    %define shift m5
-    mova shift, r4q
-%endif ; WIN64
-%endif ; X86_32
-%define stride_neg2 t0q
-%define stride_9minus4 t1q
-%define i t2q
-    mov       stride_neg2, strideq
-    neg       stride_neg2
-    add       stride_neg2, stride_neg2
-    lea    stride_9minus4, [strideq * 9 - 4]
-    mov                 i, 3
-    LOAD_ROUNDER_MMX  rnd
-    mova               m6, [pw_9]
-    pxor               m0, m0
-.loop:
+; One pass over the 8 rows: prime the pipeline, then one SHIFT2_LINE per
+; row. The loads already unpack 8 pixels, so the arithmetic is 8-wide
+; and only the store width differs between passes: the first pass
+; stores all 8 int16 results, the second stores the low 4 (cols 8-11)
+; of the recomputed row.
+%macro VER_PASS 1 ; store
     movh               m2, [srcq]
     add              srcq, strideq
     movh               m3, [srcq]
     punpcklbw          m2, m0
     punpcklbw          m3, m0
-    SHIFT2_LINE         0, 1, 2, 3, 4
-    SHIFT2_LINE        24, 2, 3, 4, 1
-    SHIFT2_LINE        48, 3, 4, 1, 2
-    SHIFT2_LINE        72, 4, 1, 2, 3
-    SHIFT2_LINE        96, 1, 2, 3, 4
-    SHIFT2_LINE       120, 2, 3, 4, 1
-    SHIFT2_LINE       144, 3, 4, 1, 2
-    SHIFT2_LINE       168, 4, 1, 2, 3
-    sub              srcq, stride_9minus4
-    add              dstq, 8
-    dec                 i
-        jnz         .loop
+    SHIFT2_LINE         0, 1, 2, 3, 4, %1
+    SHIFT2_LINE        24, 2, 3, 4, 1, %1
+    SHIFT2_LINE        48, 3, 4, 1, 2, %1
+    SHIFT2_LINE        72, 4, 1, 2, 3, %1
+    SHIFT2_LINE        96, 1, 2, 3, 4, %1
+    SHIFT2_LINE       120, 2, 3, 4, 1, %1
+    SHIFT2_LINE       144, 3, 4, 1, 2, %1
+    SHIFT2_LINE       168, 4, 1, 2, 3, %1
+%endmacro
+
+INIT_XMM sse2
+; void ff_vc1_put_ver_16b_shift2_sse2(int16_t *dst, const uint8_t *src,
+;                                    x86_reg stride, int rnd, int64_t shift)
+; Sacrificing m6 makes it possible to pipeline loads from src
+%if ARCH_X86_32
+cglobal vc1_put_ver_16b_shift2, 3,6,8, dst, src, stride
+    DECLARE_REG_TMP     3, 4, 5
+    %define rnd r3mp
+%else ; X86_64
+cglobal vc1_put_ver_16b_shift2, 4,7,8, dst, src, stride
+    DECLARE_REG_TMP     4, 5, 6
+    %define   rnd r3d
+%endif
+    ; psraw takes its count from an xmm reg or 16-byte-aligned
+    ; memory, so park the runtime shift value in m5 up front.
+    ; Only the low 64 bits are read as the count, and none of
+    ; the stack homes below is 16-byte aligned.
+%if ARCH_X86_32
+    ; The int64 shift arg spans two dword stack slots.
+    movq               m5, r4m
+%elif WIN64
+    movq               m5, r4mp
+%else ; UNIX64
+    movq               m5, r4q
+%endif
+    %define shift m5
+%define stride_neg2 t0q
+%define stride_9minus8 t1q
+    mov       stride_neg2, strideq
+    neg       stride_neg2
+    add       stride_neg2, stride_neg2
+    lea    stride_9minus8, [strideq * 9 - 8]
+    LOAD_ROUNDER_MMX  rnd
+    pshufd             m7, m7, 0
+    mova               m6, [pw_9]
+    pxor               m0, m0
+    VER_PASS         movu
+    sub              srcq, stride_9minus8
+    add              dstq, 16
+    VER_PASS         movq
     RET
 %undef rnd
 %undef shift
 %undef stride_neg2
-%undef stride_9minus4
-%undef i
+%undef stride_9minus8
 
-; void ff_vc1_*_hor_16b_shift2_mmx(uint8_t *dst, x86_reg stride,
+; void ff_vc1_*_hor_16b_shift2_sse2(uint8_t *dst, x86_reg stride,
 ;                                  const int16_t *src, int rnd);
 ; Data is already unpacked, so some operations can directly be made from
 ; memory.
 %macro HOR_16B_SHIFT2 2 ; op, opname
-cglobal vc1_%2_hor_16b_shift2, 4, 5, 0, dst, stride, src, rnd, h
+cglobal vc1_%2_hor_16b_shift2, 4, 5, 8, dst, stride, src, rnd, h
     mov                hq, 8
     sub              srcq, 2
     sub              rndd, (-1+9+9-1) * 1024 ; add -1024 bias
     LOAD_ROUNDER_MMX rndd
+    pshufd             m7, m7, 0
     mova               m5, [pw_9]
-    mova               m6, [pw_128]
+    movq               m6, [pw_128]
+    punpcklqdq         m6, m6
 
 .loop:
-    mova               m1, [srcq + 2 * 0]
-    mova               m2, [srcq + 2 * 0 + mmsize]
-    mova               m3, [srcq + 2 * 1]
-    mova               m4, [srcq + 2 * 1 + mmsize]
-    paddw              m3, [srcq + 2 * 2]
-    paddw              m4, [srcq + 2 * 2 + mmsize]
-    paddw              m1, [srcq + 2 * 3]
-    paddw              m2, [srcq + 2 * 3 + mmsize]
-    pmullw             m3, m5
-    pmullw             m4, m5
-    psubw              m3, m1
-    psubw              m4, m2
-    NORMALIZE_MMX      7
+    movu               m1, [srcq + 2 * 0]
+    movu               m2, [srcq + 2 * 1]
+    movu               m3, [srcq + 2 * 2]
+    movu               m4, [srcq + 2 * 3]
+    paddw              m2, m3
+    paddw              m1, m4
+    pmullw             m2, m5
+    psubw              m2, m1
+    paddw              m2, m7 ; +bias-r
+    psraw              m2, 7
     ; remove bias
-    paddw              m3, m6
-    paddw              m4, m6
-    TRANSFER_DO_PACK   %1, dstq
+    paddw              m2, m6
+    packuswb           m2, m2
+    %1                 m2, [dstq]
+    movq           [dstq], m2
     add              srcq, 24
     add              dstq, strideq
     dec                hq
@@ -196,10 +209,10 @@ cglobal vc1_%2_hor_16b_shift2, 4, 5, 0, dst, stride, src, 
rnd, h
     RET
 %endmacro
 
-INIT_MMX mmx
+INIT_XMM sse2
 HOR_16B_SHIFT2 OP_PUT, put
 
-INIT_MMX mmxext
+INIT_XMM sse2
 HOR_16B_SHIFT2 OP_AVG, avg
 %endif ; HAVE_MMX_INLINE
 
diff --git a/libavcodec/x86/vc1dsp_mmx.c b/libavcodec/x86/vc1dsp_mmx.c
index 36591f83fc6..efa177a00d8 100644
--- a/libavcodec/x86/vc1dsp_mmx.c
+++ b/libavcodec/x86/vc1dsp_mmx.c
@@ -35,13 +35,13 @@
 
 #if HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_MMX_EXTERNAL
 
-void ff_vc1_put_ver_16b_shift2_mmx(int16_t *dst,
-                                   const uint8_t *src, x86_reg stride,
-                                   int rnd, int64_t shift);
-void ff_vc1_put_hor_16b_shift2_mmx(uint8_t *dst, x86_reg stride,
-                                   const int16_t *src, int rnd);
-void ff_vc1_avg_hor_16b_shift2_mmxext(uint8_t *dst, x86_reg stride,
-                                      const int16_t *src, int rnd);
+void ff_vc1_put_ver_16b_shift2_sse2(int16_t *dst,
+                                    const uint8_t *src, x86_reg stride,
+                                    int rnd, int64_t shift);
+void ff_vc1_put_hor_16b_shift2_sse2(uint8_t *dst, x86_reg stride,
+                                    const int16_t *src, int rnd);
+void ff_vc1_avg_hor_16b_shift2_sse2(uint8_t *dst, x86_reg stride,
+                                    const int16_t *src, int rnd);
 
 #define OP_PUT(S,D)
 #define OP_AVG(S,D) "pavgb " #S ", " #D " \n\t"
@@ -236,14 +236,14 @@ typedef void (*vc1_mspel_mc_filter_hor_16bits)(uint8_t 
*dst, x86_reg dst_stride,
  * @param  hmode   Vertical filter.
  * @param  rnd     Rounding bias.
  */
-#define VC1_MSPEL_MC(OP, INSTR)\
+#define VC1_MSPEL_MC(OP)\
 static void OP ## vc1_mspel_mc(uint8_t *dst, const uint8_t *src, ptrdiff_t 
stride,\
                                int hmode, int vmode, int rnd)\
 {\
     static const vc1_mspel_mc_filter_ver_16bits vc1_put_shift_ver_16bits[] =\
-         { NULL, vc1_put_ver_16b_shift1_mmx, ff_vc1_put_ver_16b_shift2_mmx, 
vc1_put_ver_16b_shift3_mmx };\
+         { NULL, vc1_put_ver_16b_shift1_mmx, ff_vc1_put_ver_16b_shift2_sse2, 
vc1_put_ver_16b_shift3_mmx };\
     static const vc1_mspel_mc_filter_hor_16bits vc1_put_shift_hor_16bits[] =\
-         { NULL, OP ## vc1_hor_16b_shift1_mmx, ff_vc1_ ## OP ## 
hor_16b_shift2_ ## INSTR, OP ## vc1_hor_16b_shift3_mmx };\
+         { NULL, OP ## vc1_hor_16b_shift1_mmx, ff_vc1_ ## OP ## 
hor_16b_shift2_sse2, OP ## vc1_hor_16b_shift3_mmx };\
 \
     __asm__ volatile(\
         "pxor %%mm0, %%mm0         \n\t"\
@@ -270,8 +270,8 @@ static void OP ## vc1_mspel_mc_16(uint8_t *dst, const 
uint8_t *src, \
     OP ## vc1_mspel_mc(dst + 8, src + 8, stride, hmode, vmode, rnd); \
 }
 
-VC1_MSPEL_MC(put_, mmx)
-VC1_MSPEL_MC(avg_, mmxext)
+VC1_MSPEL_MC(put_)
+VC1_MSPEL_MC(avg_)
 
 /** Macro to ease bicubic filter interpolation functions declarations */
 #define DECLARE_FUNCTION(a, b)                                          \
-- 
2.54.0


From e2a89d4bd86028da301f25068436a6dfdfe3fd34 Mon Sep 17 00:00:00 2001
From: Zuxy Meng <[email protected]>
Date: Mon, 2 Nov 2026 19:46:29 -0800
Subject: [PATCH 2/3] avcodec/x86/vc1: convert 16b shift1/3 filters MMX to SSE2

Convert the shift1/shift3 vertical and horizontal 16-bit filters in
vc1dsp_mmx.c from inline MMX asm to inline SSE2 asm: mm0-mm7 become
xmm0-xmm7, declared as clobbers via XMM_CLOBBERS.

The filters operate on the full 16-byte width of the XMM registers:

- MSPEL_FILTER13_CORE loads each tap once (movq of 8 packed bytes
  for the vertical filter, movdqu of 8 int16 values for the
  horizontal one) and accumulates all 8 outputs in xmm3.
  NORMALIZE operates on the single accumulator.
- The vertical store is one movdqu of xmm3; the horizontal
  pack/store path packs xmm3 with itself.
- Constants and the rounder are full-width: ff_pw_53 and ff_pw_128
  are only 8 bytes, so they are broadcast with punpcklqdq; ff_pw_18
  is read with movdqu; the rounder is broadcast with pshufd so all
  8 lanes get the low dword of the round value. The bias register
  in the horizontal filter is xmm4, which the loop never writes
  (xmm0 cannot be used: OP_AVG clobbers it in TRANSFER_DO_PACK).

Benchmarks (checkasm, Zen 4, pinned, median of 5 interleaved
rounds, --duration=20000, cycles; MMX parent vs this commit,
put/avg, 8-wide unless noted. Shift2 positions were converted by
the previous diff):

  x86-64                mmx       sse2
    mc11                97.9/98.4   48.7/51.0
    mc13                97.7/98.1   48.9/50.5
    mc21                87.5/88.7   48.1/49.3
    mc23                87.6/88.7   48.0/48.8
    mc31                97.8/98.1   49.2/50.2
    mc33                97.4/98.2   48.6/50.1
    mc12                73.1/73.6   41.7/43.5
    mc32                73.1/73.7   41.5/43.4
    mc22, 16-wide      259.5/264.6 162.1/170.8

  i686                  mmx       sse2
    mc11                97.4/98.1   88.9/90.9
    mc13                97.4/98.1   88.6/90.9
    mc21                87.7/87.6   86.5/88.2
    mc23                87.7/87.7   88.3/88.4
    mc31                97.4/98.1   88.6/90.1
    mc33                97.3/98.1   89.9/90.4
    mc12                72.7/73.3   52.3/55.3
    mc32                72.6/73.3   51.5/54.4
    mc22, 16-wide      252.2/258.6 206.6/206.6

checkasm --test=vc1dsp passes (109/109 on x86-64, 107/107 on
i686, 5 seeds each); fate-vc1 passes on both ABIs.

Signed-off-by: Zuxy Meng <[email protected]>
---
 libavcodec/x86/vc1dsp.h      |   7 +-
 libavcodec/x86/vc1dsp_init.c |  14 +-
 libavcodec/x86/vc1dsp_mmx.c  | 267 +++++++++++++++++------------------
 tests/checkasm/vc1dsp.c      |   2 +-
 4 files changed, 138 insertions(+), 152 deletions(-)

diff --git a/libavcodec/x86/vc1dsp.h b/libavcodec/x86/vc1dsp.h
index 912ea0be36b..28d3de8d12a 100644
--- a/libavcodec/x86/vc1dsp.h
+++ b/libavcodec/x86/vc1dsp.h
@@ -24,11 +24,10 @@
 #include "config.h"
 #include "libavcodec/vc1dsp.h"
 
-#if HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_MMX_EXTERNAL
+#if HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_SSE2_EXTERNAL
 
-void ff_vc1dsp_init_mmx(VC1DSPContext *dsp);
-void ff_vc1dsp_init_mmxext(VC1DSPContext *dsp);
+void ff_vc1dsp_init_sse2(VC1DSPContext *dsp);
 
-#endif /* HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_MMX_EXTERNAL */
+#endif /* HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_SSE2_EXTERNAL */
 
 #endif /* AVCODEC_X86_VC1DSP_H */
diff --git a/libavcodec/x86/vc1dsp_init.c b/libavcodec/x86/vc1dsp_init.c
index 49747feb60e..5f6b7f55564 100644
--- a/libavcodec/x86/vc1dsp_init.c
+++ b/libavcodec/x86/vc1dsp_init.c
@@ -99,15 +99,11 @@ av_cold void ff_vc1dsp_init_x86(VC1DSPContext *dsp)
 {
     int cpu_flags = av_get_cpu_flags();
 
-#if HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_MMX_EXTERNAL
-    if (HAVE_X86_6REGS && INLINE_MMX(cpu_flags))
-        if (EXTERNAL_MMX(cpu_flags))
-        ff_vc1dsp_init_mmx(dsp);
-
-    if (HAVE_X86_6REGS && INLINE_MMXEXT(cpu_flags))
-        if (EXTERNAL_MMXEXT(cpu_flags))
-        ff_vc1dsp_init_mmxext(dsp);
-#endif /* HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_MMX_EXTERNAL */
+#if HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_SSE2_EXTERNAL
+    if (HAVE_X86_6REGS && INLINE_SSE2(cpu_flags))
+        if (EXTERNAL_SSE2(cpu_flags))
+        ff_vc1dsp_init_sse2(dsp);
+#endif /* HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_SSE2_EXTERNAL */
 
 #define ASSIGN_LF4(EXT) \
         dsp->vc1_v_loop_filter4  = ff_vc1_v_loop_filter4_ ## EXT; \
diff --git a/libavcodec/x86/vc1dsp_mmx.c b/libavcodec/x86/vc1dsp_mmx.c
index efa177a00d8..57ca1465060 100644
--- a/libavcodec/x86/vc1dsp_mmx.c
+++ b/libavcodec/x86/vc1dsp_mmx.c
@@ -1,5 +1,5 @@
 /*
- * VC-1 and WMV3 - DSP functions MMX-optimized
+ * VC-1 and WMV3 - DSP functions SSE2-optimized
  * Copyright (c) 2007 Christophe GISQUET <[email protected]>
  *
  * Permission is hereby granted, free of charge, to any person
@@ -33,7 +33,7 @@
 #include "fpel.h"
 #include "vc1dsp.h"
 
-#if HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_MMX_EXTERNAL
+#if HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_SSE2_EXTERNAL
 
 void ff_vc1_put_ver_16b_shift2_sse2(int16_t *dst,
                                     const uint8_t *src, x86_reg stride,
@@ -44,77 +44,63 @@ void ff_vc1_avg_hor_16b_shift2_sse2(uint8_t *dst, x86_reg 
stride,
                                     const int16_t *src, int rnd);
 
 #define OP_PUT(S,D)
-#define OP_AVG(S,D) "pavgb " #S ", " #D " \n\t"
+#define OP_AVG(S,D) "movq " #S ", %%xmm0      \n\t" \
+                    "pavgb %%xmm0, " #D "     \n\t"
 
-/** Add rounder from mm7 to mm3 and pack result at destination */
+/** Add rounder from xmm7 to xmm3 and pack result at destination. */
 #define NORMALIZE_MMX(SHIFT)                                    \
-     "paddw     %%mm7, %%mm3           \n\t" /* +bias-r */      \
-     "paddw     %%mm7, %%mm4           \n\t" /* +bias-r */      \
-     "psraw     "SHIFT", %%mm3         \n\t"                    \
-     "psraw     "SHIFT", %%mm4         \n\t"
+     "paddw     %%xmm7, %%xmm3         \n\t" /* +bias-r */      \
+     "psraw     "SHIFT", %%xmm3        \n\t"
 
 #define TRANSFER_DO_PACK(OP)                    \
-     "packuswb  %%mm4, %%mm3           \n\t"    \
-     OP((%2), %%mm3)                            \
-     "movq      %%mm3, (%2)            \n\t"
-
-#define TRANSFER_DONT_PACK(OP)                  \
-     OP(0(%2), %%mm3)                           \
-     OP(8(%2), %%mm4)                           \
-     "movq      %%mm3, 0(%2)           \n\t"    \
-     "movq      %%mm4, 8(%2)           \n\t"
+     /* xmm3 holds all 8 results; pack it with itself and */    \
+     /* store the low 8 bytes. */                               \
+     "packuswb  %%xmm3, %%xmm3         \n\t"    \
+     OP((%2), %%xmm3)                           \
+     "movq      %%xmm3, (%2)           \n\t"
 
 /** @see MSPEL_FILTER13_CORE for use as UNPACK macro */
-#define DO_UNPACK(reg)  "punpcklbw %%mm0, " reg "\n\t"
+#define DO_UNPACK(reg)  "punpcklbw %%xmm0, " reg "\n\t"
 #define DONT_UNPACK(reg)
 
-/** Compute the rounder 32-r or 8-r and unpacks it to mm7 */
+/** Compute the rounder 32-r or 8-r and unpacks it to xmm7. */
 #define LOAD_ROUNDER_MMX(ROUND)                 \
-     "movd      "ROUND", %%mm7         \n\t"    \
-     "punpcklwd %%mm7, %%mm7           \n\t"    \
-     "punpckldq %%mm7, %%mm7           \n\t"
+     "movd      "ROUND", %%xmm7        \n\t"    \
+     "punpcklwd %%xmm7, %%xmm7         \n\t"    \
+     "punpckldq %%xmm7, %%xmm7         \n\t"    \
+     "pshufd    $0, %%xmm7, %%xmm7     \n\t"
 
 /**
  * Core of the 1/4 and 3/4 shift bicubic interpolation.
  *
  * @param UNPACK  Macro unpacking arguments from 8 to 16 bits (can be empty).
- * @param MOVQ    "movd 1" or "movq 2", if data read is already unpacked.
+ * @param MOVQ    Load mnemonic for one tap, with the neutral "1" scaling
+ *                the old "*0+"/"*4+" addressing used: "movq 1" reads 8
+ *                packed bytes (unpacked by UNPACK), "movdqu 1" reads 8
+ *                unpacked int16 values. Each tap is loaded once, holding
+ *                all 8 outputs in a single register; the result
+ *                accumulates in xmm3.
  * @param A1      Address of 1st tap (beware of unpacked/packed).
  * @param A2      Address of 2nd tap
  * @param A3      Address of 3rd tap
  * @param A4      Address of 4th tap
  */
 #define MSPEL_FILTER13_CORE(UNPACK, MOVQ, A1, A2, A3, A4)       \
-     MOVQ "*0+"A1", %%mm1       \n\t"                           \
-     MOVQ "*4+"A1", %%mm2       \n\t"                           \
-     UNPACK("%%mm1")                                            \
-     UNPACK("%%mm2")                                            \
-     "pmullw    "MANGLE(ff_pw_3)", %%mm1\n\t"                   \
-     "pmullw    "MANGLE(ff_pw_3)", %%mm2\n\t"                   \
-     MOVQ "*0+"A2", %%mm3       \n\t"                           \
-     MOVQ "*4+"A2", %%mm4       \n\t"                           \
-     UNPACK("%%mm3")                                            \
-     UNPACK("%%mm4")                                            \
-     "pmullw    %%mm6, %%mm3    \n\t" /* *18 */                 \
-     "pmullw    %%mm6, %%mm4    \n\t" /* *18 */                 \
-     "psubw     %%mm1, %%mm3    \n\t" /* 18,-3 */               \
-     "psubw     %%mm2, %%mm4    \n\t" /* 18,-3 */               \
-     MOVQ "*0+"A4", %%mm1       \n\t"                           \
-     MOVQ "*4+"A4", %%mm2       \n\t"                           \
-     UNPACK("%%mm1")                                            \
-     UNPACK("%%mm2")                                            \
-     "psllw     $2, %%mm1       \n\t" /* 4* */                  \
-     "psllw     $2, %%mm2       \n\t" /* 4* */                  \
-     "psubw     %%mm1, %%mm3    \n\t" /* -4,18,-3 */            \
-     "psubw     %%mm2, %%mm4    \n\t" /* -4,18,-3 */            \
-     MOVQ "*0+"A3", %%mm1       \n\t"                           \
-     MOVQ "*4+"A3", %%mm2       \n\t"                           \
-     UNPACK("%%mm1")                                            \
-     UNPACK("%%mm2")                                            \
-     "pmullw    %%mm5, %%mm1    \n\t" /* *53 */                 \
-     "pmullw    %%mm5, %%mm2    \n\t" /* *53 */                 \
-     "paddw     %%mm1, %%mm3    \n\t" /* 4,53,18,-3 */          \
-     "paddw     %%mm2, %%mm4    \n\t" /* 4,53,18,-3 */
+     MOVQ "*0+"A2", %%xmm3      \n\t"                           \
+     UNPACK("%%xmm3")                                           \
+     "pmullw    %%xmm6, %%xmm3  \n\t" /* *18 */                 \
+     MOVQ "*0+"A1", %%xmm1      \n\t"                           \
+     UNPACK("%%xmm1")                                           \
+     "pmullw    "MANGLE(ff_pw_3)", %%xmm1\n\t"                  \
+     "psubw     %%xmm1, %%xmm3  \n\t" /* 18,-3 */               \
+     MOVQ "*0+"A4", %%xmm1      \n\t"                           \
+     UNPACK("%%xmm1")                                           \
+     "psllw     $2, %%xmm1      \n\t" /* 4* */                  \
+     "psubw     %%xmm1, %%xmm3  \n\t" /* -4,18,-3 */            \
+     MOVQ "*0+"A3", %%xmm1      \n\t"                           \
+     UNPACK("%%xmm1")                                           \
+     "pmullw    %%xmm5, %%xmm1  \n\t" /* *53 */                 \
+     "paddw     %%xmm1, %%xmm3  \n\t" /* 4,53,18,-3 */
 
 /**
  * Macro to build the vertical 16 bits version of vc1_put_shift[13].
@@ -126,51 +112,58 @@ void ff_vc1_avg_hor_16b_shift2_sse2(uint8_t *dst, x86_reg 
stride,
  */
 #define MSPEL_FILTER13_VER_16B(NAME, A1, A2, A3, A4)                    \
 static void                                                             \
-vc1_put_ver_16b_ ## NAME ## _mmx(int16_t *dst, const uint8_t *src,      \
-                                 x86_reg src_stride,                   \
-                                 int rnd, int64_t shift)                \
+vc1_put_ver_16b_ ## NAME ## _sse2(int16_t *dst, const uint8_t *src,     \
+                                  x86_reg src_stride,                   \
+                                  int rnd, int64_t shift)               \
 {                                                                       \
     int h = 8;                                                          \
+    /* psraw with an XMM destination reads a 128-bit memory operand; */ \
+    /* hold the 64-bit shift in a 16-byte object to keep that read   */ \
+    /* in bounds. */                                                    \
+    DECLARE_ALIGNED(16, int64_t, shift_buf)[2] = { shift, 0 };          \
     src -= src_stride;                                                  \
     __asm__ volatile(                                                       \
+        "pxor      %%xmm0, %%xmm0  \n\t" /* zero for unpacking */       \
         LOAD_ROUNDER_MMX("%5")                                          \
-        "movq      "MANGLE(ff_pw_53)", %%mm5\n\t"                       \
-        "movq      "MANGLE(ff_pw_18)", %%mm6\n\t"                       \
+        "movq      "MANGLE(ff_pw_53)", %%xmm5\n\t"                      \
+        "punpcklqdq %%xmm5, %%xmm5      \n\t" /* ff_pw_53 is 8 bytes */ \
+        "movdqu    "MANGLE(ff_pw_18)", %%xmm6\n\t"                      \
         ".p2align 3                \n\t"                                \
         "1:                        \n\t"                                \
-        MSPEL_FILTER13_CORE(DO_UNPACK, "movd  1", A1, A2, A3, A4)       \
+        MSPEL_FILTER13_CORE(DO_UNPACK, "movq  1", A1, A2, A3, A4)       \
         NORMALIZE_MMX("%6")                                             \
-        TRANSFER_DONT_PACK(OP_PUT)                                      \
+        "movdqu    %%xmm3, 0(%2)   \n\t"                                \
         /* Last 3 (in fact 4) bytes on the line */                      \
-        "movd      8+"A1", %%mm1   \n\t"                                \
-        DO_UNPACK("%%mm1")                                              \
-        "movq      %%mm1, %%mm3    \n\t"                                \
-        "paddw     %%mm1, %%mm1    \n\t"                                \
-        "paddw     %%mm3, %%mm1    \n\t" /* 3* */                       \
-        "movd      8+"A2", %%mm3   \n\t"                                \
-        DO_UNPACK("%%mm3")                                              \
-        "pmullw    %%mm6, %%mm3    \n\t" /* *18 */                      \
-        "psubw     %%mm1, %%mm3    \n\t" /*18,-3 */                     \
-        "movd      8+"A3", %%mm1   \n\t"                                \
-        DO_UNPACK("%%mm1")                                              \
-        "pmullw    %%mm5, %%mm1    \n\t" /* *53 */                      \
-        "paddw     %%mm1, %%mm3    \n\t" /*53,18,-3 */                  \
-        "movd      8+"A4", %%mm1   \n\t"                                \
-        DO_UNPACK("%%mm1")                                              \
-        "psllw     $2, %%mm1       \n\t" /* 4* */                       \
-        "psubw     %%mm1, %%mm3    \n\t"                                \
-        "paddw     %%mm7, %%mm3    \n\t"                                \
-        "psraw     %6, %%mm3       \n\t"                                \
-        "movq      %%mm3, 16(%2)   \n\t"                                \
+        "movd      8+"A1", %%xmm1  \n\t"                                \
+        DO_UNPACK("%%xmm1")                                             \
+        "movq      %%xmm1, %%xmm3  \n\t"                                \
+        "paddw     %%xmm1, %%xmm1  \n\t"                                \
+        "paddw     %%xmm3, %%xmm1  \n\t" /* 3* */                       \
+        "movd      8+"A2", %%xmm3  \n\t"                                \
+        DO_UNPACK("%%xmm3")                                             \
+        "pmullw    %%xmm6, %%xmm3  \n\t" /* *18 */                      \
+        "psubw     %%xmm1, %%xmm3  \n\t" /*18,-3 */                     \
+        "movd      8+"A3", %%xmm1  \n\t"                                \
+        DO_UNPACK("%%xmm1")                                             \
+        "pmullw    %%xmm5, %%xmm1  \n\t" /* *53 */                      \
+        "paddw     %%xmm1, %%xmm3  \n\t" /*53,18,-3 */                  \
+        "movd      8+"A4", %%xmm1  \n\t"                                \
+        DO_UNPACK("%%xmm1")                                             \
+        "psllw     $2, %%xmm1      \n\t" /* 4* */                       \
+        "psubw     %%xmm1, %%xmm3  \n\t"                                \
+        "paddw     %%xmm7, %%xmm3  \n\t"                                \
+        "psraw     %6, %%xmm3      \n\t"                                \
+        "movq      %%xmm3, 16(%2)  \n\t"                                \
         "add       %3, %1          \n\t"                                \
         "add       $24, %2         \n\t"                                \
         "decl      %0              \n\t"                                \
         "jnz 1b                    \n\t"                                \
         : "+r"(h), "+r" (src),  "+r" (dst)                              \
         : "r"(src_stride), "r"(3*src_stride),                           \
-          "m"(rnd), "m"(shift)                                          \
+          "m"(rnd), "m"(shift_buf[0])                                   \
           NAMED_CONSTRAINTS_ADD(ff_pw_3,ff_pw_53,ff_pw_18)              \
-        : "memory"                                                      \
+        : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3",              \
+                       "%xmm4", "%xmm5", "%xmm6", "%xmm7",) "memory"    \
     );                                                                  \
 }
 
@@ -183,7 +176,7 @@ vc1_put_ver_16b_ ## NAME ## _mmx(int16_t *dst, const 
uint8_t *src,      \
  */
 #define MSPEL_FILTER13_HOR_16B(NAME, A1, A2, A3, A4, OP, OPNAME)        \
 static void                                                             \
-OPNAME ## vc1_hor_16b_ ## NAME ## _mmx(uint8_t *dst, x86_reg stride,    \
+OPNAME ## vc1_hor_16b_ ## NAME ## _sse2(uint8_t *dst, x86_reg stride,   \
                                  const int16_t *src, int rnd)           \
 {                                                                       \
     int h = 8;                                                          \
@@ -191,15 +184,20 @@ OPNAME ## vc1_hor_16b_ ## NAME ## _mmx(uint8_t *dst, 
x86_reg stride,    \
     rnd -= (-4+58+13-3)*256; /* Add -256 bias */                        \
     __asm__ volatile(                                                       \
         LOAD_ROUNDER_MMX("%4")                                          \
-        "movq      "MANGLE(ff_pw_18)", %%mm6   \n\t"                    \
-        "movq      "MANGLE(ff_pw_53)", %%mm5   \n\t"                    \
+        /* ff_pw_128 is 8 bytes; broadcast it into xmm4, which the */   \
+        /* widened loop never writes except here. xmm0 cannot be */     \
+        /* used: OP_AVG clobbers it in TRANSFER_DO_PACK. */             \
+        "movq      "MANGLE(ff_pw_128)", %%xmm4 \n\t"                    \
+        "punpcklqdq %%xmm4, %%xmm4      \n\t"                           \
+        "movdqu    "MANGLE(ff_pw_18)", %%xmm6  \n\t"                    \
+        "movq      "MANGLE(ff_pw_53)", %%xmm5  \n\t"                    \
+        "punpcklqdq %%xmm5, %%xmm5      \n\t" /* ff_pw_53 is 8 bytes */ \
         ".p2align 3                \n\t"                                \
         "1:                        \n\t"                                \
-        MSPEL_FILTER13_CORE(DONT_UNPACK, "movq 2", A1, A2, A3, A4)      \
+        MSPEL_FILTER13_CORE(DONT_UNPACK, "movdqu 1", A1, A2, A3, A4)    \
         NORMALIZE_MMX("$7")                                             \
         /* Remove bias */                                               \
-        "paddw     "MANGLE(ff_pw_128)", %%mm3  \n\t"                    \
-        "paddw     "MANGLE(ff_pw_128)", %%mm4  \n\t"                    \
+        "paddw     %%xmm4, %%xmm3      \n\t"                            \
         TRANSFER_DO_PACK(OP)                                            \
         "add       $24, %1         \n\t"                                \
         "add       %3, %2          \n\t"                                \
@@ -208,7 +206,8 @@ OPNAME ## vc1_hor_16b_ ## NAME ## _mmx(uint8_t *dst, 
x86_reg stride,    \
         : "+r"(h), "+r" (src),  "+r" (dst)                              \
         : "r"(stride), "m"(rnd)                                         \
           NAMED_CONSTRAINTS_ADD(ff_pw_3,ff_pw_18,ff_pw_53,ff_pw_128)    \
-        : "memory"                                                      \
+        : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3",              \
+                       "%xmm4", "%xmm5", "%xmm6", "%xmm7",) "memory"    \
     );                                                                  \
 }
 
@@ -241,14 +240,9 @@ static void OP ## vc1_mspel_mc(uint8_t *dst, const uint8_t 
*src, ptrdiff_t strid
                                int hmode, int vmode, int rnd)\
 {\
     static const vc1_mspel_mc_filter_ver_16bits vc1_put_shift_ver_16bits[] =\
-         { NULL, vc1_put_ver_16b_shift1_mmx, ff_vc1_put_ver_16b_shift2_sse2, 
vc1_put_ver_16b_shift3_mmx };\
+         { NULL, vc1_put_ver_16b_shift1_sse2, ff_vc1_put_ver_16b_shift2_sse2, 
vc1_put_ver_16b_shift3_sse2 };\
     static const vc1_mspel_mc_filter_hor_16bits vc1_put_shift_hor_16bits[] =\
-         { NULL, OP ## vc1_hor_16b_shift1_mmx, ff_vc1_ ## OP ## 
hor_16b_shift2_sse2, OP ## vc1_hor_16b_shift3_mmx };\
-\
-    __asm__ volatile(\
-        "pxor %%mm0, %%mm0         \n\t"\
-        ::: "memory"\
-    );\
+         { NULL, OP ## vc1_hor_16b_shift1_sse2, ff_vc1_ ## OP ## 
hor_16b_shift2_sse2, OP ## vc1_hor_16b_shift3_sse2 };\
 \
             static const int shift_value[] = { 0, 5, 1, 5 };\
             int              shift = 
(shift_value[hmode]+shift_value[vmode])>>1;\
@@ -275,31 +269,31 @@ VC1_MSPEL_MC(avg_)
 
 /** Macro to ease bicubic filter interpolation functions declarations */
 #define DECLARE_FUNCTION(a, b)                                          \
-static void put_vc1_mspel_mc ## a ## b ## _mmx(uint8_t *dst,            \
-                                               const uint8_t *src,      \
-                                               ptrdiff_t stride,        \
-                                               int rnd)                 \
+static void put_vc1_mspel_mc ## a ## b ## _sse2(uint8_t *dst,           \
+                                                const uint8_t *src,     \
+                                                ptrdiff_t stride,       \
+                                                int rnd)                \
 {                                                                       \
      put_vc1_mspel_mc(dst, src, stride, a, b, rnd);                     \
 }\
-static void avg_vc1_mspel_mc ## a ## b ## _mmxext(uint8_t *dst,         \
-                                                  const uint8_t *src,   \
-                                                  ptrdiff_t stride,     \
-                                                  int rnd)              \
+static void avg_vc1_mspel_mc ## a ## b ## _sse2(uint8_t *dst,           \
+                                                 const uint8_t *src,    \
+                                                 ptrdiff_t stride,      \
+                                                 int rnd)               \
 {                                                                       \
      avg_vc1_mspel_mc(dst, src, stride, a, b, rnd);                     \
 }\
-static void put_vc1_mspel_mc ## a ## b ## _16_mmx(uint8_t *dst,         \
-                                                  const uint8_t *src,   \
-                                                  ptrdiff_t stride,     \
-                                                  int rnd)              \
+static void put_vc1_mspel_mc ## a ## b ## _16_sse2(uint8_t *dst,        \
+                                                   const uint8_t *src,  \
+                                                   ptrdiff_t stride,    \
+                                                   int rnd)             \
 {                                                                       \
      put_vc1_mspel_mc_16(dst, src, stride, a, b, rnd);                  \
 }\
-static void avg_vc1_mspel_mc ## a ## b ## _16_mmxext(uint8_t *dst,      \
-                                                     const uint8_t *src,\
-                                                     ptrdiff_t stride,  \
-                                                     int rnd)           \
+static void avg_vc1_mspel_mc ## a ## b ## _16_sse2(uint8_t *dst,        \
+                                                    const uint8_t *src, \
+                                                    ptrdiff_t stride,   \
+                                                    int rnd)            \
 {                                                                       \
      avg_vc1_mspel_mc_16(dst, src, stride, a, b, rnd);                  \
 }
@@ -320,33 +314,30 @@ DECLARE_FUNCTION(3, 3)
     dsp->OP##vc1_mspel_pixels_tab[1][X+4*Y] = OP##vc1_mspel_mc##X##Y##INSN; \
     dsp->OP##vc1_mspel_pixels_tab[0][X+4*Y] = OP##vc1_mspel_mc##X##Y##_16##INSN
 
-av_cold void ff_vc1dsp_init_mmx(VC1DSPContext *dsp)
+av_cold void ff_vc1dsp_init_sse2(VC1DSPContext *dsp)
 {
-    FN_ASSIGN(put_, 1, 1, _mmx);
-    FN_ASSIGN(put_, 1, 2, _mmx);
-    FN_ASSIGN(put_, 1, 3, _mmx);
+    FN_ASSIGN(put_, 1, 1, _sse2);
+    FN_ASSIGN(put_, 1, 2, _sse2);
+    FN_ASSIGN(put_, 1, 3, _sse2);
 
-    FN_ASSIGN(put_, 2, 1, _mmx);
-    FN_ASSIGN(put_, 2, 2, _mmx);
-    FN_ASSIGN(put_, 2, 3, _mmx);
+    FN_ASSIGN(put_, 2, 1, _sse2);
+    FN_ASSIGN(put_, 2, 2, _sse2);
+    FN_ASSIGN(put_, 2, 3, _sse2);
 
-    FN_ASSIGN(put_, 3, 1, _mmx);
-    FN_ASSIGN(put_, 3, 2, _mmx);
-    FN_ASSIGN(put_, 3, 3, _mmx);
+    FN_ASSIGN(put_, 3, 1, _sse2);
+    FN_ASSIGN(put_, 3, 2, _sse2);
+    FN_ASSIGN(put_, 3, 3, _sse2);
+
+    FN_ASSIGN(avg_, 1, 1, _sse2);
+    FN_ASSIGN(avg_, 1, 2, _sse2);
+    FN_ASSIGN(avg_, 1, 3, _sse2);
+
+    FN_ASSIGN(avg_, 2, 1, _sse2);
+    FN_ASSIGN(avg_, 2, 2, _sse2);
+    FN_ASSIGN(avg_, 2, 3, _sse2);
+
+    FN_ASSIGN(avg_, 3, 1, _sse2);
+    FN_ASSIGN(avg_, 3, 2, _sse2);
+    FN_ASSIGN(avg_, 3, 3, _sse2);
 }
-
-av_cold void ff_vc1dsp_init_mmxext(VC1DSPContext *dsp)
-{
-    FN_ASSIGN(avg_, 1, 1, _mmxext);
-    FN_ASSIGN(avg_, 1, 2, _mmxext);
-    FN_ASSIGN(avg_, 1, 3, _mmxext);
-
-    FN_ASSIGN(avg_, 2, 1, _mmxext);
-    FN_ASSIGN(avg_, 2, 2, _mmxext);
-    FN_ASSIGN(avg_, 2, 3, _mmxext);
-
-    FN_ASSIGN(avg_, 3, 1, _mmxext);
-    FN_ASSIGN(avg_, 3, 2, _mmxext);
-    FN_ASSIGN(avg_, 3, 3, _mmxext);
-}
-#endif /* HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_MMX_EXTERNAL */
+#endif /* HAVE_X86_6REGS && HAVE_INLINE_ASM && HAVE_SSE2_EXTERNAL */
diff --git a/tests/checkasm/vc1dsp.c b/tests/checkasm/vc1dsp.c
index 52049a4aa35..532fcae63b4 100644
--- a/tests/checkasm/vc1dsp.c
+++ b/tests/checkasm/vc1dsp.c
@@ -483,7 +483,7 @@ static void check_mspel_pixels(void)
             for (unsigned dxy = 0; dxy < 16; ++dxy) {
                 if (!check_func(func[j][dxy], "vc1dsp.%s_mc%u%u_%u", 
tests[k].name, dxy & 3, dxy >> 2, blocksize))
                     continue;
-                declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, const 
uint8_t*, ptrdiff_t, int);
+                declare_func(void, uint8_t *, const uint8_t*, ptrdiff_t, int);
                 size_t dst_offset = (rnd() % (MAX_BLOCK_SIZE / blocksize)) * 
blocksize;
                 ptrdiff_t stride  = (rnd() % (MAX_STRIDE / blocksize) + 1) * 
blocksize;
                 size_t src_offset = 1 + stride + rnd() % MAX_BLOCK_SIZE;
-- 
2.54.0


From 43abf0801bcbc0bad832ad9abcdb803c0b49304c Mon Sep 17 00:00:00 2001
From: Zuxy Meng <[email protected]>
Date: Mon, 2 Nov 2026 19:46:51 -0800
Subject: [PATCH 3/3] avcodec/x86/vc1: clean up remaining references to MMX

The shift2 filters in vc1dsp_mc.asm are SSE2 code whose callers in
vc1dsp_mmx.c are built only with SSE2 inline-asm support, so gate
the asm block on HAVE_SSE2_INLINE instead of the stale
HAVE_MMX_INLINE.

Also clean up the macro namespace: drop the _MMX suffix from the
LOAD_ROUNDER and NORMALIZE macros (both the NASM and inline-asm
copies), remove the unused NASM NORMALIZE_MMX, TRANSFER_DO_PACK,
TRANSFER_DONT_PACK, DO_UNPACK, and DONT_UNPACK macros, and update
the header comment in vc1dsp_init.c to SSE2-optimized. No generated
code changes.

checkasm --test=vc1dsp passes (109/109).

Signed-off-by: Zuxy Meng <[email protected]>
---
 libavcodec/x86/vc1dsp_init.c |  2 +-
 libavcodec/x86/vc1dsp_mc.asm | 44 ++++--------------------------------
 libavcodec/x86/vc1dsp_mmx.c  | 12 +++++-----
 3 files changed, 12 insertions(+), 46 deletions(-)

diff --git a/libavcodec/x86/vc1dsp_init.c b/libavcodec/x86/vc1dsp_init.c
index 5f6b7f55564..0bafc28757e 100644
--- a/libavcodec/x86/vc1dsp_init.c
+++ b/libavcodec/x86/vc1dsp_init.c
@@ -1,5 +1,5 @@
 /*
- * VC-1 and WMV3 - DSP functions MMX-optimized
+ * VC-1 and WMV3 - DSP functions SSE2-optimized
  * Copyright (c) 2007 Christophe GISQUET <[email protected]>
  *
  * Permission is hereby granted, free of charge, to any person
diff --git a/libavcodec/x86/vc1dsp_mc.asm b/libavcodec/x86/vc1dsp_mc.asm
index 35a790811b4..2b403a9ccc4 100644
--- a/libavcodec/x86/vc1dsp_mc.asm
+++ b/libavcodec/x86/vc1dsp_mc.asm
@@ -37,10 +37,7 @@ cextern pw_128
 
 SECTION .text
 
-%if HAVE_MMX_INLINE
-
-; XXX some of these macros are not used right now, but they will in the future
-;     when more functions are ported.
+%if HAVE_SSE2_INLINE
 
 %macro OP_PUT 2 ; dst, src
 %endmacro
@@ -50,39 +47,8 @@ SECTION .text
     pavgb           %1, m0
 %endmacro
 
-%macro NORMALIZE_MMX 1 ; shift
-    paddw           m3, m7 ; +bias-r
-    paddw           m4, m7 ; +bias-r
-    psraw           m3, %1
-    psraw           m4, %1
-%endmacro
-
-%macro TRANSFER_DO_PACK 2 ; op, dst
-    packuswb        m3, m4
-    ; Only the low 4 words of m3/m4 hold valid data; the second and
-    ; fourth dwords of the packed result are garbage. Shuffle the two
-    ; valid dwords together so a single 8-byte store writes them.
-    pshufd          m3, m3, 0x08
-    %1              m3, [%2]
-    movq          [%2], m3
-%endmacro
-
-%macro TRANSFER_DONT_PACK 2 ; op, dst
-    %1              m3, [%2]
-    %1              m3, [%2 + 8]
-    movq          [%2], m3
-    movq      [8 + %2], m4
-%endmacro
-
-; see MSPEL_FILTER13_CORE for use as UNPACK macro
-%macro DO_UNPACK 1 ; reg
-    punpcklbw       %1, m0
-%endmacro
-%macro DONT_UNPACK 1 ; reg
-%endmacro
-
 ; Compute the rounder 32-r or 8-r and unpacks it to m7
-%macro LOAD_ROUNDER_MMX 1 ; round
+%macro LOAD_ROUNDER 1 ; round
     movd      m7, %1
     punpcklwd m7, m7
     punpckldq m7, m7
@@ -156,7 +122,7 @@ cglobal vc1_put_ver_16b_shift2, 4,7,8, dst, src, stride
     neg       stride_neg2
     add       stride_neg2, stride_neg2
     lea    stride_9minus8, [strideq * 9 - 8]
-    LOAD_ROUNDER_MMX  rnd
+    LOAD_ROUNDER      rnd
     pshufd             m7, m7, 0
     mova               m6, [pw_9]
     pxor               m0, m0
@@ -179,7 +145,7 @@ cglobal vc1_%2_hor_16b_shift2, 4, 5, 8, dst, stride, src, 
rnd, h
     mov                hq, 8
     sub              srcq, 2
     sub              rndd, (-1+9+9-1) * 1024 ; add -1024 bias
-    LOAD_ROUNDER_MMX rndd
+    LOAD_ROUNDER     rndd
     pshufd             m7, m7, 0
     mova               m5, [pw_9]
     movq               m6, [pw_128]
@@ -214,7 +180,7 @@ HOR_16B_SHIFT2 OP_PUT, put
 
 INIT_XMM sse2
 HOR_16B_SHIFT2 OP_AVG, avg
-%endif ; HAVE_MMX_INLINE
+%endif ; HAVE_SSE2_INLINE
 
 %define MOV8  movq
 %define MOV16 movu
diff --git a/libavcodec/x86/vc1dsp_mmx.c b/libavcodec/x86/vc1dsp_mmx.c
index 57ca1465060..19ceb987e68 100644
--- a/libavcodec/x86/vc1dsp_mmx.c
+++ b/libavcodec/x86/vc1dsp_mmx.c
@@ -48,7 +48,7 @@ void ff_vc1_avg_hor_16b_shift2_sse2(uint8_t *dst, x86_reg 
stride,
                     "pavgb %%xmm0, " #D "     \n\t"
 
 /** Add rounder from xmm7 to xmm3 and pack result at destination. */
-#define NORMALIZE_MMX(SHIFT)                                    \
+#define NORMALIZE(SHIFT)                                        \
      "paddw     %%xmm7, %%xmm3         \n\t" /* +bias-r */      \
      "psraw     "SHIFT", %%xmm3        \n\t"
 
@@ -64,7 +64,7 @@ void ff_vc1_avg_hor_16b_shift2_sse2(uint8_t *dst, x86_reg 
stride,
 #define DONT_UNPACK(reg)
 
 /** Compute the rounder 32-r or 8-r and unpacks it to xmm7. */
-#define LOAD_ROUNDER_MMX(ROUND)                 \
+#define LOAD_ROUNDER(ROUND)                     \
      "movd      "ROUND", %%xmm7        \n\t"    \
      "punpcklwd %%xmm7, %%xmm7         \n\t"    \
      "punpckldq %%xmm7, %%xmm7         \n\t"    \
@@ -124,14 +124,14 @@ vc1_put_ver_16b_ ## NAME ## _sse2(int16_t *dst, const 
uint8_t *src,     \
     src -= src_stride;                                                  \
     __asm__ volatile(                                                       \
         "pxor      %%xmm0, %%xmm0  \n\t" /* zero for unpacking */       \
-        LOAD_ROUNDER_MMX("%5")                                          \
+        LOAD_ROUNDER("%5")                                              \
         "movq      "MANGLE(ff_pw_53)", %%xmm5\n\t"                      \
         "punpcklqdq %%xmm5, %%xmm5      \n\t" /* ff_pw_53 is 8 bytes */ \
         "movdqu    "MANGLE(ff_pw_18)", %%xmm6\n\t"                      \
         ".p2align 3                \n\t"                                \
         "1:                        \n\t"                                \
         MSPEL_FILTER13_CORE(DO_UNPACK, "movq  1", A1, A2, A3, A4)       \
-        NORMALIZE_MMX("%6")                                             \
+        NORMALIZE("%6")                                                 \
         "movdqu    %%xmm3, 0(%2)   \n\t"                                \
         /* Last 3 (in fact 4) bytes on the line */                      \
         "movd      8+"A1", %%xmm1  \n\t"                                \
@@ -183,7 +183,7 @@ OPNAME ## vc1_hor_16b_ ## NAME ## _sse2(uint8_t *dst, 
x86_reg stride,   \
     src -= 1;                                                           \
     rnd -= (-4+58+13-3)*256; /* Add -256 bias */                        \
     __asm__ volatile(                                                       \
-        LOAD_ROUNDER_MMX("%4")                                          \
+        LOAD_ROUNDER("%4")                                              \
         /* ff_pw_128 is 8 bytes; broadcast it into xmm4, which the */   \
         /* widened loop never writes except here. xmm0 cannot be */     \
         /* used: OP_AVG clobbers it in TRANSFER_DO_PACK. */             \
@@ -195,7 +195,7 @@ OPNAME ## vc1_hor_16b_ ## NAME ## _sse2(uint8_t *dst, 
x86_reg stride,   \
         ".p2align 3                \n\t"                                \
         "1:                        \n\t"                                \
         MSPEL_FILTER13_CORE(DONT_UNPACK, "movdqu 1", A1, A2, A3, A4)    \
-        NORMALIZE_MMX("$7")                                             \
+        NORMALIZE("$7")                                                 \
         /* Remove bias */                                               \
         "paddw     %%xmm4, %%xmm3      \n\t"                            \
         TRANSFER_DO_PACK(OP)                                            \
-- 
2.54.0

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

Reply via email to