aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/x86/aacpsdsp.asm
blob: 105e1af5c56be540dfbedf1175fb083df313dd5e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
;******************************************************************************
;* SIMD optimized MPEG-4 Parametric Stereo decoding functions
;*
;* Copyright (C) 2015 James Almer
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg is free software; you can redistribute it and/or
;* modify it under the terms of the GNU Lesser General Public
;* License as published by the Free Software Foundation; either
;* version 2.1 of the License, or (at your option) any later version.
;*
;* FFmpeg is distributed in the hope that it will be useful,
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************

%include "libavutil/x86/x86util.asm"

SECTION_RODATA

ps_p1m1p1m1: dd 0, 0x80000000, 0, 0x80000000

SECTION .text

;*************************************************************************
;void ff_ps_add_squares_<opt>(float *dst, const float (*src)[2], int n);
;*************************************************************************
%macro PS_ADD_SQUARES 1
cglobal ps_add_squares, 3, 3, %1, dst, src, n
    shl    nd, 3
    add  srcq, nq
    neg    nq

align 16
.loop:
    movaps m0, [srcq+nq]
    movaps m1, [srcq+nq+mmsize]
    mulps  m0, m0
    mulps  m1, m1
    HADDPS m0, m1, m2
    addps  m0, [dstq]
    movaps [dstq], m0
    add  dstq, mmsize
    add    nq, mmsize*2
    jl .loop
    REP_RET
%endmacro

INIT_XMM sse
PS_ADD_SQUARES 2
INIT_XMM sse3
PS_ADD_SQUARES 3

;*******************************************************************
;void ff_ps_mul_pair_single_sse(float (*dst)[2], float (*src0)[2],
;                                   float *src1, int n);
;*******************************************************************
INIT_XMM sse
cglobal ps_mul_pair_single, 4, 4, 4, dst, src1, src2, n
    shl      nd, 3
    add   src1q, nq
    add    dstq, nq
    neg      nq

align 16
.loop:
    movu     m0, [src1q+nq]
    movu     m1, [src1q+nq+mmsize]
    mova     m2, [src2q]
    mova     m3, m2
    unpcklps m2, m2
    unpckhps m3, m3
    mulps    m0, m2
    mulps    m1, m3
    mova [dstq+nq], m0
    mova [dstq+nq+mmsize], m1
    add   src2q, mmsize
    add      nq, mmsize*2
    jl .loop
    REP_RET

;***********************************************************************
;void ff_ps_stereo_interpolate_sse3(float (*l)[2], float (*r)[2],
;                                   float h[2][4], float h_step[2][4],
;                                   int len);
;***********************************************************************
INIT_XMM sse3
cglobal ps_stereo_interpolate, 5, 5, 6, l, r, h, h_step, n
    movaps   m0, [hq]
    movaps   m1, [h_stepq]
    unpcklps m4, m0, m0
    unpckhps m0, m0
    unpcklps m5, m1, m1
    unpckhps m1, m1
    shl      nd, 3
    add      lq, nq
    add      rq, nq
    neg      nq

align 16
.loop:
    addps    m4, m5
    addps    m0, m1
    movddup  m2, [lq+nq]
    movddup  m3, [rq+nq]
    mulps    m2, m4
    mulps    m3, m0
    addps    m2, m3
    movsd  [lq+nq], m2
    movhps [rq+nq], m2
    add      nq, 8
    jl .loop
    REP_RET

;***************************************************************************
;void ps_stereo_interpolate_ipdopd_sse3(float (*l)[2], float (*r)[2],
;                                       float h[2][4], float h_step[2][4],
;                                       int len);
;***************************************************************************
INIT_XMM sse3
cglobal ps_stereo_interpolate_ipdopd, 5, 5, 10, l, r, h, h_step, n
    movaps   m0, [hq]
    movaps   m1, [hq+mmsize]
%if ARCH_X86_64
    movaps   m8, [h_stepq]
    movaps   m9, [h_stepq+mmsize]
    %define  H_STEP0 m8
    %define  H_STEP1 m9
%else
    %define  H_STEP0 [h_stepq]
    %define  H_STEP1 [h_stepq+mmsize]
%endif
    shl      nd, 3
    add      lq, nq
    add      rq, nq
    neg      nq

align 16
.loop:
    addps    m0, H_STEP0
    addps    m1, H_STEP1
    movddup  m2, [lq+nq]
    movddup  m3, [rq+nq]
    shufps   m4, m2, m2, q2301
    shufps   m5, m3, m3, q2301
    unpcklps m6, m0, m0
    unpckhps m7, m0, m0
    mulps    m2, m6
    mulps    m3, m7
    unpcklps m6, m1, m1
    unpckhps m7, m1, m1
    mulps    m4, m6
    mulps    m5, m7
    addps    m2, m3
    addsubps m2, m4
    addsubps m2, m5
    movsd  [lq+nq], m2
    movhps [rq+nq], m2
    add      nq, 8
    jl .loop
    REP_RET

