[FFmpeg-devel] [PATCH 5/9] SBR DSP x86: implement SSE hf_apply_noise
Christophe Gisquet
christophe.gisquet at gmail.com
Thu Apr 4 21:45:49 CEST 2013
497 to 255 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 | 100 +++++++++++++++++++++++++++++++++++++++++++
libavcodec/x86/sbrdsp_init.c | 16 +++++++
2 files changed, 116 insertions(+)
diff --git a/libavcodec/x86/sbrdsp.asm b/libavcodec/x86/sbrdsp.asm
index 573981a..fdeaa2b 100644
--- a/libavcodec/x86/sbrdsp.asm
+++ b/libavcodec/x86/sbrdsp.asm
@@ -25,6 +25,12 @@ SECTION_RODATA
; mask equivalent for multiply by -1.0 1.0
ps_mask times 2 dd 1<<31, 0
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
@@ -301,3 +307,97 @@ cglobal sbr_qmf_deint_bfly, 3,5,8, v,src0,src1,vrev,c
sub cq, 2*mmsize
jge .loop
REP_RET
+
+INIT_XMM sse
+%ifdef PIC
+%define NPICREGS 0
+%define NOISE_TABLE sbr_noise_table
+%else
+%define NPICREGS 1
+%define NOISE_TABLE r5q
+%endif
+; 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+NPICREGS,8, Y,s_m,q_filt,noise,kx,m_max
+ mova m0, [ps_noise0]
+ jmp apply_noise_main
+
+; 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+NPICREGS,8, Y,s_m,q_filt,noise,kx,m_max
+ and kxq, 1
+ shl kxq, 4
+ mova m0, [kxq + ps_noise13]
+ jmp apply_noise_main
+
+; 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+NPICREGS,8, Y,s_m,q_filt,noise,kx,m_max
+ mova m0, [ps_noise2]
+ jmp apply_noise_main
+
+; 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+NPICREGS,8, Y,s_m,q_filt,noise,kx,m_max
+ and kxq, 1
+ shl kxq, 4
+ mova m0, [kxq + ps_noise13 + 16]
+
+apply_noise_main:
+%if ARCH_X86_64 == 0 || WIN64
+ mov kxd, m_maxm
+%define count kxq
+%else
+%define count m_maxq
+%endif
+ dec noiseq
+ shl count, 2
+%ifndef PIC
+ lea r5q, [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, 16
+ and noiseq, 0x1ff<<3
+ mova m2, [q_filtq + count]
+ movu m3, [noiseq + NOISE_TABLE]
+ mova m1, m2
+ add noiseq, 16
+ and noiseq, 0x1ff<<3
+ movu m4, [noiseq + NOISE_TABLE]
+ unpcklps m1, m1
+ unpckhps m2, m2
+ 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 m4, [s_mq + count]
+ mova m3, m4
+ unpcklps m3, m3
+ unpckhps m4, m4
+ mova m6, m3
+ mova m7, m4
+ mulps m3, m0 ; s_m[m] * phi_sign
+ mulps m4, m0 ; s_m[m] * phi_sign
+ cmpps m6, m5, 0 ; m6 == 0
+ cmpps m7, m5, 0 ; m7 == 0
+ andps m1, m6
+ andps m2, m7
+ movu m6, [Yq + 2*count]
+ movu m7, [Yq + 2*count + 16]
+ addps m3, m1
+ addps m4, m2
+ addps m6, m3
+ addps m7, m4
+ movu [Yq + 2*count], m6
+ movu [Yq + 2*count + 16], m7
+ add count, 16
+ jl .loop
+ RET
diff --git a/libavcodec/x86/sbrdsp_init.c b/libavcodec/x86/sbrdsp_init.c
index 80598b2..78c8f4c 100644
--- a/libavcodec/x86/sbrdsp_init.c
+++ b/libavcodec/x86/sbrdsp_init.c
@@ -36,6 +36,18 @@ void ff_sbr_qmf_post_shuffle_sse(float W[32][2], const float *z);
void ff_sbr_qmf_pre_shuffle_sse(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_hf_apply_noise_0_sse(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_sse(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_sse(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_sse(float (*Y)[2], const float *s_m,
+ const float *q_filt, int noise,
+ int kx, int m_max);
av_cold void ff_sbrdsp_init_x86(SBRDSPContext *s)
{
@@ -50,5 +62,9 @@ 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;
}
}
--
1.8.0.msysgit.0
More information about the ffmpeg-devel
mailing list