[FFmpeg-devel] [PATCH 5/5] x86: sbrdsp: implement SSE hf_apply_noise
Christophe Gisquet
christophe.gisquet at gmail.com
Sun Apr 7 22:20:34 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/aacsbrdata.h | 6 ++-
libavcodec/x86/sbrdsp.asm | 118 +++++++++++++++++++++++++++++++++++++++++++
libavcodec/x86/sbrdsp_init.c | 24 +++++++++
3 files changed, 147 insertions(+), 1 deletion(-)
diff --git a/libavcodec/aacsbrdata.h b/libavcodec/aacsbrdata.h
index dd7a827..12575ee 100644
--- a/libavcodec/aacsbrdata.h
+++ b/libavcodec/aacsbrdata.h
@@ -352,7 +352,7 @@ static DECLARE_ALIGNED(32, float, sbr_qmf_window_us)[640] = {
0.8537385600,
};
-/* First two entries repeated at end to simplify SIMD implementations. */
+/* First eight entries repeated at end to simplify SIMD implementations. */
const DECLARE_ALIGNED(16, float, ff_sbr_noise_table)[][2] = {
{-0.99948153278296, -0.59483417516607}, { 0.97113454393991, -0.67528515225647},
{ 0.14130051758487, -0.95090983575689}, {-0.47005496701697, -0.37340549728647},
@@ -610,7 +610,11 @@ const DECLARE_ALIGNED(16, float, ff_sbr_noise_table)[][2] = {
{-0.93412041758744, 0.41374052024363}, { 0.96063943315511, 0.93116709541280},
{ 0.97534253457837, 0.86150930812689}, { 0.99642466504163, 0.70190043427512},
{-0.94705089665984, -0.29580042814306}, { 0.91599807087376, -0.98147830385781},
+// Start of duplicated table
{-0.99948153278296, -0.59483417516607}, { 0.97113454393991, -0.67528515225647},
+{ 0.14130051758487, -0.95090983575689}, {-0.47005496701697, -0.37340549728647},
+{ 0.80705063769351, 0.29653668284408}, {-0.38981478896926, 0.89572605717087},
+{-0.01053049862020, -0.66959058036166}, {-0.91266367957293, -0.11522938140034},
};
#endif /* AVCODEC_AACSBRDATA_H */
diff --git a/libavcodec/x86/sbrdsp.asm b/libavcodec/x86/sbrdsp.asm
index b48f964..277be09 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
@@ -350,3 +356,115 @@ SBR_QMF_DEINT_BFLY
INIT_XMM sse2
SBR_QMF_DEINT_BFLY
+
+%if WIN64
+%define NREGS 0
+%else
+%ifdef PIC
+%define NREGS 1
+%else
+%define NREGS 0
+%endif
+%endif
+
+%macro LOAD_NST 1
+%if NREGS
+ lea r5q, [%1]
+ mova m0, [kxq + r5q]
+%else
+ mova m0, [kxq + %1]
+%endif
+%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
+ LOAD_NST ps_noise13
+ 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
+ LOAD_NST ps_noise13+16
+
+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:
+ mova m1, [q_filtq + count]
+ movu m3, [noiseq + NOISE_TABLE + 1*mmsize]
+ movu m4, [noiseq + NOISE_TABLE + 2*mmsize]
+ add noiseq, 2*mmsize
+ and noiseq, 0x1ff<<3
+ SBUTTERFLY dq, 1, 1, 2
+ mulps m2, m3 ; m2 = q_filt[m] * ff_sbr_noise_table[noise]
+ mulps m1, m4 ; m2 = q_filt[m] * ff_sbr_noise_table[noise]
+ mova m3, [s_mq + count]
+ ; TODO: replace by a vpermd in AVX2
+ SBUTTERFLY dq, 3, 3, 4
+ cmpps m6, m4, m5, 0 ; m6 == 0
+ cmpps m7, m3, m5, 0 ; m7 == 0
+ mulps m4, m0 ; s_m[m] * phi_sign
+ mulps m3, m0 ; s_m[m] * phi_sign
+ andps m2, m6
+ andps m1, m7
+ movu m6, [Yq + 2*count]
+ movu m7, [Yq + 2*count + mmsize]
+ addps m4, m2
+ addps m3, m1
+ addps m6, m4
+ addps m7, m3
+ 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 895660a..2674ff7 100644
--- a/libavcodec/x86/sbrdsp_init.c
+++ b/libavcodec/x86/sbrdsp_init.c
@@ -39,6 +39,22 @@ 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)
av_cold void ff_sbrdsp_init_x86(SBRDSPContext *s)
{
@@ -50,6 +66,10 @@ av_cold void ff_sbrdsp_init_x86(SBRDSPContext *s)
s->sum64x5 = ff_sbr_sum64x5_sse;
s->hf_g_filt = ff_sbr_hf_g_filt_sse;
s->hf_gen = ff_sbr_hf_gen_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;
s->qmf_post_shuffle = ff_sbr_qmf_post_shuffle_sse;
s->qmf_pre_shuffle = ff_sbr_qmf_pre_shuffle_sse;
s->qmf_deint_neg = ff_sbr_qmf_deint_neg_sse;
@@ -59,5 +79,9 @@ av_cold void ff_sbrdsp_init_x86(SBRDSPContext *s)
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;
}
}
--
1.8.0.msysgit.0
More information about the ffmpeg-devel
mailing list