aboutsummaryrefslogtreecommitdiffstats
path: root/libavresample/arm/resample_neon.S
blob: a8181e55ce08736f4f309e47813590b936ca49db (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
/*
 * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
 *
 * This file is part of Libav.
 *
 * Libav 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.
 *
 * Libav 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 Libav; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "libavutil/arm/asm.S"

#include "asm-offsets.h"

.macro resample_one     fmt, es=2
function ff_resample_one_\fmt\()_neon, export=1
        push            {r4, r5}
        add             r1, r1, r2, lsl #\es

        ldr             r2, [r0, #PHASE_SHIFT+4] /* phase_mask */
        ldr             ip, [sp, #8] /* index */
        ldr             r5, [r0, #FILTER_LENGTH]
        and             r2, ip, r2 /* (index & phase_mask) */
        ldr             r4, [r0, #PHASE_SHIFT]
        lsr             r4, ip, r4 /* compute sample_index */
        mul             r2, r2, r5

        ldr             ip, [r0, #FILTER_BANK]
        add             r3, r3, r4, lsl #\es /* &src[sample_index] */

        cmp             r5, #8
        add             r0, ip, r2, lsl #\es /* filter = &filter_bank[...] */

        blt             5f
8:
        subs            r5, r5, #8
        LOAD4
        MUL4
7:
        LOAD4
        beq             6f
        cmp             r5, #8
        MLA4
        blt             4f
        subs            r5, r5, #8
        LOAD4
        MLA4
        b               7b
6:
        MLA4
        STORE
        pop             {r4, r5}
        bx              lr
5:
        INIT4
4:      /* remaining filter_length 1 to 7 */
        cmp             r5, #4
        blt             2f
        subs            r5, r5, #4
        LOAD4
        MLA4
        beq             0f
2:      /* remaining filter_length 1 to 3 */
        cmp             r5, #2
        blt             1f
        subs            r5, r5, #2
        LOAD2
        MLA2
        beq             0f
1:      /* remaining filter_length 1 */
        LOAD1
        MLA1
0:
        STORE
        pop             {r4, r5}
        bx              lr
endfunc

.purgem LOAD1
.purgem LOAD2
.purgem LOAD4
.purgem MLA1
.purgem MLA2
.purgem MLA4
.purgem MUL4
.purgem INIT4
.purgem STORE
.endm


/* float32 */
.macro  LOAD1
        veor.32         d0, d0
        vld1.32         {d0[0]}, [r0]! /* load filter */
        vld1.32         {d4[0]}, [r3]! /* load src */
.endm
.macro  LOAD2
        vld1.32         {d0}, [r0]! /* load filter */
        vld1.32         {d4}, [r3]! /* load src */
.endm
.macro  LOAD4
        vld1.32         {d0,d1}, [r0]! /* load filter */
        vld1.32         {d4,d5}, [r3]! /* load src */
.endm
.macro  MLA1
        vmla.f32        d16, d0, d4[0]
.endm
.macro  MLA2
        vmla.f32        d16, d0, d4
.endm
.macro  MLA4
        vmla.f32        d16, d0, d4
        vmla.f32        d17, d1, d5
.endm
.macro  MUL4
        vmul.f32        d16, d0, d4
        vmul.f32        d17, d1, d5
.endm
.macro  INIT4
        veor.f32        q8, q8
.endm
.macro  STORE
        vpadd.f32       d16, d16, d17
        vpadd.f32       d16, d16, d16
        vst1.32         d16[0], [r1]
.endm

resample_one flt, 2


/* s32 */
.macro  LOAD1
        veor.32         d0, d0
        vld1.32         {d0[0]}, [r0]! /* load filter */
        vld1.32         {d4[0]}, [r3]! /* load src */
.endm
.macro  LOAD2
        vld1.32         {d0}, [r0]! /* load filter */
        vld1.32         {d4}, [r3]! /* load src */
.endm
.macro  LOAD4
        vld1.32         {d0,d1}, [r0]! /* load filter */
        vld1.32         {d4,d5}, [r3]! /* load src */
.endm
.macro  MLA1
        vmlal.s32       q8, d0, d4[0]
.endm
.macro  MLA2
        vmlal.s32       q8, d0, d4
.endm
.macro  MLA4
        vmlal.s32       q8, d0, d4
        vmlal.s32       q9, d1, d5
.endm
.macro  MUL4
        vmull.s32       q8, d0, d4
        vmull.s32       q9, d1, d5
.endm
.macro  INIT4
        veor.s64        q8, q8
        veor.s64        q9, q9
.endm
.macro  STORE
        vadd.s64        q8, q8, q9
        vadd.s64        d16, d16, d17
        vqrshrn.s64     d16, q8, #30
        vst1.32         d16[0], [r1]
.endm

resample_one s32, 2


/* s16 */
.macro  LOAD1
        veor.16         d0, d0
        vld1.16         {d0[0]}, [r0]! /* load filter */
        vld1.16         {d4[0]}, [r3]! /* load src */
.endm
.macro  LOAD2
        veor.16         d0, d0
        vld1.32         {d0[0]}, [r0]! /* load filter */
        veor.16         d4, d4
        vld1.32         {d4[0]}, [r3]! /* load src */
.endm
.macro  LOAD4
        vld1.16         {d0}, [r0]! /* load filter */
        vld1.16         {d4}, [r3]! /* load src */
.endm
.macro  MLA1
        vmlal.s16       q8, d0, d4[0]
.endm
.macro  MLA2
        vmlal.s16       q8, d0, d4
.endm
.macro  MLA4
        vmlal.s16       q8, d0, d4
.endm
.macro  MUL4
        vmull.s16       q8, d0, d4
.endm
.macro  INIT4
        veor.s32        q8, q8
.endm
.macro  STORE
        vpadd.s32       d16, d16, d17
        vpadd.s32       d16, d16, d16
        vqrshrn.s32     d16, q8, #15
        vst1.16         d16[0], [r1]
.endm

resample_one s16, 1


.macro resample_linear  fmt, es=2
function ff_resample_linear_\fmt\()_neon, export=1
        push            {r4, r5}
        add             r1, r1, r2, lsl #\es

        ldr             r2, [r0, #PHASE_SHIFT+4] /* phase_mask */
        ldr             ip, [sp, #8] /* index */
        ldr             r5, [r0, #FILTER_LENGTH]
        and             r2, ip, r2 /* (index & phase_mask) */
        ldr             r4, [r0, #PHASE_SHIFT]
        lsr             r4, ip, r4 /* compute sample_index */
        mul             r2, r2, r5

        ldr             ip, [r0, #FILTER_BANK]
        add             r3, r3, r4, lsl #\es /* &src[sample_index] */

        cmp             r5, #8
        ldr             r4, [r0, #SRC_INCR]
        add             r0, ip, r2, lsl #\es /* filter = &filter_bank[...] */
        add             r2, r0, r5, lsl #\es /* filter[... + c->filter_length] */

        blt             5f
8:
        subs            r5, r5, #8
        LOAD4
        MUL4
7:
        LOAD4
        beq             6f
        cmp             r5, #8
        MLA4
        blt             4f
        subs            r5, r5, #8
        LOAD4
        MLA4
        b               7b
6:
        MLA4
        STORE
        pop             {r4, r5}
        bx              lr
5:
        INIT4
4:      /* remaining filter_length 1 to 7 */
        cmp             r5, #4
        blt             2f
        subs            r5, r5, #4
        LOAD4
        MLA4
        beq             0f
2:      /* remaining filter_length 1 to 3 */
        cmp             r5, #2
        blt             1f
        subs            r5, r5, #2
        LOAD2
        MLA2
        beq             0f
1:      /* remaining filter_length 1 */
        LOAD1
        MLA1
0:
        STORE
        pop             {r4, r5}
        bx              lr
endfunc

.purgem LOAD1
.purgem LOAD2
.purgem LOAD4
.purgem MLA1
.purgem MLA2
.purgem MLA4
.purgem MUL4
.purgem INIT4
.purgem STORE
.endm


/* float32 linear */
.macro  LOAD1
        veor.32         d0, d0
        veor.32         d2, d2
        vld1.32         {d0[0]}, [r0]! /* load filter */
        vld1.32         {d2[0]}, [r2]! /* load filter */
        vld1.32         {d4[0]}, [r3]! /* load src */
.endm
.macro  LOAD2
        vld1.32         {d0}, [r0]! /* load filter */
        vld1.32         {d2}, [r2]! /* load filter */
        vld1.32         {d4}, [r3]! /* load src */
.endm
.macro  LOAD4
        vld1.32         {d0,d1}, [r0]! /* load filter */
        vld1.32         {d2,d3}, [r2]! /* load filter */
        vld1.32         {d4,d5}, [r3]! /* load src */
.endm
.macro  MLA1
        vmla.f32        d18, d0, d4[0]
        vmla.f32        d16, d2, d4[0]
.endm
.macro  MLA2
        vmla.f32        d18, d0, d4
        vmla.f32        d16, d2, d4
.endm
.macro  MLA4
        vmla.f32        q9, q0, q2
        vmla.f32        q8, q1, q2
.endm
.macro  MUL4
        vmul.f32        q9, q0, q2
        vmul.f32        q8, q1, q2
.endm
.macro  INIT4
        veor.f32        q9, q9
        veor.f32        q8, q8
.endm
.macro  STORE
        vldr            s0, [sp, #12] /* frac */
        vmov            s1, r4
        vcvt.f32.s32    d0, d0

        vsub.f32        q8, q8, q9 /* v2 - val */
        vpadd.f32       d18, d18, d19
        vpadd.f32       d16, d16, d17
        vpadd.f32       d2, d18, d18
        vpadd.f32       d1, d16, d16

        vmul.f32        s2, s2, s0 /* (v2 - val) * frac */
        vdiv.f32        s2, s2, s1 /* / c->src_incr */
        vadd.f32        s4, s4, s2

        vstr            s4, [r1]
.endm

resample_linear flt, 2