From eb5733f38f56ca79e3bbcf2e3c12483d219f0523 Mon Sep 17 00:00:00 2001
From: James Almer <jamrial@gmail.com>
Date: Sun, 12 May 2024 12:36:01 -0300
Subject: x86/flacdsp: add an SSE4 version of wasted33

flac_wasted_33_c: 214.1
flac_wasted_33_sse4: 103.2

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/x86/flacdsp.asm    | 25 +++++++++++++++++++++++++
 libavcodec/x86/flacdsp_init.c |  2 ++
 2 files changed, 27 insertions(+)

diff --git a/libavcodec/x86/flacdsp.asm b/libavcodec/x86/flacdsp.asm
index 21b2439bc0..15fcec4f08 100644
--- a/libavcodec/x86/flacdsp.asm
+++ b/libavcodec/x86/flacdsp.asm
@@ -113,6 +113,31 @@ ALIGN 16
     jl .loop
     RET
 
+INIT_XMM sse4
+cglobal flac_wasted_33, 4,4,5, decoded, residuals, wasted, len
+    shl   lend, 2
+    lea   decodedq, [decodedq+lenq*2]
+    add   residualsq, lenq
+    neg   lenq
+    movd  m4, wastedd
+ALIGN 16
+.loop:
+    pmovsxdq  m0, [residualsq+lenq+mmsize*0]
+    pmovsxdq  m1, [residualsq+lenq+mmsize/2]
+    pmovsxdq  m2, [residualsq+lenq+mmsize*1]
+    pmovsxdq  m3, [residualsq+lenq+mmsize*1+mmsize/2]
+    psllq m0, m4
+    psllq m1, m4
+    psllq m2, m4
+    psllq m3, m4
+    mova  [decodedq+lenq*2+mmsize*0], m0
+    mova  [decodedq+lenq*2+mmsize*1], m1
+    mova  [decodedq+lenq*2+mmsize*2], m2
+    mova  [decodedq+lenq*2+mmsize*3], m3
+    add lenq, mmsize * 2
+    jl .loop
+    RET
+
 ;----------------------------------------------------------------------------------
 ;void ff_flac_decorrelate_[lrm]s_16_sse2(uint8_t **out, int32_t **in, int channels,
 ;                                                   int len, int shift);
diff --git a/libavcodec/x86/flacdsp_init.c b/libavcodec/x86/flacdsp_init.c
index 67aa118760..fa993d3466 100644
--- a/libavcodec/x86/flacdsp_init.c
+++ b/libavcodec/x86/flacdsp_init.c
@@ -31,6 +31,7 @@ void ff_flac_lpc_32_xop(int32_t *samples, const int coeffs[32], int order,
                         int qlevel, int len);
 
 void ff_flac_wasted_32_sse2(int32_t *decoded, int wasted, int len);
+void ff_flac_wasted_33_sse4(int64_t *decoded, const int32_t *residual, int wasted, int len);
 
 #define DECORRELATE_FUNCS(fmt, opt)                                                      \
 void ff_flac_decorrelate_ls_##fmt##_##opt(uint8_t **out, int32_t **in, int channels,     \
@@ -100,6 +101,7 @@ av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum AVSampleFormat fmt, int
     if (EXTERNAL_SSE4(cpu_flags)) {
         c->lpc16 = ff_flac_lpc_16_sse4;
         c->lpc32 = ff_flac_lpc_32_sse4;
+        c->wasted33 = ff_flac_wasted_33_sse4;
     }
     if (EXTERNAL_AVX(cpu_flags)) {
         if (fmt == AV_SAMPLE_FMT_S16) {
-- 
cgit v1.2.3