[FFmpeg-devel] [PATCH 4/7] x86: sbrdsp: implement SSE hf_apply_noise
Christophe Gisquet
christophe.gisquet at gmail.com
Sat Apr 6 12:52:11 CEST 2013
233 to 115(sse)/110(sse2) cycles on Arrandale and Win64.
Replacing the multiplication by s_m[m] by an andps and an xorps with
appropriate vectors is slower. Unrolling is a 15 cycles win.
---
libavcodec/x86/sbrdsp.asm | 145 +++++++++++++++++++++++++++++++++++++++++++
libavcodec/x86/sbrdsp_init.c | 32 ++++++++++
2 files changed, 177 insertions(+)
diff --git a/libavcodec/x86/sbrdsp.asm b/libavcodec/x86/sbrdsp.asm
index 65c972e..a7998fa 100644
--- a/libavcodec/x86/sbrdsp.asm
+++ b/libavcodec/x86/sbrdsp.asm
@@ -26,6 +26,12 @@ SECTION_RODATA
ps_mask times 2 dd 1<<31, 0
ps_mask2 times 2 dd 0, 1<<31
ps_neg times 4 dd 1<<31
+ps_noise0 times 2 dd 1.0, 0.0,
+ps_noise2 times 2 dd -1.0, 0.0
+ps_noise13 dd 0.0, 1.0, 0.0, -1.0
+ dd 0.0, -1.0, 0.0, 1.0
+ dd 0.0, 1.0, 0.0, -1.0
+cextern sbr_noise_table
SECTION_TEXT
@@ -358,3 +364,142 @@ SBR_QMF_DEINT_BFLY
INIT_XMM sse2
SBR_QMF_DEINT_BFLY
+
+%if WIN64
+%define NREGS 0
+%else
+%ifndef PIC
+%define NREGS 1
+%else
+%define NREGS 0
+%endif
+%endif
+
+%macro SBUTTERFLY_F128 3
+ vperm2i128 m%3, m%1, m%2, q0301 ; punpckh
+ vinserti128 m%1, m%1, xm%2, 1 ; punpckl
+ SWAP %2, %3
+%endmacro
+
+%macro SBR_HF_APPLY_NOISE 0
+; sbr_hf_apply_noise_0(float (*Y)[2], const float *s_m,
+; const float *q_filt, int noise,
+; int kx, int m_max)
+cglobal sbr_hf_apply_noise_0, 5,5+NREGS,8, Y,s_m,q_filt,noise,kx,m_max
+ mova m0, [ps_noise0]
+ jmp apply_noise_main %+ SUFFIX
+
+; sbr_hf_apply_noise_1(float (*Y)[2], const float *s_m,
+; const float *q_filt, int noise,
+; int kx, int m_max)
+cglobal sbr_hf_apply_noise_1, 5,5+NREGS,8, Y,s_m,q_filt,noise,kx,m_max
+ and kxq, 1
+ shl kxq, 4
+%if NREGS
+ lea r5q, [ps_noise13]
+ mova m0, [kxq + r5q]
+%else
+ mova m0, [kxq + ps_noise13]
+%endif
+ jmp apply_noise_main %+ SUFFIX
+
+; sbr_hf_apply_noise_2(float (*Y)[2], const float *s_m,
+; const float *q_filt, int noise,
+; int kx, int m_max)
+cglobal sbr_hf_apply_noise_2, 5,5+NREGS,8, Y,s_m,q_filt,noise,kx,m_max
+ mova m0, [ps_noise2]
+ jmp apply_noise_main %+ SUFFIX
+
+; sbr_hf_apply_noise_3(float (*Y)[2], const float *s_m,
+; const float *q_filt, int noise,
+; int kx, int m_max)
+cglobal sbr_hf_apply_noise_3, 5,5+NREGS,8, Y,s_m,q_filt,noise,kx,m_max
+ and kxq, 1
+ shl kxq, 4
+%if NREGS
+ lea r5q, [ps_noise13]
+ mova m0, [kxq + r5q + 16]
+%else
+ mova m0, [kxq + ps_noise13 + 16]
+%endif
+
+apply_noise_main %+ SUFFIX:
+%if ARCH_X86_64 == 0 || WIN64
+ mov kxd, m_maxm
+%define count kxq
+%else
+%define count m_maxq
+%endif
+ dec noiseq
+ shl count, 2
+%if NREGS
+ lea r5q, [sbr_noise_table]
+%define NOISE_TABLE r5q
+%else
+%define NOISE_TABLE sbr_noise_table
+%endif
+ lea Yq, [Yq + 2*count]
+ add s_mq, count
+ add q_filtq, count
+ shl noiseq, 3
+ xorps m5, m5
+ neg count
+.loop:
+ add noiseq, mmsize
+ and noiseq, 0x1ff<<3
+ mova m1, [q_filtq + count]
+ movu m3, [noiseq + NOISE_TABLE]
+ add noiseq, mmsize
+ and noiseq, 0x1ff<<3
+ movu m4, [noiseq + NOISE_TABLE]
+%if cpuflag(sse2)
+ punpckhdq m2, m1, m1
+ punpckldq m1, m1, m1
+%else
+ unpckhps m2, m1, m1
+ unpcklps m1, m1, m1
+%endif
+%if mmsize==32
+ SBUTTERFLY_F128 m1, m2, m7
+%endif
+ mulps m1, m3 ; m2 = q_filt[m] * ff_sbr_noise_table[noise]
+ mulps m2, m4 ; m2 = q_filt[m] * ff_sbr_noise_table[noise]
+ mova m3, [s_mq + count]
+ ; TODO: replace by a vpermd in AVX2
+%if cpuflag(sse2)
+ punpckhdq m4, m3, m3
+ punpckldq m3, m3, m3
+%else
+ unpckhps m4, m3, m3
+ unpcklps m3, m3, m3
+%endif
+%if mmsize==32
+ SBUTTERFLY_F128 m3, m4, m7
+%endif
+ cmpps m6, m3, m5, 0 ; m6 == 0
+ cmpps m7, m4, m5, 0 ; m7 == 0
+ mulps m3, m0 ; s_m[m] * phi_sign
+ mulps m4, m0 ; s_m[m] * phi_sign
+ andps m1, m6
+ andps m2, m7
+ movu m6, [Yq + 2*count]
+ movu m7, [Yq + 2*count + mmsize]
+ addps m3, m1
+ addps m4, m2
+ addps m6, m3
+ addps m7, m4
+ movu [Yq + 2*count], m6
+ movu [Yq + 2*count + mmsize], m7
+ add count, mmsize
+ jl .loop
+ RET
+%endmacro
+
+INIT_XMM sse
+SBR_HF_APPLY_NOISE
+
+INIT_XMM sse2
+SBR_HF_APPLY_NOISE
+
+INIT_XMM avx
+SBR_HF_APPLY_NOISE
diff --git a/libavcodec/x86/sbrdsp_init.c b/libavcodec/x86/sbrdsp_init.c
index 2003129..9694675 100644
--- a/libavcodec/x86/sbrdsp_init.c
+++ b/libavcodec/x86/sbrdsp_init.c
@@ -39,6 +39,23 @@ void ff_sbr_qmf_pre_shuffle_sse2(float *z);
void ff_sbr_qmf_deint_neg_sse(float *v, const float *src);
void ff_sbr_qmf_deint_bfly_sse(float *v, const float *src0, const float *src1);
void ff_sbr_qmf_deint_bfly_sse2(float *v, const float *src0, const float *src1);
+#define DECLARE_SBR_HF_APPLY_NOISE(insn) \
+void ff_sbr_hf_apply_noise_0_ ## insn(float (*Y)[2], const float *s_m, \
+ const float *q_filt, int noise, \
+ int kx, int m_max); \
+void ff_sbr_hf_apply_noise_1_ ## insn(float (*Y)[2], const float *s_m, \
+ const float *q_filt, int noise, \
+ int kx, int m_max); \
+void ff_sbr_hf_apply_noise_2_ ## insn(float (*Y)[2], const float *s_m, \
+ const float *q_filt, int noise, \
+ int kx, int m_max); \
+void ff_sbr_hf_apply_noise_3_ ## insn(float (*Y)[2], const float *s_m, \
+ const float *q_filt, int noise, \
+ int kx, int m_max);
+
+DECLARE_SBR_HF_APPLY_NOISE(sse)
+DECLARE_SBR_HF_APPLY_NOISE(sse2)
+DECLARE_SBR_HF_APPLY_NOISE(avx)
av_cold void ff_sbrdsp_init_x86(SBRDSPContext *s)
{
@@ -54,10 +71,25 @@ av_cold void ff_sbrdsp_init_x86(SBRDSPContext *s)
s->qmf_pre_shuffle = ff_sbr_qmf_pre_shuffle_sse;
s->qmf_deint_neg = ff_sbr_qmf_deint_neg_sse;
s->qmf_deint_bfly = ff_sbr_qmf_deint_bfly_sse;
+ s->hf_apply_noise[0] = ff_sbr_hf_apply_noise_0_sse;
+ s->hf_apply_noise[1] = ff_sbr_hf_apply_noise_1_sse;
+ s->hf_apply_noise[2] = ff_sbr_hf_apply_noise_2_sse;
+ s->hf_apply_noise[3] = ff_sbr_hf_apply_noise_3_sse;
}
if (EXTERNAL_SSE2(mm_flags)) {
s->qmf_pre_shuffle = ff_sbr_qmf_pre_shuffle_sse2;
s->qmf_deint_bfly = ff_sbr_qmf_deint_bfly_sse2;
+ s->hf_apply_noise[0] = ff_sbr_hf_apply_noise_0_sse2;
+ s->hf_apply_noise[1] = ff_sbr_hf_apply_noise_1_sse2;
+ s->hf_apply_noise[2] = ff_sbr_hf_apply_noise_2_sse2;
+ s->hf_apply_noise[3] = ff_sbr_hf_apply_noise_3_sse2;
+ }
+
+ if (EXTERNAL_AVX(mm_flags)) {
+ s->hf_apply_noise[0] = ff_sbr_hf_apply_noise_0_avx;
+ s->hf_apply_noise[1] = ff_sbr_hf_apply_noise_1_avx;
+ s->hf_apply_noise[2] = ff_sbr_hf_apply_noise_2_avx;
+ s->hf_apply_noise[3] = ff_sbr_hf_apply_noise_3_avx;
}
}
--
1.8.0.msysgit.0
More information about the ffmpeg-devel
mailing list