diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2015-10-28 15:38:22 +0100 |
---|---|---|
committer | Diego Biurrun <diego@biurrun.de> | 2016-10-01 00:46:25 +0200 |
commit | b57e38f52cc3f31a27105c28887d57cd6812c3eb (patch) | |
tree | e37260a47617bb608972ae3169b90feb43c270e6 /libavcodec/x86/ac3dsp_init.c | |
parent | a9ba59591ed509fb7e6decfde8da4cbfd4ddf4b8 (diff) | |
download | ffmpeg-b57e38f52cc3f31a27105c28887d57cd6812c3eb.tar.gz |
ac3dsp: x86: Replace inline asm for in-decoder downmixing with standalone asm
Adds a wrapper function for downmixing which detects channel count changes
and updates the selected downmix function accordingly.
Simplification and porting to current x86inc infrastructure by Diego Biurrun.
Signed-off-by: Diego Biurrun <diego@biurrun.de>
Diffstat (limited to 'libavcodec/x86/ac3dsp_init.c')
-rw-r--r-- | libavcodec/x86/ac3dsp_init.c | 174 |
1 files changed, 41 insertions, 133 deletions
diff --git a/libavcodec/x86/ac3dsp_init.c b/libavcodec/x86/ac3dsp_init.c index 9036389296..6d049b37cf 100644 --- a/libavcodec/x86/ac3dsp_init.c +++ b/libavcodec/x86/ac3dsp_init.c @@ -63,135 +63,6 @@ void ff_apply_window_int16_ssse3(int16_t *output, const int16_t *input, void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input, const int16_t *window, unsigned int len); -#if HAVE_SSE_INLINE && HAVE_7REGS - -#define IF1(x) x -#define IF0(x) - -#define MIX5(mono, stereo) \ - __asm__ volatile ( \ - "movss 0(%1), %%xmm5 \n" \ - "movss 4(%1), %%xmm6 \n" \ - "movss 12(%1), %%xmm7 \n" \ - "shufps $0, %%xmm5, %%xmm5 \n" \ - "shufps $0, %%xmm6, %%xmm6 \n" \ - "shufps $0, %%xmm7, %%xmm7 \n" \ - "1: \n" \ - "movaps (%0, %2), %%xmm0 \n" \ - "movaps (%0, %3), %%xmm1 \n" \ - "movaps (%0, %4), %%xmm2 \n" \ - "movaps (%0, %5), %%xmm3 \n" \ - "movaps (%0, %6), %%xmm4 \n" \ - "mulps %%xmm5, %%xmm0 \n" \ - "mulps %%xmm6, %%xmm1 \n" \ - "mulps %%xmm5, %%xmm2 \n" \ - "mulps %%xmm7, %%xmm3 \n" \ - "mulps %%xmm7, %%xmm4 \n" \ - stereo("addps %%xmm1, %%xmm0 \n") \ - "addps %%xmm1, %%xmm2 \n" \ - "addps %%xmm3, %%xmm0 \n" \ - "addps %%xmm4, %%xmm2 \n" \ - mono("addps %%xmm2, %%xmm0 \n") \ - "movaps %%xmm0, (%0, %2) \n" \ - stereo("movaps %%xmm2, (%0, %3) \n") \ - "add $16, %0 \n" \ - "jl 1b \n" \ - : "+&r"(i) \ - : "r"(matrix[0]), \ - "r"(samples[0] + len), \ - "r"(samples[1] + len), \ - "r"(samples[2] + len), \ - "r"(samples[3] + len), \ - "r"(samples[4] + len) \ - : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \ - "%xmm4", "%xmm5", "%xmm6", "%xmm7",) \ - "memory" \ - ); - -#define MIX_MISC(stereo) \ - __asm__ volatile ( \ - "mov %5, %2 \n" \ - "1: \n" \ - "mov -%c7(%6, %2, %c8), %3 \n" \ - "movaps (%3, %0), %%xmm0 \n" \ - stereo("movaps %%xmm0, %%xmm1 \n") \ - "mulps %%xmm4, %%xmm0 \n" \ - stereo("mulps %%xmm5, %%xmm1 \n") \ - "2: \n" \ - "mov (%6, %2, %c8), %1 \n" \ - "movaps (%1, %0), %%xmm2 \n" \ - stereo("movaps %%xmm2, %%xmm3 \n") \ - "mulps (%4, %2, 8), %%xmm2 \n" \ - stereo("mulps 16(%4, %2, 8), %%xmm3 \n") \ - "addps %%xmm2, %%xmm0 \n" \ - stereo("addps %%xmm3, %%xmm1 \n") \ - "add $4, %2 \n" \ - "jl 2b \n" \ - "mov %5, %2 \n" \ - stereo("mov (%6, %2, %c8), %1 \n") \ - "movaps %%xmm0, (%3, %0) \n" \ - stereo("movaps %%xmm1, (%1, %0) \n") \ - "add $16, %0 \n" \ - "jl 1b \n" \ - : "+&r"(i), "=&r"(j), "=&r"(k), "=&r"(m) \ - : "r"(matrix_simd + in_ch), \ - "g"((intptr_t) - 4 * (in_ch - 1)), \ - "r"(samp + in_ch), \ - "i"(sizeof(float *)), "i"(sizeof(float *)/4) \ - : "memory" \ - ); - -static void ac3_downmix_sse(float **samples, float **matrix, - int out_ch, int in_ch, int len) -{ - int **matrix_cmp = (int **)matrix; - intptr_t i, j, k, m; - - i = -len * sizeof(float); - if (in_ch == 5 && out_ch == 2 && - !(matrix_cmp[1][0] | matrix_cmp[0][2] | - matrix_cmp[1][3] | matrix_cmp[0][4] | - (matrix_cmp[0][1] ^ matrix_cmp[1][1]) | - (matrix_cmp[0][0] ^ matrix_cmp[1][2]))) { - MIX5(IF0, IF1); - } else if (in_ch == 5 && out_ch == 1 && - matrix_cmp[0][0] == matrix_cmp[0][2] && - matrix_cmp[0][3] == matrix_cmp[0][4]) { - MIX5(IF1, IF0); - } else { - DECLARE_ALIGNED(16, float, matrix_simd)[AC3_MAX_CHANNELS][2][4]; - float *samp[AC3_MAX_CHANNELS]; - - for (j = 0; j < in_ch; j++) - samp[j] = samples[j] + len; - - j = 2 * in_ch * sizeof(float); - k = in_ch * sizeof(float); - __asm__ volatile ( - "1: \n" - "sub $4, %1 \n" - "sub $8, %0 \n" - "movss (%3, %1), %%xmm4 \n" - "movss (%4, %1), %%xmm5 \n" - "shufps $0, %%xmm4, %%xmm4 \n" - "shufps $0, %%xmm5, %%xmm5 \n" - "movaps %%xmm4, (%2, %0, 4) \n" - "movaps %%xmm5, 16(%2, %0, 4) \n" - "jg 1b \n" - : "+&r"(j), "+&r"(k) - : "r"(matrix_simd), "r"(matrix[0]), "r"(matrix[1]) - : "memory" - ); - if (out_ch == 2) { - MIX_MISC(IF1); - } else { - MIX_MISC(IF0); - } - } -} - -#endif /* HAVE_SSE_INLINE && HAVE_7REGS */ - av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact) { int cpu_flags = av_get_cpu_flags(); @@ -247,10 +118,47 @@ av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact) c->apply_window_int16 = ff_apply_window_int16_ssse3; } } +} + +#define DOWNMIX_FUNC_OPT(ch, opt) \ +void ff_ac3_downmix_ ## ch ## _to_1_ ## opt(float **samples, \ + float **matrix, int len); \ +void ff_ac3_downmix_ ## ch ## _to_2_ ## opt(float **samples, \ + float **matrix, int len); + +#define DOWNMIX_FUNCS(opt) \ + DOWNMIX_FUNC_OPT(3, opt) \ + DOWNMIX_FUNC_OPT(4, opt) \ + DOWNMIX_FUNC_OPT(5, opt) \ + DOWNMIX_FUNC_OPT(6, opt) + +DOWNMIX_FUNCS(sse) +DOWNMIX_FUNCS(avx) +DOWNMIX_FUNCS(fma3) + +void ff_ac3dsp_set_downmix_x86(AC3DSPContext *c) +{ + int cpu_flags = av_get_cpu_flags(); + +#define SET_DOWNMIX(ch, suf, SUF) \ + if (ch == c->in_channels) { \ + if (EXTERNAL_ ## SUF (cpu_flags)) { \ + if (c->out_channels == 1) \ + c->downmix = ff_ac3_downmix_ ## ch ## _to_1_ ## suf; \ + else \ + c->downmix = ff_ac3_downmix_ ## ch ## _to_2_ ## suf; \ + } \ + } + +#define SET_DOWNMIX_ALL(suf, SUF) \ + SET_DOWNMIX(3, suf, SUF) \ + SET_DOWNMIX(4, suf, SUF) \ + SET_DOWNMIX(5, suf, SUF) \ + SET_DOWNMIX(6, suf, SUF) -#if HAVE_SSE_INLINE && HAVE_7REGS - if (INLINE_SSE(cpu_flags)) { - c->downmix = ac3_downmix_sse; + SET_DOWNMIX_ALL(sse, SSE) + if (!(cpu_flags & AV_CPU_FLAG_AVXSLOW)) { + SET_DOWNMIX_ALL(avx, AVX) + SET_DOWNMIX_ALL(fma3, FMA3) } -#endif } |