;**********************************************************
;void ps_hybrid_analysis_ileave_sse(float out[2][38][64],
;                                   float (*in)[32][2],
;                                   int i, int len)
;**********************************************************
INIT_XMM sse
cglobal ps_hybrid_analysis_ileave, 3, 7, 5, out, in, i, len, in0, in1, tmp
    movsxdifnidn        iq, id
    mov               lend, 32 << 3
    lea                inq, [inq+iq*4]
    mov               tmpd, id
    shl               tmpd, 8
    add               outq, tmpq
    mov               tmpd, 64
    sub               tmpd, id
    mov                 id, tmpd

    test                id, 1
    jne .loop4
    test                id, 2
    jne .loop8

align 16
.loop16:
    mov               in0q, inq
    mov               in1q, 38*64*4
    add               in1q, in0q
    mov               tmpd, lend

.inner_loop16:
    movaps              m0, [in0q]
    movaps              m1, [in1q]
    movaps              m2, [in0q+lenq]
    movaps              m3, [in1q+lenq]
    TRANSPOSE4x4PS 0, 1, 2, 3, 4
    movaps          [outq], m0
    movaps     [outq+lenq], m1
    movaps   [outq+lenq*2], m2
    movaps [outq+3*32*2*4], m3
    lea               in0q, [in0q+lenq*2]
    lea               in1q, [in1q+lenq*2]
    add               outq, mmsize
    sub               tmpd, mmsize
    jg .inner_loop16
    add                inq, 16
    add               outq, 3*32*2*4
    sub                 id, 4
    jg .loop16
    RET

align 16
.loop8:
    mov               in0q, inq
    mov               in1q, 38*64*4
    add               in1q, in0q
    mov               tmpd, lend

.inner_loop8:
    movlps              m0, [in0q]
    movlps              m1, [in1q]
    movhps              m0, [in0q+lenq]
    movhps              m1, [in1q+lenq]
    SBUTTERFLYPS 0, 1, 2
    SBUTTERFLYPD 0, 1, 2
    movaps          [outq], m0
    movaps     [outq+lenq], m1
    lea               in0q, [in0q+lenq*2]
    lea               in1q, [in1q+lenq*2]
    add               outq, mmsize
    sub               tmpd, mmsize
    jg .inner_loop8
    add                inq, 8
    add               outq, lenq
    sub                 id, 2
    jg .loop16
    RET

align 16
.loop4:
    mov               in0q, inq
    mov               in1q, 38*64*4
    add               in1q, in0q
    mov               tmpd, lend

.inner_loop4:
    movss               m0, [in0q]
    movss               m1, [in1q]
    movss               m2, [in0q+lenq]
    movss               m3, [in1q+lenq]
    movlhps             m0, m1
    movlhps             m2, m3
    shufps              m0, m2, q2020
    movaps          [outq], m0
    lea               in0q, [in0q+lenq*2]
    lea               in1q, [in1q+lenq*2]
    add               outq, mmsize
    sub               tmpd, mmsize
    jg .inner_loop4
    add                inq, 4
    sub                 id, 1
    test                id, 2
    jne .loop8
    cmp                 id, 4
    jge .loop16
    RET

;***********************************************************
;void ps_hybrid_synthesis_deint_sse4(float out[2][38][64],
;                                    float (*in)[32][2],
;                                    int i, int len)
;***********************************************************
%macro HYBRID_SYNTHESIS_DEINT 0
cglobal ps_hybrid_synthesis_deint, 3, 7, 5, out, in, i, len, out0, out1, tmp
%if cpuflag(sse4)
%define MOVH movsd
%else
%define MOVH movlps
%endif
    movsxdifnidn        iq, id
    mov               lend, 32 << 3
    lea               outq, [outq+iq*4]
    mov               tmpd, id
    shl               tmpd, 8
    add                inq, tmpq
    mov               tmpd, 64
    sub               tmpd, id
    mov                 id, tmpd

    test                id, 1
    jne .loop4
    test                id, 2
    jne .loop8

align 16
.loop16:
    mov              out0q, outq
    mov              out1q, 38*64*4
    add              out1q, out0q
    mov               tmpd, lend

.inner_loop16:
    movaps              m0, [inq]
    movaps              m1, [inq+lenq]
    movaps              m2, [inq+lenq*2]
    movaps              m3, [inq+3*32*2*4]
    TRANSPOSE4x4PS 0, 1, 2, 3, 4
    movaps         [out0q], m0
    movaps         [out1q], m1
    movaps    [out0q+lenq], m2
    movaps    [out1q+lenq], m3
    lea              out0q, [out0q+lenq*2]
    lea              out1q, [out1q+lenq*2]
    add                inq, mmsize
    sub               tmpd, mmsize
    jg .inner_loop16
    add               outq, 16
    add                inq, 3*32*2*4
    sub                 id, 4
    jg .loop16
    RET

align 16
.loop8:
    mov              out0q, outq
    mov              out1q, 38*64*4
    add              out1q, out0q
    mov               tmpd, lend

