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


>From e975658c69802e546dd84397878fec31ab0903f4 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 7 Aug 2026 01:07:35 +0200
Subject: [PATCH 1/9] tests/checkasm: Add ttadsp test

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 tests/checkasm/Makefile   |  1 +
 tests/checkasm/checkasm.c |  3 ++
 tests/checkasm/checkasm.h |  1 +
 tests/checkasm/ttadsp.c   | 74 +++++++++++++++++++++++++++++++++++++++
 tests/fate/checkasm.mak   |  1 +
 5 files changed, 80 insertions(+)
 create mode 100644 tests/checkasm/ttadsp.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index c154d19ed4..7f9b78dfca 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -55,6 +55,7 @@ AVCODECOBJS-$(CONFIG_SBC_ENCODER)       += sbcdsp.o
 AVCODECOBJS-$(CONFIG_SNOW_DECODER)      += snowdsp.o
 AVCODECOBJS-$(CONFIG_SVQ1_ENCODER)      += svq1enc.o
 AVCODECOBJS-$(CONFIG_TAK_DECODER)       += takdsp.o
+AVCODECOBJS-$(CONFIG_TTA_DECODER)       += ttadsp.o
 AVCODECOBJS-$(CONFIG_UTVIDEO_DECODER)   += utvideodsp.o
 AVCODECOBJS-$(CONFIG_V210_DECODER)      += v210dec.o
 AVCODECOBJS-$(CONFIG_V210_ENCODER)      += v210enc.o
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index a8cad59d4c..320f0a9338 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -202,6 +202,9 @@ static const CheckasmTest tests[] = {
     #if CONFIG_TAK_DECODER
         { "takdsp", checkasm_check_takdsp },
     #endif
+    #if CONFIG_TTA_DECODER
+        { "ttadsp", checkasm_check_ttadsp },
+    #endif
     #if CONFIG_UTVIDEO_DECODER
         { "utvideodsp", checkasm_check_utvideodsp },
     #endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 5ba4080d69..549911c3e3 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -106,6 +106,7 @@ void checkasm_check_sw_yuv2rgb(void);
 void checkasm_check_sw_yuv2yuv(void);
 void checkasm_check_sw_ops(void);
 void checkasm_check_takdsp(void);
+void checkasm_check_ttadsp(void);
 void checkasm_check_utvideodsp(void);
 void checkasm_check_v210dec(void);
 void checkasm_check_v210enc(void);
diff --git a/tests/checkasm/ttadsp.c b/tests/checkasm/ttadsp.c
new file mode 100644
index 0000000000..5dd44eb77f
--- /dev/null
+++ b/tests/checkasm/ttadsp.c
@@ -0,0 +1,74 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <string.h>
+
+#include "checkasm.h"
+
+#include "libavcodec/ttadata.h"
+#include "libavcodec/ttadsp.h"
+#include "libavutil/mem_internal.h"
+
+#define randomize_buffer(NAME)                                \
+do {                                                          \
+    checkasm_randomize(NAME ## _ref, sizeof(NAME ## _ref));   \
+    memcpy(NAME ## _new, NAME ## _ref, sizeof(NAME ## _new)); \
+} while (0)
+
+static void check_filter_process(void)
+{
+    DECLARE_ALIGNED_16(int32_t, qm_ref)[MAX_ORDER];
+    DECLARE_ALIGNED_16(int32_t, dx_ref)[MAX_ORDER];
+    DECLARE_ALIGNED_16(int32_t, dl_ref)[MAX_ORDER];
+    DECLARE_ALIGNED_16(int32_t, qm_new)[MAX_ORDER];
+    DECLARE_ALIGNED_16(int32_t, dx_new)[MAX_ORDER];
+    DECLARE_ALIGNED_16(int32_t, dl_new)[MAX_ORDER];
+    int bps = 1 + rnd() % 3;
+    int32_t shift = ff_tta_filter_configs[bps - 1], round = 
ff_tta_shift_1[shift - 1];
+    int32_t in_ref = rnd(), in_new = in_ref;
+    int32_t error_ref = rnd(), error_new = error_ref;
+
+    declare_func(void, int32_t *qm, int32_t *dx, int32_t *dl, int32_t *error,
+                       int32_t *in, int32_t shift, int32_t round);
+
+    randomize_buffer(qm);
+    randomize_buffer(dx);
+    randomize_buffer(dl);
+
+    call_ref(qm_ref, dx_ref, dl_ref, &error_ref, &in_ref, shift, round);
+    call_new(qm_new, dx_new, dl_new, &error_new, &in_new, shift, round);
+
+    if (in_ref != in_new || error_ref != error_new ||
+        memcmp(qm_ref, qm_new, sizeof(qm_ref))     ||
+        memcmp(dx_ref, dx_new, sizeof(dx_ref))     ||
+        memcmp(dl_ref, dl_new, sizeof(dl_ref)))
+        fail();
+#define alt(var) checkasm_alternate(var ## _ref, var ## _new)
+    bench_new(alt(qm), alt(dx), alt(dl), alt(&error), alt(&in), shift, round);
+}
+
+void checkasm_check_ttadsp(void)
+{
+    TTADSPContext ttadsp;
+
+    ff_ttadsp_init(&ttadsp);
+
+    if (check_func(ttadsp.filter_process, "filter_process"))
+        check_filter_process();
+    report("filter_process");
+}
diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak
index 249fb91d4f..082ff99bb8 100644
--- a/tests/fate/checkasm.mak
+++ b/tests/fate/checkasm.mak
@@ -69,6 +69,7 @@ FATE_CHECKASM = fate-checkasm-aacencdsp                       
          \
                 fate-checkasm-sw_yuv2rgb                                \
                 fate-checkasm-sw_yuv2yuv                                \
                 fate-checkasm-takdsp                                    \
+                fate-checkasm-ttadsp                                    \
                 fate-checkasm-utvideodsp                                \
                 fate-checkasm-v210dec                                   \
                 fate-checkasm-v210enc                                   \
-- 
2.52.0


>From c72ee7b16f6e55d48cfe81f46563797dd0a0f561 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 7 Aug 2026 01:08:56 +0200
Subject: [PATCH 2/9] avcodec/ttadata: Don't use too big arrays

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/ttadata.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/ttadata.h b/libavcodec/ttadata.h
index 1ec1d749ce..3554817183 100644
--- a/libavcodec/ttadata.h
+++ b/libavcodec/ttadata.h
@@ -23,7 +23,7 @@
 
 #include <stdint.h>
 
-#define MAX_ORDER 16
+#define MAX_ORDER 8
 typedef struct TTAFilter {
     int32_t shift, round, error;
     int32_t qm[MAX_ORDER];
-- 
2.52.0


>From d986012672952d3e93ad2618a6504e9fb8c2f02c Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 7 Aug 2026 01:14:50 +0200
Subject: [PATCH 3/9] avcodec/ttadata: Explicitly specify alignment

x86 assembly relies on it.

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

diff --git a/libavcodec/ttadata.h b/libavcodec/ttadata.h
index 3554817183..2f1b662bad 100644
--- a/libavcodec/ttadata.h
+++ b/libavcodec/ttadata.h
@@ -23,12 +23,14 @@
 
 #include <stdint.h>
 
+#include "libavutil/mem_internal.h"
+
 #define MAX_ORDER 8
 typedef struct TTAFilter {
-    int32_t shift, round, error;
     int32_t qm[MAX_ORDER];
     int32_t dx[MAX_ORDER];
     int32_t dl[MAX_ORDER];
+    int32_t shift, round, error;
 } TTAFilter;
 
 typedef struct TTARice {
@@ -36,8 +38,8 @@ typedef struct TTARice {
 } TTARice;
 
 typedef struct TTAChannel {
+    DECLARE_ALIGNED_16(TTAFilter, filter);
     int32_t predictor;
-    TTAFilter filter;
     TTARice rice;
 } TTAChannel;
 
-- 
2.52.0


>From bb0f3ca3d39640135be9a69309a889055988df80 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 7 Aug 2026 01:23:54 +0200
Subject: [PATCH 4/9] avcodec/x86/ttaencdsp: Merge into ttadsp

This allows to avoid duplication of (source) code and constants.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/x86/Makefile      |   2 +-
 libavcodec/x86/ttadsp.asm    |  23 ++++++-
 libavcodec/x86/ttaencdsp.asm | 119 -----------------------------------
 3 files changed, 22 insertions(+), 122 deletions(-)
 delete mode 100644 libavcodec/x86/ttaencdsp.asm

diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index b85fa7e1cc..85a01af5c5 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -177,7 +177,7 @@ X86ASM-OBJS-$(CONFIG_SVQ1_ENCODER)     += x86/svq1enc.o
 X86ASM-OBJS-$(CONFIG_TAK_DECODER)      += x86/takdsp.o
 X86ASM-OBJS-$(CONFIG_TRUEHD_DECODER)   += x86/mlpdsp.o
 X86ASM-OBJS-$(CONFIG_TTA_DECODER)      += x86/ttadsp.o
-X86ASM-OBJS-$(CONFIG_TTA_ENCODER)      += x86/ttaencdsp.o
+X86ASM-OBJS-$(CONFIG_TTA_ENCODER)      += x86/ttadsp.o
 X86ASM-OBJS-$(CONFIG_UTVIDEO_DECODER)  += x86/utvideodsp.o
 X86ASM-OBJS-$(CONFIG_V210_ENCODER)     += x86/v210enc.o
 X86ASM-OBJS-$(CONFIG_V210_DECODER)     += x86/v210.o
diff --git a/libavcodec/x86/ttadsp.asm b/libavcodec/x86/ttadsp.asm
index db12a32eca..f4b9fa831d 100644
--- a/libavcodec/x86/ttadsp.asm
+++ b/libavcodec/x86/ttadsp.asm
@@ -20,6 +20,8 @@
 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 ;******************************************************************************
 
+%include "config_components.asm"
+
 %include "libavutil/x86/x86util.asm"
 
 SECTION_RODATA
@@ -29,9 +31,9 @@ pd_1224:  dd 1, 2, 2, 4
 
 SECTION .text
 
-%macro TTA_FILTER 2
+%macro TTA_FILTER 2-3
 INIT_XMM %1
-cglobal tta_filter_process, 5,5,%2, qm, dx, dl, error, in, shift, round
+cglobal tta%3_filter_process, 5,5,%2, qm, dx, dl, error, in, shift, round
     mova       m2, [qmq       ]
     mova       m3, [qmq + 0x10]
     mova       m4, [dxq       ]
@@ -94,6 +96,15 @@ cglobal tta_filter_process, 5,5,%2, qm, dx, dl, error, in, 
shift, round
     mova       [dlq       ], m2
     mova       [dxq       ], m5
     mova       [dxq + 0x10], m4
+
+%ifidn %3,enc
+    movd       m2, shiftm           ;
+    movd       m0, [inq]            ;
+    psrad      m6, m2               ;
+    psubd      m3, m0, m6           ;
+    movd       [inq], m3            ; *in -= (sum >> filter->shift);
+    movd       [errorq], m3         ; filter->error = *in;
+%else
     movd       m0, [inq]            ; filter->error = *in;
     movd       [errorq], m0         ;
 
@@ -101,6 +112,7 @@ cglobal tta_filter_process, 5,5,%2, qm, dx, dl, error, in, 
shift, round
     psrad      m6, m2               ;
     paddd      m0, m6               ;
     movd       [inq], m0            ;
+%endif
 
     psrldq     m1, 4                ;
     pslldq     m0, 12               ; filter->dl[4] = -filter->dl[5];
@@ -115,5 +127,12 @@ cglobal tta_filter_process, 5,5,%2, qm, dx, dl, error, in, 
shift, round
     RET
 %endmacro
 
+%if CONFIG_TTA_DECODER
 TTA_FILTER ssse3, 8
 TTA_FILTER sse4,  7
+%endif
+
+%if CONFIG_TTA_ENCODER
+TTA_FILTER ssse3, 8, enc
+TTA_FILTER sse4,  7, enc
+%endif
diff --git a/libavcodec/x86/ttaencdsp.asm b/libavcodec/x86/ttaencdsp.asm
deleted file mode 100644
index c9cbd49874..0000000000
--- a/libavcodec/x86/ttaencdsp.asm
+++ /dev/null
@@ -1,119 +0,0 @@
-;******************************************************************************
-;* TTA Encoder DSP SIMD optimizations
-;*
-;* Copyright (C) 2014-2016 James Almer
-;*
-;* This file is part of FFmpeg.
-;*
-;* FFmpeg is free software; you can redistribute it and/or
-;* modify it under the terms of the GNU Lesser General Public
-;* License as published by the Free Software Foundation; either
-;* version 2.1 of the License, or (at your option) any later version.
-;*
-;* FFmpeg is distributed in the hope that it will be useful,
-;* but WITHOUT ANY WARRANTY; without even the implied warranty of
-;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-;* Lesser General Public License for more details.
-;*
-;* You should have received a copy of the GNU Lesser General Public
-;* License along with FFmpeg; if not, write to the Free Software
-;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-;******************************************************************************
-
-%include "libavutil/x86/x86util.asm"
-
-SECTION_RODATA
-
-pd_n0113: dd ~0, ~1, ~1, ~3
-pd_1224:  dd 1, 2, 2, 4
-
-SECTION .text
-
-%macro TTAENC_FILTER 2
-INIT_XMM %1
-cglobal ttaenc_filter_process, 5,5,%2, qm, dx, dl, error, in, shift, round
-    mova       m2, [qmq       ]
-    mova       m3, [qmq + 0x10]
-    mova       m4, [dxq       ]
-    mova       m5, [dxq + 0x10]
-
-    movd       m6, [errorq]         ; if (filter->error < 0) {
-    SPLATD     m6                   ;     for (int i = 0; i < 8; i++)
-    psignd     m0, m4, m6           ;         filter->qm[i] -= filter->dx[i];
-    psignd     m1, m5, m6           ; } else if (filter->error > 0) {
-    paddd      m2, m0               ;     for (int i = 0; i < 8; i++)
-    paddd      m3, m1               ;         filter->qm[i] += filter->dx[i];
-    mova       [qmq       ], m2     ; }
-    mova       [qmq + 0x10], m3     ;
-
-    mova       m0, [dlq       ]
-    mova       m1, [dlq + 0x10]
-
-%if cpuflag(sse4)
-    pmulld     m2, m0
-    pmulld     m3, m1
-%else
-    pshufd     m6, m0, 0xb1
-    pshufd     m7, m2, 0xb1
-    pmuludq    m6, m7
-    pshufd     m6, m6, 0xd8
-    pmuludq    m2, m0
-    pshufd     m2, m2, 0xd8
-    punpckldq  m2, m6
-
-    pshufd     m6, m1, 0xb1
-    pshufd     m7, m3, 0xb1
-    pmuludq    m6, m7
-    pshufd     m6, m6, 0xd8
-    pmuludq    m3, m1
-    pshufd     m3, m3, 0xd8
-    punpckldq  m3, m6
-%endif
-    ; Using horizontal add (phaddd) seems to be slower than shuffling stuff 
around
-    paddd      m2, m3               ; int sum = filter->round +
-                                    ;           filter->dl[0] * filter->qm[0] +
-    pshufd     m3, m2, 0xe          ;           filter->dl[1] * filter->qm[1] +
-    paddd      m2, m3               ;           filter->dl[2] * filter->qm[2] +
-                                    ;           filter->dl[3] * filter->qm[3] +
-    movd       m6, roundm           ;           filter->dl[4] * filter->qm[4] +
-    paddd      m6, m2               ;           filter->dl[5] * filter->qm[5] +
-    pshufd     m2, m2, 0x1          ;           filter->dl[6] * filter->qm[6] +
-    paddd      m6, m2               ;           filter->dl[7] * filter->qm[7];
-
-    palignr    m5, m4, 4            ; filter->dx[0] = filter->dx[1]; 
filter->dx[1] = filter->dx[2];
-                                    ; filter->dx[2] = filter->dx[3]; 
filter->dx[3] = filter->dx[4];
-
-    palignr    m2, m1, m0, 4        ; filter->dl[0] = filter->dl[1]; 
filter->dl[1] = filter->dl[2];
-                                    ; filter->dl[2] = filter->dl[3]; 
filter->dl[3] = filter->dl[4];
-
-    psrad      m4, m1, 30           ; filter->dx[4] = ((filter->dl[4] >> 30) | 
1);
-    por        m4, [pd_1224 ]       ; filter->dx[5] = ((filter->dl[5] >> 30) | 
2) & ~1;
-    pand       m4, [pd_n0113]       ; filter->dx[6] = ((filter->dl[6] >> 30) | 
2) & ~1;
-                                    ; filter->dx[7] = ((filter->dl[7] >> 30) | 
4) & ~3;
-
-    mova       [dlq       ], m2
-    mova       [dxq       ], m5
-    mova       [dxq + 0x10], m4
-
-    movd       m2, shiftm           ;
-    movd       m0, [inq]            ;
-    psrad      m6, m2               ;
-    psubd      m3, m0, m6           ;
-    movd       [inq], m3            ; *in -= (sum >> filter->shift);
-    movd       [errorq], m3         ; filter->error = *in;
-
-    psrldq     m1, 4                ;
-    pslldq     m0, 12               ; filter->dl[4] = -filter->dl[5];
-    pshufd     m0, m0, 0xf0         ; filter->dl[5] = -filter->dl[6];
-    psubd      m0, m1               ; filter->dl[6] = *in - filter->dl[7];
-    psrldq     m1, m0, 4            ; filter->dl[7] = *in;
-    pshufd     m1, m1, 0xf4         ; filter->dl[5] += filter->dl[6];
-    paddd      m0, m1               ; filter->dl[4] += filter->dl[5];
-    psrldq     m1, 4                ;
-    paddd      m0, m1               ;
-    mova       [dlq + 0x10], m0     ;
-    RET
-%endmacro
-
-TTAENC_FILTER ssse3, 8
-TTAENC_FILTER sse4,  7
-- 
2.52.0


>From f042bdfc272b7eeb89563cc069d1bf52c945ede8 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 7 Aug 2026 01:30:56 +0200
Subject: [PATCH 5/9] avcodec/ttaencdsp: Use unsigned to avoid UB

The decoder has been made to use unsigned values after
the fuzzer encountered signed integer overflow;
the same can probably happen in the encoder (I don't know),
but it definitely can happen in the checkasm test that
will be added soon. So use unsigned here, too.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/ttaencdsp.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/libavcodec/ttaencdsp.c b/libavcodec/ttaencdsp.c
index 0a717313bf..7e4fed0679 100644
--- a/libavcodec/ttaencdsp.c
+++ b/libavcodec/ttaencdsp.c
@@ -20,9 +20,12 @@
 #include "ttaencdsp.h"
 #include "config.h"
 
-static void ttaenc_filter_process_c(int32_t *qm, int32_t *dx, int32_t *dl,
+static void ttaenc_filter_process_c(int32_t *qmi, int32_t *dx, int32_t *dl,
                                     int32_t *error, int32_t *in, int32_t shift,
-                                    int32_t round) {
+                                    int32_t round)
+{
+    uint32_t *qm = qmi;
+
     if (*error < 0) {
         qm[0] -= dx[0]; qm[1] -= dx[1]; qm[2] -= dx[2]; qm[3] -= dx[3];
         qm[4] -= dx[4]; qm[5] -= dx[5]; qm[6] -= dx[6]; qm[7] -= dx[7];
@@ -42,9 +45,9 @@ static void ttaenc_filter_process_c(int32_t *qm, int32_t *dx, 
int32_t *dl,
     dx[6] = ((dl[6] >> 30) | 2) & ~1;
     dx[7] = ((dl[7] >> 30) | 4) & ~3;
 
-    dl[4] = -dl[5]; dl[5] = -dl[6];
-    dl[6] = *in - dl[7]; dl[7] = *in;
-    dl[5] += dl[6]; dl[4] += dl[5];
+    dl[4]  = -(unsigned)dl[5];     dl[5] = -(unsigned)dl[6];
+    dl[6]  = *in -(unsigned)dl[7]; dl[7] = *in;
+    dl[5] += (unsigned)dl[6];      dl[4] += (unsigned)dl[5];
 
     *in -= (round >> shift);
     *error = *in;
-- 
2.52.0


>From 4c845e92d22c53e80fa108881fe4dfdac00ee155 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 7 Aug 2026 01:39:51 +0200
Subject: [PATCH 6/9] tests/checkasm/ttadsp: Also test ttaencdsp

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 tests/checkasm/Makefile   |  1 +
 tests/checkasm/checkasm.c |  3 +++
 tests/checkasm/checkasm.h |  1 +
 tests/checkasm/ttadsp.c   | 18 ++++++++++++++++++
 tests/fate/checkasm.mak   |  1 +
 5 files changed, 24 insertions(+)

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 7f9b78dfca..169b40413b 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -56,6 +56,7 @@ AVCODECOBJS-$(CONFIG_SNOW_DECODER)      += snowdsp.o
 AVCODECOBJS-$(CONFIG_SVQ1_ENCODER)      += svq1enc.o
 AVCODECOBJS-$(CONFIG_TAK_DECODER)       += takdsp.o
 AVCODECOBJS-$(CONFIG_TTA_DECODER)       += ttadsp.o
+AVCODECOBJS-$(CONFIG_TTA_ENCODER)       += ttadsp.o
 AVCODECOBJS-$(CONFIG_UTVIDEO_DECODER)   += utvideodsp.o
 AVCODECOBJS-$(CONFIG_V210_DECODER)      += v210dec.o
 AVCODECOBJS-$(CONFIG_V210_ENCODER)      += v210enc.o
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 320f0a9338..cd837e4f54 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -205,6 +205,9 @@ static const CheckasmTest tests[] = {
     #if CONFIG_TTA_DECODER
         { "ttadsp", checkasm_check_ttadsp },
     #endif
+    #if CONFIG_TTA_ENCODER
+        { "ttaencdsp", checkasm_check_ttaencdsp },
+    #endif
     #if CONFIG_UTVIDEO_DECODER
         { "utvideodsp", checkasm_check_utvideodsp },
     #endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 549911c3e3..331d04b0c2 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -107,6 +107,7 @@ void checkasm_check_sw_yuv2yuv(void);
 void checkasm_check_sw_ops(void);
 void checkasm_check_takdsp(void);
 void checkasm_check_ttadsp(void);
+void checkasm_check_ttaencdsp(void);
 void checkasm_check_utvideodsp(void);
 void checkasm_check_v210dec(void);
 void checkasm_check_v210enc(void);
diff --git a/tests/checkasm/ttadsp.c b/tests/checkasm/ttadsp.c
index 5dd44eb77f..485b785f32 100644
--- a/tests/checkasm/ttadsp.c
+++ b/tests/checkasm/ttadsp.c
@@ -18,10 +18,13 @@
 
 #include <string.h>
 
+#include "config_components.h"
+
 #include "checkasm.h"
 
 #include "libavcodec/ttadata.h"
 #include "libavcodec/ttadsp.h"
+#include "libavcodec/ttaencdsp.h"
 #include "libavutil/mem_internal.h"
 
 #define randomize_buffer(NAME)                                \
@@ -62,6 +65,7 @@ static void check_filter_process(void)
     bench_new(alt(qm), alt(dx), alt(dl), alt(&error), alt(&in), shift, round);
 }
 
+#if CONFIG_TTA_DECODER
 void checkasm_check_ttadsp(void)
 {
     TTADSPContext ttadsp;
@@ -72,3 +76,17 @@ void checkasm_check_ttadsp(void)
         check_filter_process();
     report("filter_process");
 }
+#endif
+
+#if CONFIG_TTA_ENCODER
+void checkasm_check_ttaencdsp(void)
+{
+    TTAEncDSPContext ttaencdsp;
+
+    ff_ttaencdsp_init(&ttaencdsp);
+
+    if (check_func(ttaencdsp.filter_process, "filter_process"))
+        check_filter_process();
+    report("filter_process");
+}
+#endif
diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak
index 082ff99bb8..adc082e39a 100644
--- a/tests/fate/checkasm.mak
+++ b/tests/fate/checkasm.mak
@@ -70,6 +70,7 @@ FATE_CHECKASM = fate-checkasm-aacencdsp                       
          \
                 fate-checkasm-sw_yuv2yuv                                \
                 fate-checkasm-takdsp                                    \
                 fate-checkasm-ttadsp                                    \
+                fate-checkasm-ttaencdsp                                 \
                 fate-checkasm-utvideodsp                                \
                 fate-checkasm-v210dec                                   \
                 fate-checkasm-v210enc                                   \
-- 
2.52.0


>From 429c3bfe566f415dde9616f646e80ee3f690e1c6 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 7 Aug 2026 02:17:46 +0200
Subject: [PATCH 7/9] avcodec/x86/ttadsp: Reduce number of registers used

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

diff --git a/libavcodec/x86/ttadsp.asm b/libavcodec/x86/ttadsp.asm
index f4b9fa831d..fd98ccab34 100644
--- a/libavcodec/x86/ttadsp.asm
+++ b/libavcodec/x86/ttadsp.asm
@@ -39,10 +39,15 @@ cglobal tta%3_filter_process, 5,5,%2, qm, dx, dl, error, 
in, shift, round
     mova       m4, [dxq       ]
     mova       m5, [dxq + 0x10]
 
-    movd       m6, [errorq]         ; if (filter->error < 0) {
-    SPLATD     m6                   ;     for (int i = 0; i < 8; i++)
-    psignd     m0, m4, m6           ;         filter->qm[i] -= filter->dx[i];
+    movd       m1, [errorq]         ; if (filter->error < 0) {
+    SPLATD     m1                   ;     for (int i = 0; i < 8; i++)
+    psignd     m0, m4, m1           ;         filter->qm[i] -= filter->dx[i];
+%if avx_enabled
+    psignd     m1, m5, m1           ; } else if (filter->error > 0) {
+%else
+    SWAP        1, 6
     psignd     m1, m5, m6           ; } else if (filter->error > 0) {
+%endif
     paddd      m2, m0               ;     for (int i = 0; i < 8; i++)
     paddd      m3, m1               ;         filter->qm[i] += filter->dx[i];
     mova       [qmq       ], m2     ; }
@@ -54,54 +59,55 @@ cglobal tta%3_filter_process, 5,5,%2, qm, dx, dl, error, 
in, shift, round
 %if cpuflag(sse4)
     pmulld     m2, m0
     pmulld     m3, m1
+    palignr    m5, m4, 4            ; filter->dx[0] = filter->dx[1]; 
filter->dx[1] = filter->dx[2];
+                                    ; filter->dx[2] = filter->dx[3]; 
filter->dx[3] = filter->dx[4];
 %else
     pshufd     m6, m0, 0xb1
-    pshufd     m7, m2, 0xb1
-    pmuludq    m6, m7
+    palignr    m5, m4, 4            ; filter->dx[0] = filter->dx[1]; 
filter->dx[1] = filter->dx[2];
+                                    ; filter->dx[2] = filter->dx[3]; 
filter->dx[3] = filter->dx[4];
+    pshufd     m4, m2, 0xb1
+    pmuludq    m6, m4
     pshufd     m6, m6, 0xd8
     pmuludq    m2, m0
     pshufd     m2, m2, 0xd8
     punpckldq  m2, m6
 
     pshufd     m6, m1, 0xb1
-    pshufd     m7, m3, 0xb1
-    pmuludq    m6, m7
+    pshufd     m4, m3, 0xb1
+    pmuludq    m6, m4
     pshufd     m6, m6, 0xd8
     pmuludq    m3, m1
     pshufd     m3, m3, 0xd8
     punpckldq  m3, m6
 %endif
+    movd       m4, roundm           ; int sum = filter->round +
     ; Using horizontal add (phaddd) seems to be slower than shuffling stuff 
around
-    paddd      m2, m3               ; int sum = filter->round +
-                                    ;           filter->dl[0] * filter->qm[0] +
+    paddd      m2, m3               ;           filter->dl[0] * filter->qm[0] +
     pshufd     m3, m2, 0xe          ;           filter->dl[1] * filter->qm[1] +
     paddd      m2, m3               ;           filter->dl[2] * filter->qm[2] +
                                     ;           filter->dl[3] * filter->qm[3] +
-    movd       m6, roundm           ;           filter->dl[4] * filter->qm[4] +
-    paddd      m6, m2               ;           filter->dl[5] * filter->qm[5] +
+                                    ;           filter->dl[4] * filter->qm[4] +
+    paddd      m4, m2               ;           filter->dl[5] * filter->qm[5] +
     pshufd     m2, m2, 0x1          ;           filter->dl[6] * filter->qm[6] +
-    paddd      m6, m2               ;           filter->dl[7] * filter->qm[7];
-
-    palignr    m5, m4, 4            ; filter->dx[0] = filter->dx[1]; 
filter->dx[1] = filter->dx[2];
-                                    ; filter->dx[2] = filter->dx[3]; 
filter->dx[3] = filter->dx[4];
+    paddd      m4, m2               ;           filter->dl[7] * filter->qm[7];
 
     palignr    m2, m1, m0, 4        ; filter->dl[0] = filter->dl[1]; 
filter->dl[1] = filter->dl[2];
                                     ; filter->dl[2] = filter->dl[3]; 
filter->dl[3] = filter->dl[4];
 
-    psrad      m4, m1, 30           ; filter->dx[4] = ((filter->dl[4] >> 30) | 
1);
-    por        m4, [pd_1224 ]       ; filter->dx[5] = ((filter->dl[5] >> 30) | 
2) & ~1;
-    pand       m4, [pd_n0113]       ; filter->dx[6] = ((filter->dl[6] >> 30) | 
2) & ~1;
+    psrad      m3, m1, 30           ; filter->dx[4] = ((filter->dl[4] >> 30) | 
1);
+    por        m3, [pd_1224 ]       ; filter->dx[5] = ((filter->dl[5] >> 30) | 
2) & ~1;
+    pand       m3, [pd_n0113]       ; filter->dx[6] = ((filter->dl[6] >> 30) | 
2) & ~1;
                                     ; filter->dx[7] = ((filter->dl[7] >> 30) | 
4) & ~3;
 
     mova       [dlq       ], m2
     mova       [dxq       ], m5
-    mova       [dxq + 0x10], m4
+    mova       [dxq + 0x10], m3
 
 %ifidn %3,enc
     movd       m2, shiftm           ;
     movd       m0, [inq]            ;
-    psrad      m6, m2               ;
-    psubd      m3, m0, m6           ;
+    psrad      m4, m2               ;
+    psubd      m3, m0, m4           ;
     movd       [inq], m3            ; *in -= (sum >> filter->shift);
     movd       [errorq], m3         ; filter->error = *in;
 %else
@@ -109,8 +115,8 @@ cglobal tta%3_filter_process, 5,5,%2, qm, dx, dl, error, 
in, shift, round
     movd       [errorq], m0         ;
 
     movd       m2, shiftm           ; *in += (sum >> filter->shift);
-    psrad      m6, m2               ;
-    paddd      m0, m6               ;
+    psrad      m4, m2               ;
+    paddd      m0, m4               ;
     movd       [inq], m0            ;
 %endif
 
@@ -128,11 +134,11 @@ cglobal tta%3_filter_process, 5,5,%2, qm, dx, dl, error, 
in, shift, round
 %endmacro
 
 %if CONFIG_TTA_DECODER
-TTA_FILTER ssse3, 8
-TTA_FILTER sse4,  7
+TTA_FILTER ssse3, 7
+TTA_FILTER sse4,  7-avx_enabled
 %endif
 
 %if CONFIG_TTA_ENCODER
-TTA_FILTER ssse3, 8, enc
-TTA_FILTER sse4,  7, enc
+TTA_FILTER ssse3, 7, enc
+TTA_FILTER sse4,  7-avx_enabled, enc
 %endif
-- 
2.52.0


>From 684a616ed7d6c7351ab721b85c52a20018cfa3f0 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 7 Aug 2026 03:19:03 +0200
Subject: [PATCH 8/9] avcodec/x86/ttadsp: Optimize updating dl[4..7]

ttaencdsp old:
  filter_process_c:         15.0
  filter_process_ssse3:      9.0 ( 1.66x)
  filter_process_sse4:       6.9 ( 2.18x)

ttaencdsp new:
  filter_process_c:         14.9
  filter_process_ssse3:      8.3 ( 1.79x)
  filter_process_sse4:       6.4 ( 2.32x)

ttadsp old:
  filter_process_c:         14.7
  filter_process_ssse3:      8.7 ( 1.70x)
  filter_process_sse4:       6.6 ( 2.24x)

ttadsp new:
  filter_process_c:         14.6
  filter_process_ssse3:      8.1 ( 1.81x)
  filter_process_sse4:       6.3 ( 2.30x)

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

diff --git a/libavcodec/x86/ttadsp.asm b/libavcodec/x86/ttadsp.asm
index fd98ccab34..d8e4406d53 100644
--- a/libavcodec/x86/ttadsp.asm
+++ b/libavcodec/x86/ttadsp.asm
@@ -107,6 +107,7 @@ cglobal tta%3_filter_process, 5,5,%2, qm, dx, dl, error, 
in, shift, round
     movd       m2, shiftm           ;
     movd       m0, [inq]            ;
     psrad      m4, m2               ;
+    psrldq     m1, 4                ; dl5,                 dl6,     dl7,   0
     psubd      m3, m0, m4           ;
     movd       [inq], m3            ; *in -= (sum >> filter->shift);
     movd       [errorq], m3         ; filter->error = *in;
@@ -116,19 +117,17 @@ cglobal tta%3_filter_process, 5,5,%2, qm, dx, dl, error, 
in, shift, round
 
     movd       m2, shiftm           ; *in += (sum >> filter->shift);
     psrad      m4, m2               ;
+    psrldq     m1, 4                ; dl5,                 dl6,     dl7,   0
     paddd      m0, m4               ;
     movd       [inq], m0            ;
 %endif
 
-    psrldq     m1, 4                ;
-    pslldq     m0, 12               ; filter->dl[4] = -filter->dl[5];
-    pshufd     m0, m0, 0xf0         ; filter->dl[5] = -filter->dl[6];
-    psubd      m0, m1               ; filter->dl[6] = *in - filter->dl[7];
-    psrldq     m1, m0, 4            ; filter->dl[7] = *in;
-    pshufd     m1, m1, 0xf4         ; filter->dl[5] += filter->dl[6];
-    paddd      m0, m1               ; filter->dl[4] += filter->dl[5];
-    psrldq     m1, 4                ;
-    paddd      m0, m1               ;
+    pshufd     m2, m1, q3321        ; dl6,                 dl7,       0,   0
+    pshufd     m0, m0, 0
+    paddd      m1, m2               ; dl5+dl6,         dl6+dl7,     dl7,   0
+    psrldq     m2, 4                ; dl7
+    paddd      m1, m2               ; dl5+dl6+dl7, dl5+dl6+dl7, dl6+dl7, dl7
+    psubd      m0, m1
     mova       [dlq + 0x10], m0     ;
     RET
 %endmacro
-- 
2.52.0


>From b82a571b99a0b735bc99b8b0cf49488b6acaf14a Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Fri, 7 Aug 2026 04:12:21 +0200
Subject: [PATCH 9/9] avcodec/tta{,enc}dsp: Avoid stack

Pass the input value by value and return the output value
as return value and not by passing the input value by reference.
This improves decoding speed by 2% here.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/tta.c                | 15 ++++++++-------
 libavcodec/ttadsp.c             | 14 ++++++++------
 libavcodec/ttadsp.h             |  6 +++---
 libavcodec/ttaenc.c             |  4 ++--
 libavcodec/ttaencdsp.c          | 14 ++++++++------
 libavcodec/ttaencdsp.h          |  6 +++---
 libavcodec/x86/ttadsp.asm       | 13 +++++++------
 libavcodec/x86/ttadsp_init.c    | 12 ++++++------
 libavcodec/x86/ttaencdsp_init.c | 12 ++++++------
 tests/checkasm/ttadsp.c         | 19 +++++++++----------
 10 files changed, 60 insertions(+), 55 deletions(-)

diff --git a/libavcodec/tta.c b/libavcodec/tta.c
index ed839b27fb..85acf4e4e2 100644
--- a/libavcodec/tta.c
+++ b/libavcodec/tta.c
@@ -319,21 +319,22 @@ static int tta_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
         }
 
         // extract coded value
-        *p = 1 + ((value >> 1) ^ ((value & 1) - 1));
+        value = 1 + ((value >> 1) ^ ((value & 1) - 1));
 
         // run hybrid filter
-        s->dsp.filter_process(filter->qm, filter->dx, filter->dl, 
&filter->error, p,
-                              filter->shift, filter->round);
+        value = s->dsp.filter_process(filter->qm, filter->dx, filter->dl,
+                                      &filter->error, value,
+                                      filter->shift, filter->round);
 
         // fixed order prediction
 #define PRED(x, k) (int32_t)((((uint64_t)(x) << (k)) - (x)) >> (k))
         switch (s->bps) {
-        case 1: *p += PRED(*predictor, 4); break;
+        case 1: value += PRED(*predictor, 4); break;
         case 2:
-        case 3: *p += PRED(*predictor, 5); break;
-        case 4: *p +=      *predictor;     break;
+        case 3: value += PRED(*predictor, 5); break;
+        case 4: value +=      *predictor;     break;
         }
-        *predictor = *p;
+        *predictor = *p = value;
 
         // flip channels
         if (cur_chan < (s->channels-1))
diff --git a/libavcodec/ttadsp.c b/libavcodec/ttadsp.c
index af82850869..1f4e839d34 100644
--- a/libavcodec/ttadsp.c
+++ b/libavcodec/ttadsp.c
@@ -20,9 +20,9 @@
 #include "ttadsp.h"
 #include "config.h"
 
-static void tta_filter_process_c(int32_t *qmi, int32_t *dx, int32_t *dl,
-                                 int32_t *error, int32_t *in, int32_t shift,
-                                 int32_t round)
+static int32_t tta_filter_process_c(int32_t *qmi, int32_t *dx, int32_t *dl,
+                                    int32_t *error, int32_t in, int32_t shift,
+                                    int32_t round)
 {
     uint32_t *qm = qmi;
 
@@ -45,12 +45,14 @@ static void tta_filter_process_c(int32_t *qmi, int32_t *dx, 
int32_t *dl,
     dx[6] = ((dl[6] >> 30) | 2) & ~1;
     dx[7] = ((dl[7] >> 30) | 4) & ~3;
 
-    *error = *in;
-    *in += (round >> shift);
+    *error = in;
+    in += (round >> shift);
 
     dl[4] = -(unsigned)dl[5]; dl[5] = -(unsigned)dl[6];
-    dl[6] = *in -(unsigned)dl[7]; dl[7] = *in;
+    dl[6] = in -(unsigned)dl[7]; dl[7] = in;
     dl[5] += (unsigned)dl[6]; dl[4] += (unsigned)dl[5];
+
+    return in;
 }
 
 av_cold void ff_ttadsp_init(TTADSPContext *c)
diff --git a/libavcodec/ttadsp.h b/libavcodec/ttadsp.h
index 737d9bdbaa..c60dd84581 100644
--- a/libavcodec/ttadsp.h
+++ b/libavcodec/ttadsp.h
@@ -22,9 +22,9 @@
 #include <stdint.h>
 
 typedef struct TTADSPContext {
-    void (*filter_process)(int32_t *qm, int32_t *dx, int32_t *dl,
-                           int32_t *error, int32_t *in, int32_t shift,
-                           int32_t round);
+    int32_t (*filter_process)(int32_t *qm, int32_t *dx, int32_t *dl,
+                              int32_t *error, int32_t in, int32_t shift,
+                              int32_t round);
 } TTADSPContext;
 
 void ff_ttadsp_init(TTADSPContext *c);
diff --git a/libavcodec/ttaenc.c b/libavcodec/ttaenc.c
index 16fa377536..46751ff3ca 100644
--- a/libavcodec/ttaenc.c
+++ b/libavcodec/ttaenc.c
@@ -130,8 +130,8 @@ pkt_alloc:
         }
         c->predictor = temp;
 
-        s->dsp.filter_process(filter->qm, filter->dx, filter->dl, 
&filter->error, &value,
-                              filter->shift, filter->round);
+        value = s->dsp.filter_process(filter->qm, filter->dx, filter->dl, 
&filter->error, value,
+                                      filter->shift, filter->round);
         outval = (value > 0) ? (value << 1) - 1: -value << 1;
 
         k = rice->k0;
diff --git a/libavcodec/ttaencdsp.c b/libavcodec/ttaencdsp.c
index 7e4fed0679..65904430ee 100644
--- a/libavcodec/ttaencdsp.c
+++ b/libavcodec/ttaencdsp.c
@@ -20,9 +20,9 @@
 #include "ttaencdsp.h"
 #include "config.h"
 
-static void ttaenc_filter_process_c(int32_t *qmi, int32_t *dx, int32_t *dl,
-                                    int32_t *error, int32_t *in, int32_t shift,
-                                    int32_t round)
+static int32_t ttaenc_filter_process_c(int32_t *qmi, int32_t *dx, int32_t *dl,
+                                       int32_t *error, int32_t in, int32_t 
shift,
+                                       int32_t round)
 {
     uint32_t *qm = qmi;
 
@@ -46,11 +46,13 @@ static void ttaenc_filter_process_c(int32_t *qmi, int32_t 
*dx, int32_t *dl,
     dx[7] = ((dl[7] >> 30) | 4) & ~3;
 
     dl[4]  = -(unsigned)dl[5];     dl[5] = -(unsigned)dl[6];
-    dl[6]  = *in -(unsigned)dl[7]; dl[7] = *in;
+    dl[6]  = in -(unsigned)dl[7];  dl[7] = in;
     dl[5] += (unsigned)dl[6];      dl[4] += (unsigned)dl[5];
 
-    *in -= (round >> shift);
-    *error = *in;
+    in -= (round >> shift);
+    *error = in;
+
+    return in;
 }
 
 av_cold void ff_ttaencdsp_init(TTAEncDSPContext *c)
diff --git a/libavcodec/ttaencdsp.h b/libavcodec/ttaencdsp.h
index 4b00728f96..32dfd26a79 100644
--- a/libavcodec/ttaencdsp.h
+++ b/libavcodec/ttaencdsp.h
@@ -22,9 +22,9 @@
 #include <stdint.h>
 
 typedef struct TTAEncDSPContext {
-    void (*filter_process)(int32_t *qm, int32_t *dx, int32_t *dl,
-                           int32_t *error, int32_t *in, int32_t shift,
-                           int32_t round);
+    int32_t (*filter_process)(int32_t *qm, int32_t *dx, int32_t *dl,
+                              int32_t *error, int32_t in, int32_t shift,
+                              int32_t round);
 } TTAEncDSPContext;
 
 void ff_ttaencdsp_init(TTAEncDSPContext *c);
diff --git a/libavcodec/x86/ttadsp.asm b/libavcodec/x86/ttadsp.asm
index d8e4406d53..324d27f461 100644
--- a/libavcodec/x86/ttadsp.asm
+++ b/libavcodec/x86/ttadsp.asm
@@ -96,6 +96,7 @@ cglobal tta%3_filter_process, 5,5,%2, qm, dx, dl, error, in, 
shift, round
 
     psrad      m3, m1, 30           ; filter->dx[4] = ((filter->dl[4] >> 30) | 
1);
     por        m3, [pd_1224 ]       ; filter->dx[5] = ((filter->dl[5] >> 30) | 
2) & ~1;
+    movd       m0, inm              ;
     pand       m3, [pd_n0113]       ; filter->dx[6] = ((filter->dl[6] >> 30) | 
2) & ~1;
                                     ; filter->dx[7] = ((filter->dl[7] >> 30) | 
4) & ~3;
 
@@ -103,23 +104,23 @@ cglobal tta%3_filter_process, 5,5,%2, qm, dx, dl, error, 
in, shift, round
     mova       [dxq       ], m5
     mova       [dxq + 0x10], m3
 
+    ; notice that eax is r6 (round) on x64 and r0 (qm) otherwise;
+    ; round and qm are no longer needed.
 %ifidn %3,enc
     movd       m2, shiftm           ;
-    movd       m0, [inq]            ;
     psrad      m4, m2               ;
     psrldq     m1, 4                ; dl5,                 dl6,     dl7,   0
-    psubd      m3, m0, m4           ;
-    movd       [inq], m3            ; *in -= (sum >> filter->shift);
+    psubd      m3, m0, m4           ; *in -= (sum >> filter->shift);
+    movd      eax, m3               ;
     movd       [errorq], m3         ; filter->error = *in;
 %else
-    movd       m0, [inq]            ; filter->error = *in;
-    movd       [errorq], m0         ;
+    movd [errorq], m0               ; filter->error = *in;
 
     movd       m2, shiftm           ; *in += (sum >> filter->shift);
     psrad      m4, m2               ;
     psrldq     m1, 4                ; dl5,                 dl6,     dl7,   0
     paddd      m0, m4               ;
-    movd       [inq], m0            ;
+    movd      eax, m0               ;
 %endif
 
     pshufd     m2, m1, q3321        ; dl6,                 dl7,       0,   0
diff --git a/libavcodec/x86/ttadsp_init.c b/libavcodec/x86/ttadsp_init.c
index b4d5184260..5e4e4aea60 100644
--- a/libavcodec/x86/ttadsp_init.c
+++ b/libavcodec/x86/ttadsp_init.c
@@ -22,12 +22,12 @@
 #include "libavcodec/ttadsp.h"
 #include "libavutil/x86/cpu.h"
 
-void ff_tta_filter_process_ssse3(int32_t *qm, int32_t *dx, int32_t *dl,
-                                 int32_t *error, int32_t *in, int32_t shift,
-                                 int32_t round);
-void ff_tta_filter_process_sse4(int32_t *qm, int32_t *dx, int32_t *dl,
-                                int32_t *error, int32_t *in, int32_t shift,
-                                int32_t round);
+int32_t ff_tta_filter_process_ssse3(int32_t *qm, int32_t *dx, int32_t *dl,
+                                    int32_t *error, int32_t in, int32_t shift,
+                                    int32_t round);
+int32_t ff_tta_filter_process_sse4(int32_t *qm, int32_t *dx, int32_t *dl,
+                                   int32_t *error, int32_t in, int32_t shift,
+                                   int32_t round);
 
 av_cold void ff_ttadsp_init_x86(TTADSPContext *c)
 {
diff --git a/libavcodec/x86/ttaencdsp_init.c b/libavcodec/x86/ttaencdsp_init.c
index cfe11f9678..a9cfa67006 100644
--- a/libavcodec/x86/ttaencdsp_init.c
+++ b/libavcodec/x86/ttaencdsp_init.c
@@ -22,12 +22,12 @@
 #include "libavcodec/ttaencdsp.h"
 #include "libavutil/x86/cpu.h"
 
-void ff_ttaenc_filter_process_ssse3(int32_t *qm, int32_t *dx, int32_t *dl,
-                                    int32_t *error, int32_t *in, int32_t shift,
-                                    int32_t round);
-void ff_ttaenc_filter_process_sse4(int32_t *qm, int32_t *dx, int32_t *dl,
-                                   int32_t *error, int32_t *in, int32_t shift,
-                                   int32_t round);
+int32_t ff_ttaenc_filter_process_ssse3(int32_t *qm, int32_t *dx, int32_t *dl,
+                                       int32_t *error, int32_t in, int32_t 
shift,
+                                       int32_t round);
+int32_t ff_ttaenc_filter_process_sse4(int32_t *qm, int32_t *dx, int32_t *dl,
+                                      int32_t *error, int32_t in, int32_t 
shift,
+                                      int32_t round);
 
 av_cold void ff_ttaencdsp_init_x86(TTAEncDSPContext *c)
 {
diff --git a/tests/checkasm/ttadsp.c b/tests/checkasm/ttadsp.c
index 485b785f32..d4c95e5b16 100644
--- a/tests/checkasm/ttadsp.c
+++ b/tests/checkasm/ttadsp.c
@@ -43,26 +43,25 @@ static void check_filter_process(void)
     DECLARE_ALIGNED_16(int32_t, dl_new)[MAX_ORDER];
     int bps = 1 + rnd() % 3;
     int32_t shift = ff_tta_filter_configs[bps - 1], round = 
ff_tta_shift_1[shift - 1];
-    int32_t in_ref = rnd(), in_new = in_ref;
-    int32_t error_ref = rnd(), error_new = error_ref;
+    int32_t in = rnd(), error_ref = rnd(), error_new = error_ref;
 
-    declare_func(void, int32_t *qm, int32_t *dx, int32_t *dl, int32_t *error,
-                       int32_t *in, int32_t shift, int32_t round);
+    declare_func(int32_t, int32_t *qm, int32_t *dx, int32_t *dl, int32_t 
*error,
+                          int32_t in,  int32_t shift, int32_t round);
 
     randomize_buffer(qm);
     randomize_buffer(dx);
     randomize_buffer(dl);
 
-    call_ref(qm_ref, dx_ref, dl_ref, &error_ref, &in_ref, shift, round);
-    call_new(qm_new, dx_new, dl_new, &error_new, &in_new, shift, round);
+    int32_t out_ref = call_ref(qm_ref, dx_ref, dl_ref, &error_ref, in, shift, 
round);
+    int32_t out_new = call_new(qm_new, dx_new, dl_new, &error_new, in, shift, 
round);
 
-    if (in_ref != in_new || error_ref != error_new ||
-        memcmp(qm_ref, qm_new, sizeof(qm_ref))     ||
-        memcmp(dx_ref, dx_new, sizeof(dx_ref))     ||
+    if (out_ref != out_new || error_ref != error_new ||
+        memcmp(qm_ref, qm_new, sizeof(qm_ref))       ||
+        memcmp(dx_ref, dx_new, sizeof(dx_ref))       ||
         memcmp(dl_ref, dl_new, sizeof(dl_ref)))
         fail();
 #define alt(var) checkasm_alternate(var ## _ref, var ## _new)
-    bench_new(alt(qm), alt(dx), alt(dl), alt(&error), alt(&in), shift, round);
+    bench_new(alt(qm), alt(dx), alt(dl), alt(&error), in, shift, round);
 }
 
 #if CONFIG_TTA_DECODER
-- 
2.52.0

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

Reply via email to