replaygain: remove unused variable
[libav.git] / libavcodec / x86 / dcadsp.asm
1 ;******************************************************************************
2 ;* SSE-optimized functions for the DCA decoder
3 ;* Copyright (C) 2012-2014 Christophe Gisquet <christophe.gisquet@gmail.com>
4 ;*
5 ;* This file is part of Libav.
6 ;*
7 ;* Libav is free software; you can redistribute it and/or
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 ;*
12 ;* Libav is distributed in the hope that it will be useful,
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
18 ;* License along with Libav; if not, write to the Free Software
19 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ;******************************************************************************
21
22 %include "libavutil/x86/x86util.asm"
23
24 SECTION_RODATA
25 pf_inv16: times 4 dd 0x3D800000 ; 1/16
26
27 SECTION_TEXT
28
29 ; void decode_hf(float dst[DCA_SUBBANDS][8], const int32_t vq_num[DCA_SUBBANDS],
30 ; const int8_t hf_vq[1024][32], intptr_t vq_offset,
31 ; int32_t scale[DCA_SUBBANDS][2], intptr_t start, intptr_t end)
32
33 %macro DECODE_HF 0
34 cglobal decode_hf, 6,6,5, dst, num, src, offset, scale, start, end
35 lea srcq, [srcq + offsetq]
36 shl startq, 2
37 mov offsetd, endm
38 %define DICT offsetq
39 shl offsetq, 2
40 mov endm, offsetq
41 .loop:
42 %if ARCH_X86_64
43 mov offsetd, [scaleq + 2 * startq]
44 cvtsi2ss m0, offsetd
45 %else
46 cvtsi2ss m0, [scaleq + 2 * startq]
47 %endif
48 mov offsetd, [numq + startq]
49 mulss m0, [pf_inv16]
50 shl DICT, 5
51 shufps m0, m0, 0
52 %if cpuflag(sse2)
53 %if cpuflag(sse4)
54 pmovsxbd m1, [srcq + DICT + 0]
55 pmovsxbd m2, [srcq + DICT + 4]
56 %else
57 movq m1, [srcq + DICT]
58 punpcklbw m1, m1
59 mova m2, m1
60 punpcklwd m1, m1
61 punpckhwd m2, m2
62 psrad m1, 24
63 psrad m2, 24
64 %endif
65 cvtdq2ps m1, m1
66 cvtdq2ps m2, m2
67 %else
68 movd mm0, [srcq + DICT + 0]
69 movd mm1, [srcq + DICT + 4]
70 punpcklbw mm0, mm0
71 punpcklbw mm1, mm1
72 movq mm2, mm0
73 movq mm3, mm1
74 punpcklwd mm0, mm0
75 punpcklwd mm1, mm1
76 punpckhwd mm2, mm2
77 punpckhwd mm3, mm3
78 psrad mm0, 24
79 psrad mm1, 24
80 psrad mm2, 24
81 psrad mm3, 24
82 cvtpi2ps m1, mm0
83 cvtpi2ps m2, mm1
84 cvtpi2ps m3, mm2
85 cvtpi2ps m4, mm3
86 shufps m0, m0, 0
87 shufps m1, m3, q1010
88 shufps m2, m4, q1010
89 %endif
90 mulps m1, m0
91 mulps m2, m0
92 mova [dstq + 8 * startq + 0], m1
93 mova [dstq + 8 * startq + 16], m2
94 add startq, 4
95 cmp startq, endm
96 jl .loop
97 .end:
98 %if notcpuflag(sse2)
99 emms
100 %endif
101 REP_RET
102 %endmacro
103
104 %if ARCH_X86_32
105 INIT_XMM sse
106 DECODE_HF
107 %endif
108
109 INIT_XMM sse2
110 DECODE_HF
111
112 INIT_XMM sse4
113 DECODE_HF
114
115 ; %1=v0/v1 %2=in1 %3=in2
116 %macro FIR_LOOP 2-3
117 .loop%1:
118 %define va m1
119 %define vb m2
120 %if %1
121 %define OFFSET 0
122 %else
123 %define OFFSET NUM_COEF*count
124 %endif
125 ; for v0, incrementing and for v1, decrementing
126 mova va, [cf0q + OFFSET]
127 mova vb, [cf0q + OFFSET + 4*NUM_COEF]
128 %if %0 == 3
129 mova m4, [cf0q + OFFSET + mmsize]
130 mova m0, [cf0q + OFFSET + 4*NUM_COEF + mmsize]
131 %endif
132 mulps va, %2
133 mulps vb, %2
134 %if %0 == 3
135 mulps m4, %3
136 mulps m0, %3
137 addps va, m4
138 addps vb, m0
139 %endif
140 ; va = va1 va2 va3 va4
141 ; vb = vb1 vb2 vb3 vb4
142 %if %1
143 SWAP va, vb
144 %endif
145 mova m4, va
146 unpcklps va, vb ; va3 vb3 va4 vb4
147 unpckhps m4, vb ; va1 vb1 va2 vb2
148 addps m4, va ; va1+3 vb1+3 va2+4 vb2+4
149 movhlps vb, m4 ; va1+3 vb1+3
150 addps vb, m4 ; va0..4 vb0..4
151 movh [outq + count], vb
152 %if %1
153 sub cf0q, 8*NUM_COEF
154 %endif
155 add count, 8
156 jl .loop%1
157 %endmacro
158
159 ; void dca_lfe_fir(float *out, float *in, float *coefs)
160 %macro DCA_LFE_FIR 1
161 cglobal dca_lfe_fir%1, 3,3,6-%1, out, in, cf0
162 %define IN1 m3
163 %define IN2 m5
164 %define count inq
165 %define NUM_COEF 4*(2-%1)
166 %define NUM_OUT 32*(%1+1)
167
168 movu IN1, [inq + 4 - 1*mmsize]
169 shufps IN1, IN1, q0123
170 %if %1 == 0
171 movu IN2, [inq + 4 - 2*mmsize]
172 shufps IN2, IN2, q0123
173 %endif
174
175 mov count, -4*NUM_OUT
176 add cf0q, 4*NUM_COEF*NUM_OUT
177 add outq, 4*NUM_OUT
178 ; compute v0 first
179 %if %1 == 0
180 FIR_LOOP 0, IN1, IN2
181 %else
182 FIR_LOOP 0, IN1
183 %endif
184 shufps IN1, IN1, q0123
185 mov count, -4*NUM_OUT
186 ; cf1 already correctly positioned
187 add outq, 4*NUM_OUT ; outq now at out2
188 sub cf0q, 8*NUM_COEF
189 %if %1 == 0
190 shufps IN2, IN2, q0123
191 FIR_LOOP 1, IN2, IN1
192 %else
193 FIR_LOOP 1, IN1
194 %endif
195 RET
196 %endmacro
197
198 INIT_XMM sse
199 DCA_LFE_FIR 0
200 DCA_LFE_FIR 1
201
202 INIT_XMM sse2
203 %macro INNER_LOOP 1
204 ; reading backwards: ptr1 = synth_buf + j + i; ptr2 = synth_buf + j - i
205 ;~ a += window[i + j] * (-synth_buf[15 - i + j])
206 ;~ b += window[i + j + 16] * (synth_buf[i + j])
207 pshufd m5, [ptr2 + j + (15 - 3) * 4], q0123
208 mova m6, [ptr1 + j]
209 %if ARCH_X86_64
210 pshufd m11, [ptr2 + j + (15 - 3) * 4 - mmsize], q0123
211 mova m12, [ptr1 + j + mmsize]
212 %endif
213 mulps m6, [win + %1 + j + 16 * 4]
214 mulps m5, [win + %1 + j]
215 %if ARCH_X86_64
216 mulps m12, [win + %1 + j + mmsize + 16 * 4]
217 mulps m11, [win + %1 + j + mmsize]
218 %endif
219 addps m2, m6
220 subps m1, m5
221 %if ARCH_X86_64
222 addps m8, m12
223 subps m7, m11
224 %endif
225 ;~ c += window[i + j + 32] * (synth_buf[16 + i + j])
226 ;~ d += window[i + j + 48] * (synth_buf[31 - i + j])
227 pshufd m6, [ptr2 + j + (31 - 3) * 4], q0123
228 mova m5, [ptr1 + j + 16 * 4]
229 %if ARCH_X86_64
230 pshufd m12, [ptr2 + j + (31 - 3) * 4 - mmsize], q0123
231 mova m11, [ptr1 + j + mmsize + 16 * 4]
232 %endif
233 mulps m5, [win + %1 + j + 32 * 4]
234 mulps m6, [win + %1 + j + 48 * 4]
235 %if ARCH_X86_64
236 mulps m11, [win + %1 + j + mmsize + 32 * 4]
237 mulps m12, [win + %1 + j + mmsize + 48 * 4]
238 %endif
239 addps m3, m5
240 addps m4, m6
241 %if ARCH_X86_64
242 addps m9, m11
243 addps m10, m12
244 %endif
245 sub j, 64 * 4
246 %endmacro
247
248 ; void ff_synth_filter_inner_sse2(float *synth_buf, float synth_buf2[32],
249 ; const float window[512], float out[32],
250 ; intptr_t offset, float scale)
251 cglobal synth_filter_inner, 0, 6 + 4 * ARCH_X86_64, 7 + 6 * ARCH_X86_64, \
252 synth_buf, synth_buf2, window, out, off, scale
253 %define scale m0
254 %if ARCH_X86_32 || WIN64
255 movd scale, scalem
256 ; Make sure offset is in a register and not on the stack
257 %define OFFQ r4q
258 %else
259 %define OFFQ offq
260 %endif
261 pshufd m0, m0, 0
262 ; prepare inner counter limit 1
263 mov r5q, 480
264 sub r5q, offmp
265 and r5q, -64
266 shl r5q, 2
267 mov OFFQ, r5q
268 %define i r5q
269 mov i, 16 * 4 - (ARCH_X86_64 + 1) * mmsize ; main loop counter
270
271 %define buf2 synth_buf2q
272 %if ARCH_X86_32
273 mov buf2, synth_buf2mp
274 %endif
275 .mainloop
276 ; m1 = a m2 = b m3 = c m4 = d
277 pxor m3, m3
278 pxor m4, m4
279 mova m1, [buf2 + i]
280 mova m2, [buf2 + i + 16 * 4]
281 %if ARCH_X86_32
282 %define ptr1 r0q
283 %define ptr2 r1q
284 %define win r2q
285 %define j r3q
286 mov win, windowm
287 mov ptr1, synth_bufm
288 add win, i
289 add ptr1, i
290 %else ; ARCH_X86_64
291 %define ptr1 r6q
292 %define ptr2 r7q ; must be loaded
293 %define win r8q
294 %define j r9q
295 pxor m9, m9
296 pxor m10, m10
297 mova m7, [buf2 + i + mmsize]
298 mova m8, [buf2 + i + mmsize + 16 * 4]
299 lea win, [windowq + i]
300 lea ptr1, [synth_bufq + i]
301 %endif
302 mov ptr2, synth_bufmp
303 ; prepare the inner loop counter
304 mov j, OFFQ
305 sub ptr2, i
306 .loop1:
307 INNER_LOOP 0
308 jge .loop1
309
310 mov j, 448 * 4
311 sub j, OFFQ
312 jz .end
313 sub ptr1, j
314 sub ptr2, j
315 add win, OFFQ ; now at j-64, so define OFFSET
316 sub j, 64 * 4
317 .loop2:
318 INNER_LOOP 64 * 4
319 jge .loop2
320
321 .end:
322 %if ARCH_X86_32
323 mov buf2, synth_buf2m ; needed for next iteration anyway
324 mov outq, outmp ; j, which will be set again during it
325 %endif
326 ;~ out[i] = a * scale;
327 ;~ out[i + 16] = b * scale;
328 mulps m1, scale
329 mulps m2, scale
330 %if ARCH_X86_64
331 mulps m7, scale
332 mulps m8, scale
333 %endif
334 ;~ synth_buf2[i] = c;
335 ;~ synth_buf2[i + 16] = d;
336 mova [buf2 + i + 0 * 4], m3
337 mova [buf2 + i + 16 * 4], m4
338 %if ARCH_X86_64
339 mova [buf2 + i + 0 * 4 + mmsize], m9
340 mova [buf2 + i + 16 * 4 + mmsize], m10
341 %endif
342 ;~ out[i] = a;
343 ;~ out[i + 16] = a;
344 mova [outq + i + 0 * 4], m1
345 mova [outq + i + 16 * 4], m2
346 %if ARCH_X86_64
347 mova [outq + i + 0 * 4 + mmsize], m7
348 mova [outq + i + 16 * 4 + mmsize], m8
349 %endif
350 sub i, (ARCH_X86_64 + 1) * mmsize
351 jge .mainloop
352 RET