.inner_loop8:
    movaps              m0, [inq]
    movaps              m1, [inq+lenq]
    SBUTTERFLYPS 0, 1, 2
    SBUTTERFLYPD 0, 1, 2
    MOVH           [out0q], m0
    MOVH           [out1q], m1
    movhps    [out0q+lenq], m0
    movhps    [out1q+lenq], m1
    lea              out0q, [out0q+lenq*2]
    lea              out1q, [out1q+lenq*2]
    add                inq, mmsize
    sub               tmpd, mmsize
    jg .inner_loop8
    add               outq, 8
    add                inq, lenq
    sub                 id, 2
    jg .loop16
    RET

align 16
.loop4:
    mov              out0q, outq
    mov              out1q, 38*64*4
    add              out1q, out0q
    mov               tmpd, lend

.inner_loop4:
    movaps              m0, [inq]
    movss          [out0q], m0
%if cpuflag(sse4)
    extractps      [out1q], m0, 1
    extractps [out0q+lenq], m0, 2
    extractps [out1q+lenq], m0, 3
%else
    movhlps             m1, m0
    movss     [out0q+lenq], m1
    shufps              m0, m0, 0xb1
    movss          [out1q], m0
    movhlps             m1, m0
    movss     [out1q+lenq], m1
%endif
    lea              out0q, [out0q+lenq*2]
    lea              out1q, [out1q+lenq*2]
    add                inq, mmsize
    sub               tmpd, mmsize
    jg .inner_loop4
    add               outq, 4
    sub                 id, 1
    test                id, 2
    jne .loop8
    cmp                 id, 4
    jge .loop16
    RET
%endmacro

INIT_XMM sse
HYBRID_SYNTHESIS_DEINT
INIT_XMM sse4
HYBRID_SYNTHESIS_DEINT

;*******************************************************************
;void ff_ps_hybrid_analysis_<opt>(float (*out)[2], float (*in)[2],
;                                 const float (*filter)[8][2],
;                                 ptrdiff_t stride, int n);
;*******************************************************************
%macro PS_HYBRID_ANALYSIS_IN 1
    movu     m0, [inq+mmsize*%1]
    movu     m1, [inq+mmsize*(5-%1)+8]
    shufps   m3, m0, m0, q2301
    shufps   m4, m1, m1, q0123
    shufps   m1, m1, q1032
%if cpuflag(sse3)
    addsubps m3, m4
    addsubps m0, m1
%else
    xorps    m4, m7
    xorps    m1, m7
    subps    m3, m4
    subps    m0, m1
%endif
    mova  [rsp+mmsize*%1*2], m3
    mova  [rsp+mmsize+mmsize*%1*2], m0
%endmacro

%macro PS_HYBRID_ANALYSIS_LOOP 3
    mova     m2, [filterq+nq+mmsize*%3]
    shufps   m2, m2, q2301
%if cpuflag(fma3)
%if %3
    fmaddps  m3, m2, [rsp+mmsize*%3*2], m3
    fmaddps  m0, m2, [rsp+mmsize+mmsize*%3*2], m0
%else
    mulps    m3, m2, [rsp]
    mulps    m0, m2, [rsp+mmsize]
%endif
%else ; cpuflag(sse)
    mova     %2, [rsp+mmsize*%3*2]
    mova     %1, [rsp+mmsize+mmsize*%3*2]
    mulps    %2, m2
    mulps    %1, m2
%if %3
    addps    m3, %2
    addps    m0, %1
%endif
%endif
%endmacro

%macro PS_HYBRID_ANALYSIS 0
cglobal ps_hybrid_analysis, 5, 5, 5 + notcpuflag(fma3) * 3, 24 * 4, out, in, filter, stride, n
%if cpuflag(sse3)
%define MOVH movsd
%else
%define MOVH movlps
    mova m7, [ps_p1m1p1m1]
%endif
    shl strideq, 3
    shl nd, 6
    add filterq, nq
    neg nq
    PS_HYBRID_ANALYSIS_IN 0
    PS_HYBRID_ANALYSIS_IN 1
    PS_HYBRID_ANALYSIS_IN 2

align 16
.loop:
    PS_HYBRID_ANALYSIS_LOOP m0, m3, 0
    PS_HYBRID_ANALYSIS_LOOP m5, m6, 1
    PS_HYBRID_ANALYSIS_LOOP m5, m6, 2

    shufps   m1, m3, m3, q2301
    shufps   m2, m0, m0, q2301
    subps    m1, m3
    addps    m2, m0
    unpcklps m3, m1, m2
    unpckhps m1, m2
    addps    m1, m3
    movu     m2, [inq+6*8] ; faster than movlps and no risk of overread
    movss    m3, [filterq+nq+8*6]
    SPLATD   m3
%if cpuflag(fma3)
    fmaddps  m1, m2, m3, m1
%else
    mulps    m2, m3
    addps    m1, m2
%endif
    MOVH [outq], m1
    add    outq, strideq
    add      nq, 64
    jl .loop
    REP_RET
%endmacro

INIT_XMM sse
PS_HYBRID_ANALYSIS
INIT_XMM fma3
PS_HYBRID_ANALYSIS