x86: ac3dsp: Drop forward declaration for nonexisting function
[libav.git] / libavcodec / x86 / ac3dsp_init.c
CommitLineData
dda3f0ef 1/*
831a1180 2 * x86-optimized AC-3 DSP functions
dda3f0ef
JR
3 * Copyright (c) 2011 Justin Ruggles
4 *
2912e87a 5 * This file is part of Libav.
dda3f0ef 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
dda3f0ef
JR
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
dda3f0ef
JR
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
2912e87a 18 * License along with Libav; if not, write to the Free Software
dda3f0ef
JR
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
b0be1ae7 22#include "libavutil/attributes.h"
97cb9236 23#include "libavutil/mem.h"
c318626c 24#include "libavutil/x86/asm.h"
e0c6cce4 25#include "libavutil/x86/cpu.h"
97cb9236 26#include "libavcodec/ac3.h"
dda3f0ef
JR
27#include "libavcodec/ac3dsp.h"
28
b6649ab5
DB
29void ff_ac3_exponent_min_mmx (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
30void ff_ac3_exponent_min_mmxext(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
31void ff_ac3_exponent_min_sse2 (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
dda3f0ef 32
b6649ab5
DB
33int ff_ac3_max_msb_abs_int16_mmx (const int16_t *src, int len);
34int ff_ac3_max_msb_abs_int16_mmxext(const int16_t *src, int len);
35int ff_ac3_max_msb_abs_int16_sse2 (const int16_t *src, int len);
36int ff_ac3_max_msb_abs_int16_ssse3(const int16_t *src, int len);
fbb6b49d 37
b6649ab5
DB
38void ff_ac3_lshift_int16_mmx (int16_t *src, unsigned int len, unsigned int shift);
39void ff_ac3_lshift_int16_sse2(int16_t *src, unsigned int len, unsigned int shift);
f1efbca5 40
b6649ab5
DB
41void ff_ac3_rshift_int32_mmx (int32_t *src, unsigned int len, unsigned int shift);
42void ff_ac3_rshift_int32_sse2(int32_t *src, unsigned int len, unsigned int shift);
f1efbca5 43
b6649ab5
DB
44void ff_float_to_fixed24_3dnow(int32_t *dst, const float *src, unsigned int len);
45void ff_float_to_fixed24_sse (int32_t *dst, const float *src, unsigned int len);
46void ff_float_to_fixed24_sse2 (int32_t *dst, const float *src, unsigned int len);
0f999cfd 47
b6649ab5 48int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16]);
6ca23db9 49
b6649ab5
DB
50void ff_ac3_extract_exponents_sse2 (uint8_t *exp, int32_t *coef, int nb_coefs);
51void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_coefs);
f99a5ef9 52
4958f35a
DB
53void ff_apply_window_int16_round_mmxext(int16_t *output, const int16_t *input,
54 const int16_t *window, unsigned int len);
55void ff_apply_window_int16_round_sse2(int16_t *output, const int16_t *input,
56 const int16_t *window, unsigned int len);
57void ff_apply_window_int16_mmxext(int16_t *output, const int16_t *input,
58 const int16_t *window, unsigned int len);
59void ff_apply_window_int16_sse2(int16_t *output, const int16_t *input,
60 const int16_t *window, unsigned int len);
61void ff_apply_window_int16_ssse3(int16_t *output, const int16_t *input,
62 const int16_t *window, unsigned int len);
63void ff_apply_window_int16_ssse3_atom(int16_t *output, const int16_t *input,
64 const int16_t *window, unsigned int len);
65
30b39164 66#if HAVE_SSE_INLINE && HAVE_7REGS
97cb9236
MR
67
68#define IF1(x) x
69#define IF0(x)
70
71#define MIX5(mono, stereo) \
72 __asm__ volatile ( \
30b39164
MR
73 "movss 0(%1), %%xmm5 \n" \
74 "movss 8(%1), %%xmm6 \n" \
75 "movss 24(%1), %%xmm7 \n" \
97cb9236
MR
76 "shufps $0, %%xmm5, %%xmm5 \n" \
77 "shufps $0, %%xmm6, %%xmm6 \n" \
78 "shufps $0, %%xmm7, %%xmm7 \n" \
79 "1: \n" \
30b39164
MR
80 "movaps (%0, %2), %%xmm0 \n" \
81 "movaps (%0, %3), %%xmm1 \n" \
82 "movaps (%0, %4), %%xmm2 \n" \
83 "movaps (%0, %5), %%xmm3 \n" \
84 "movaps (%0, %6), %%xmm4 \n" \
97cb9236
MR
85 "mulps %%xmm5, %%xmm0 \n" \
86 "mulps %%xmm6, %%xmm1 \n" \
87 "mulps %%xmm5, %%xmm2 \n" \
88 "mulps %%xmm7, %%xmm3 \n" \
89 "mulps %%xmm7, %%xmm4 \n" \
90 stereo("addps %%xmm1, %%xmm0 \n") \
91 "addps %%xmm1, %%xmm2 \n" \
92 "addps %%xmm3, %%xmm0 \n" \
93 "addps %%xmm4, %%xmm2 \n" \
94 mono("addps %%xmm2, %%xmm0 \n") \
30b39164
MR
95 "movaps %%xmm0, (%0, %2) \n" \
96 stereo("movaps %%xmm2, (%0, %3) \n") \
97cb9236
MR
97 "add $16, %0 \n" \
98 "jl 1b \n" \
99 : "+&r"(i) \
30b39164
MR
100 : "r"(matrix), \
101 "r"(samples[0] + len), \
102 "r"(samples[1] + len), \
103 "r"(samples[2] + len), \
104 "r"(samples[3] + len), \
105 "r"(samples[4] + len) \
97cb9236
MR
106 : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \
107 "%xmm4", "%xmm5", "%xmm6", "%xmm7",) \
108 "memory" \
109 );
110
111#define MIX_MISC(stereo) \
112 __asm__ volatile ( \
30b39164 113 "mov %5, %2 \n" \
97cb9236 114 "1: \n" \
30b39164 115 "mov -%c7(%6, %2, %c8), %3 \n" \
97cb9236
MR
116 "movaps (%3, %0), %%xmm0 \n" \
117 stereo("movaps %%xmm0, %%xmm1 \n") \
118 "mulps %%xmm4, %%xmm0 \n" \
119 stereo("mulps %%xmm5, %%xmm1 \n") \
97cb9236 120 "2: \n" \
30b39164
MR
121 "mov (%6, %2, %c8), %1 \n" \
122 "movaps (%1, %0), %%xmm2 \n" \
97cb9236 123 stereo("movaps %%xmm2, %%xmm3 \n") \
30b39164
MR
124 "mulps (%4, %2, 8), %%xmm2 \n" \
125 stereo("mulps 16(%4, %2, 8), %%xmm3 \n") \
97cb9236
MR
126 "addps %%xmm2, %%xmm0 \n" \
127 stereo("addps %%xmm3, %%xmm1 \n") \
30b39164 128 "add $4, %2 \n" \
97cb9236 129 "jl 2b \n" \
30b39164
MR
130 "mov %5, %2 \n" \
131 stereo("mov (%6, %2, %c8), %1 \n") \
132 "movaps %%xmm0, (%3, %0) \n" \
133 stereo("movaps %%xmm1, (%1, %0) \n") \
97cb9236
MR
134 "add $16, %0 \n" \
135 "jl 1b \n" \
30b39164
MR
136 : "+&r"(i), "=&r"(j), "=&r"(k), "=&r"(m) \
137 : "r"(matrix_simd + in_ch), \
138 "g"((intptr_t) - 4 * (in_ch - 1)), \
139 "r"(samp + in_ch), \
140 "i"(sizeof(float *)), "i"(sizeof(float *)/4) \
97cb9236
MR
141 : "memory" \
142 );
143
30b39164 144static void ac3_downmix_sse(float **samples, float (*matrix)[2],
97cb9236
MR
145 int out_ch, int in_ch, int len)
146{
147 int (*matrix_cmp)[2] = (int(*)[2])matrix;
30b39164 148 intptr_t i, j, k, m;
97cb9236
MR
149
150 i = -len * sizeof(float);
151 if (in_ch == 5 && out_ch == 2 &&
152 !(matrix_cmp[0][1] | matrix_cmp[2][0] |
153 matrix_cmp[3][1] | matrix_cmp[4][0] |
154 (matrix_cmp[1][0] ^ matrix_cmp[1][1]) |
155 (matrix_cmp[0][0] ^ matrix_cmp[2][1]))) {
156 MIX5(IF0, IF1);
157 } else if (in_ch == 5 && out_ch == 1 &&
158 matrix_cmp[0][0] == matrix_cmp[2][0] &&
159 matrix_cmp[3][0] == matrix_cmp[4][0]) {
160 MIX5(IF1, IF0);
161 } else {
162 DECLARE_ALIGNED(16, float, matrix_simd)[AC3_MAX_CHANNELS][2][4];
30b39164
MR
163 float *samp[AC3_MAX_CHANNELS];
164
165 for (j = 0; j < in_ch; j++)
166 samp[j] = samples[j] + len;
167
97cb9236
MR
168 j = 2 * in_ch * sizeof(float);
169 __asm__ volatile (
170 "1: \n"
171 "sub $8, %0 \n"
172 "movss (%2, %0), %%xmm4 \n"
173 "movss 4(%2, %0), %%xmm5 \n"
174 "shufps $0, %%xmm4, %%xmm4 \n"
175 "shufps $0, %%xmm5, %%xmm5 \n"
176 "movaps %%xmm4, (%1, %0, 4) \n"
177 "movaps %%xmm5, 16(%1, %0, 4) \n"
178 "jg 1b \n"
179 : "+&r"(j)
180 : "r"(matrix_simd), "r"(matrix)
181 : "memory"
182 );
183 if (out_ch == 2) {
184 MIX_MISC(IF1);
185 } else {
186 MIX_MISC(IF0);
187 }
188 }
189}
190
30b39164 191#endif /* HAVE_SSE_INLINE && HAVE_7REGS */
97cb9236 192
0f999cfd 193av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact)
dda3f0ef 194{
3ac7fa81 195 int cpu_flags = av_get_cpu_flags();
dda3f0ef 196
3ac7fa81 197 if (EXTERNAL_MMX(cpu_flags)) {
dda3f0ef 198 c->ac3_exponent_min = ff_ac3_exponent_min_mmx;
fbb6b49d 199 c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx;
f1efbca5
JR
200 c->ac3_lshift_int16 = ff_ac3_lshift_int16_mmx;
201 c->ac3_rshift_int32 = ff_ac3_rshift_int32_mmx;
dda3f0ef 202 }
3ac7fa81 203 if (EXTERNAL_AMD3DNOW(cpu_flags)) {
0f999cfd
JR
204 if (!bit_exact) {
205 c->float_to_fixed24 = ff_float_to_fixed24_3dnow;
206 }
207 }
3ac7fa81 208 if (EXTERNAL_MMXEXT(cpu_flags)) {
dda3f0ef 209 c->ac3_exponent_min = ff_ac3_exponent_min_mmxext;
26301caa 210 c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmxext;
4958f35a
DB
211 if (bit_exact) {
212 c->apply_window_int16 = ff_apply_window_int16_mmxext;
213 } else {
214 c->apply_window_int16 = ff_apply_window_int16_round_mmxext;
215 }
dda3f0ef 216 }
3ac7fa81 217 if (EXTERNAL_SSE(cpu_flags)) {
0f999cfd
JR
218 c->float_to_fixed24 = ff_float_to_fixed24_sse;
219 }
3ac7fa81 220 if (EXTERNAL_SSE2(cpu_flags)) {
dda3f0ef 221 c->ac3_exponent_min = ff_ac3_exponent_min_sse2;
fbb6b49d 222 c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_sse2;
0f999cfd 223 c->float_to_fixed24 = ff_float_to_fixed24_sse2;
6ca23db9 224 c->compute_mantissa_size = ff_ac3_compute_mantissa_size_sse2;
f99a5ef9 225 c->extract_exponents = ff_ac3_extract_exponents_sse2;
3ac7fa81 226 if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
f1efbca5
JR
227 c->ac3_lshift_int16 = ff_ac3_lshift_int16_sse2;
228 c->ac3_rshift_int32 = ff_ac3_rshift_int32_sse2;
229 }
4958f35a
DB
230 if (bit_exact) {
231 c->apply_window_int16 = ff_apply_window_int16_sse2;
232 } else if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
233 c->apply_window_int16 = ff_apply_window_int16_round_sse2;
234 }
fbb6b49d 235 }
3ac7fa81 236 if (EXTERNAL_SSSE3(cpu_flags)) {
fbb6b49d 237 c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_ssse3;
4958f35a
DB
238 if (cpu_flags & AV_CPU_FLAG_ATOM) {
239 c->apply_window_int16 = ff_apply_window_int16_ssse3_atom;
240 } else {
f99a5ef9 241 c->extract_exponents = ff_ac3_extract_exponents_ssse3;
4958f35a 242 c->apply_window_int16 = ff_apply_window_int16_ssse3;
f99a5ef9 243 }
dda3f0ef 244 }
97cb9236 245
30b39164 246#if HAVE_SSE_INLINE && HAVE_7REGS
3ac7fa81 247 if (INLINE_SSE(cpu_flags)) {
97cb9236
MR
248 c->downmix = ac3_downmix_sse;
249 }
91ff4e83 250#endif
dda3f0ef 251}