This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 1f276a42dbd693ef58222e2c1499d45691b49089 Author: Andreas Rheinhardt <[email protected]> AuthorDate: Fri Aug 7 04:12:21 2026 +0200 Commit: Andreas Rheinhardt <[email protected]> CommitDate: Sun Aug 9 17:25:23 2026 +0200 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. Reviewed-by: Lynne <[email protected]> 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 _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
