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
|
/* Spa
*
* Copyright © 2019 Wim Taymans
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "resample-native-impl.h"
#include <arm_neon.h>
static inline void inner_product_neon(float *d, const float * SPA_RESTRICT s,
const float * SPA_RESTRICT taps, uint32_t n_taps)
{
unsigned int remainder = n_taps % 16;
n_taps = n_taps - remainder;
#ifdef __aarch64__
asm volatile(
" cmp %[n_taps], #0\n"
" bne 1f\n"
" ld1 {v4.4s}, [%[taps]], #16\n"
" ld1 {v8.4s}, [%[s]], #16\n"
" subs %[remainder], %[remainder], #4\n"
" fmul v0.4s, v4.4s, v8.4s\n"
" bne 4f\n"
" b 5f\n"
"1:"
" ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%[taps]], #64\n"
" ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%[s]], #64\n"
" subs %[n_taps], %[n_taps], #16\n"
" fmul v0.4s, v4.4s, v8.4s\n"
" fmul v1.4s, v5.4s, v9.4s\n"
" fmul v2.4s, v6.4s, v10.4s\n"
" fmul v3.4s, v7.4s, v11.4s\n"
" beq 3f\n"
"2:"
" ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%[taps]], #64\n"
" ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%[s]], #64\n"
" subs %[n_taps], %[n_taps], #16\n"
" fmla v0.4s, v4.4s, v8.4s\n"
" fmla v1.4s, v5.4s, v9.4s\n"
" fmla v2.4s, v6.4s, v10.4s\n"
" fmla v3.4s, v7.4s, v11.4s\n"
" bne 2b\n"
"3:"
" fadd v4.4s, v0.4s, v1.4s\n"
" fadd v5.4s, v2.4s, v3.4s\n"
" cmp %[remainder], #0\n"
" fadd v0.4s, v4.4s, v5.4s\n"
" beq 5f\n"
"4:"
" ld1 {v6.4s}, [%[taps]], #16\n"
" ld1 {v10.4s}, [%[s]], #16\n"
" subs %[remainder], %[remainder], #4\n"
" fmla v0.4s, v6.4s, v10.4s\n"
" bne 4b\n"
"5:"
" faddp v0.4s, v0.4s, v0.4s\n"
" faddp v0.2s, v0.2s, v0.2s\n"
" str s0, [%[d]]\n"
: [d] "+r" (d), [s] "+r" (s), [taps] "+r" (taps),
[n_taps] "+r" (n_taps), [remainder] "+r" (remainder)
:
: "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8",
"v9", "v10", "v11");
#else
asm volatile (
" cmp %[n_taps], #0\n"
" bne 1f\n"
" vld1.32 {q4}, [%[taps] :128]!\n"
" vld1.32 {q8}, [%[s]]!\n"
" subs %[remainder], %[remainder], #4\n"
" vmul.f32 q0, q4, q8\n"
" bne 4f\n"
" b 5f\n"
"1:"
" vld1.32 {q4, q5}, [%[taps] :128]!\n"
" vld1.32 {q8, q9}, [%[s]]!\n"
" vld1.32 {q6, q7}, [%[taps] :128]!\n"
" vld1.32 {q10, q11}, [%[s]]!\n"
" subs %[n_taps], %[n_taps], #16\n"
" vmul.f32 q0, q4, q8\n"
" vmul.f32 q1, q5, q9\n"
" vmul.f32 q2, q6, q10\n"
" vmul.f32 q3, q7, q11\n"
" beq 3f\n"
"2:"
" vld1.32 {q4, q5}, [%[taps] :128]!\n"
" vld1.32 {q8, q9}, [%[s]]!\n"
" vld1.32 {q6, q7}, [%[taps] :128]!\n"
" vld1.32 {q10, q11}, [%[s]]!\n"
" subs %[n_taps], %[n_taps], #16\n"
" vmla.f32 q0, q4, q8\n"
" vmla.f32 q1, q5, q9\n"
" vmla.f32 q2, q6, q10\n"
" vmla.f32 q3, q7, q11\n"
" bne 2b\n"
"3:"
" vadd.f32 q4, q0, q1\n"
" vadd.f32 q5, q2, q3\n"
" cmp %[remainder], #0\n"
" vadd.f32 q0, q4, q5\n"
" beq 5f\n"
"4:"
" vld1.32 {q6}, [%[taps] :128]!\n"
" vld1.32 {q10}, [%[s]]!\n"
" subs %[remainder], %[remainder], #4\n"
" vmla.f32 q0, q6, q10\n"
" bne 4b\n"
"5:"
" vadd.f32 d0, d0, d1\n"
" vpadd.f32 d0, d0, d0\n"
" vstr d0, [%[d]]\n"
: [d] "+r" (d), [s] "+r" (s), [taps] "+r" (taps),
[n_taps] "+l" (n_taps), [remainder] "+l" (remainder)
:
: "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8",
"q9", "q10", "q11");
#endif
}
static inline void inner_product_ip_neon(float *d, const float * SPA_RESTRICT s,
const float * SPA_RESTRICT t0, const float * SPA_RESTRICT t1, float x,
uint32_t n_taps)
{
#ifdef __aarch64__
asm volatile(
" dup v10.4s, %w[x]\n"
" ld1 {v4.4s, v5.4s}, [%[t0]], #32\n"
" ld1 {v8.4s, v9.4s}, [%[s]], #32\n"
" ld1 {v6.4s, v7.4s}, [%[t1]], #32\n"
" subs %[n_taps], %[n_taps], #8\n"
" fmul v0.4s, v4.4s, v8.4s\n"
" fmul v1.4s, v5.4s, v9.4s\n"
" fmul v2.4s, v6.4s, v8.4s\n"
" fmul v3.4s, v7.4s, v9.4s\n"
" beq 3f\n"
"2:"
" ld1 {v4.4s, v5.4s}, [%[t0]], #32\n"
" ld1 {v8.4s, v9.4s}, [%[s]], #32\n"
" ld1 {v6.4s, v7.4s}, [%[t1]], #32\n"
" subs %[n_taps], %[n_taps], #8\n"
" fmla v0.4s, v4.4s, v8.4s\n"
" fmla v1.4s, v5.4s, v9.4s\n"
" fmla v2.4s, v6.4s, v8.4s\n"
" fmla v3.4s, v7.4s, v9.4s\n"
" bne 2b\n"
"3:"
" fadd v0.4s, v0.4s, v1.4s\n" /* sum[0] */
" fadd v2.4s, v2.4s, v3.4s\n" /* sum[1] */
" fsub v2.4s, v2.4s, v0.4s\n" /* sum[1] -= sum[0] */
" fmla v0.4s, v2.4s, v10.4s\n" /* sum[0] += sum[1] * x */
" faddp v0.4s, v0.4s, v0.4s\n"
" faddp v0.2s, v0.2s, v0.2s\n"
" str s0, [%[d]]\n"
: [d] "+r" (d), [s] "+r" (s), [t0] "+r" (t0), [t1] "+r" (t1),
[n_taps] "+r" (n_taps), [x] "+r" (x)
:
: "cc", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8",
"v9", "v10");
#else
asm volatile(
" vdup.32 q10, %[x]\n"
" vld1.32 {q4, q5}, [%[t0] :128]!\n"
" vld1.32 {q8, q9}, [%[s]]!\n"
" vld1.32 {q6, q7}, [%[t1] :128]!\n"
" subs %[n_taps], %[n_taps], #8\n"
" vmul.f32 q0, q4, q8\n"
" vmul.f32 q1, q5, q9\n"
" vmul.f32 q2, q6, q8\n"
" vmul.f32 q3, q7, q9\n"
" beq 3f\n"
"2:"
" vld1.32 {q4, q5}, [%[t0] :128]!\n"
" vld1.32 {q8, q9}, [%[s]]!\n"
" vld1.32 {q6, q7}, [%[t1] :128]!\n"
" subs %[n_taps], %[n_taps], #8\n"
" vmla.f32 q0, q4, q8\n"
" vmla.f32 q1, q5, q9\n"
" vmla.f32 q2, q6, q8\n"
" vmla.f32 q3, q7, q9\n"
" bne 2b\n"
"3:"
" vadd.f32 q0, q0, q1\n" /* sum[0] */
" vadd.f32 q2, q2, q3\n" /* sum[1] */
" vsub.f32 q2, q2, q0\n" /* sum[1] -= sum[0] */
" vmla.f32 q0, q2, q10\n" /* sum[0] += sum[1] * x */
" vadd.f32 d0, d0, d1\n"
" vpadd.f32 d0, d0, d0\n"
" vstr d0, [%[d]]\n"
: [d] "+r" (d), [s] "+r" (s), [t0] "+r" (t0), [t1] "+r" (t1),
[n_taps] "+l" (n_taps), [x] "+l" (x)
:
: "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8",
"q9", "q10");
#endif
}
MAKE_RESAMPLER_FULL(neon);
MAKE_RESAMPLER_INTER(neon);
|