Debian Codegraph @

modules/lsp-dsp-lib/include/private/dsp/arch/arm/neon-d32/dynamics/gate.h

raw
1 /*
2 * Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2023 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-dsp-lib
6 * Created on: 20 окт. 2023 г.
7 *
8 * lsp-dsp-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-dsp-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-dsp-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef PRIVATE_DSP_ARCH_ARM_NEON_D32_DYNAMICS_GATE_H_
23 #define PRIVATE_DSP_ARCH_ARM_NEON_D32_DYNAMICS_GATE_H_
24
25 #include <private/dsp/arch/arm/neon-d32/pmath/exp.h>
26 #include <private/dsp/arch/arm/neon-d32/pmath/log.h>
27
28 namespace lsp
29 {
30 namespace neon_d32
31 {
32 #define PROCESS_KNEE_SINGLE_X8 \
33 /* in: q0 = lx0, q1 = lx1 */ \
34 __ASM_EMIT("add %[off], %[gate], #0x10") \
35 __ASM_EMIT("vld4.f32 {d16[], d18[], d20[], d22[]}, [%[off]]") /* q8 = herm[0] q9=herm[1] q10=herm[2], q11=herm[3] */ \
36 __ASM_EMIT("vld4.f32 {d17[], d19[], d21[], d23[]}, [%[off]]") /* q8 = herm[0] q9=herm[1] q10=herm[2], q11=herm[3] */ \
37 __ASM_EMIT("vmul.f32 q2, q0, q8") /* q2 = herm[0]*lx0 */ \
38 __ASM_EMIT("vmul.f32 q3, q1, q8") \
39 __ASM_EMIT("vadd.f32 q2, q2, q9") /* q2 = herm[0]*lx0+herm[1] */ \
40 __ASM_EMIT("vadd.f32 q3, q3, q9") \
41 __ASM_EMIT("vmul.f32 q2, q2, q0") /* q2 = (herm[0]*lx0+herm[1])*lx0 */ \
42 __ASM_EMIT("vmul.f32 q3, q3, q1") \
43 __ASM_EMIT("vadd.f32 q2, q2, q10") /* q2 = (herm[0]*lx0+herm[1])*lx0+herm[2] */ \
44 __ASM_EMIT("vadd.f32 q3, q3, q10") \
45 __ASM_EMIT("vldm %[LOG2E], {q15}") \
46 __ASM_EMIT("vmul.f32 q2, q2, q0") /* q2 = ((herm[0]*lx0+herm[1])*lx0+herm[2])*lx0 */ \
47 __ASM_EMIT("vmul.f32 q3, q3, q1") \
48 __ASM_EMIT("vadd.f32 q0, q2, q11") /* q0 = TV = ((herm[0]*lx0+herm[1])*lx0+herm[2])*lx0+herm[3] */ \
49 __ASM_EMIT("vadd.f32 q1, q3, q11") \
50 EXP_CORE_X8 /* q0 = KV = expf(TV) */ \
51 __ASM_EMIT("vldm %[mem], {q6-q7}") /* q6 = x0 */ \
52 __ASM_EMIT("vld4.f32 {d4[], d6[], d8[], d10[]}, [%[gate]]") /* q2 = start, q3 = end, q4 = gain_start, q5 = gain_end */ \
53 __ASM_EMIT("vld4.f32 {d5[], d7[], d9[], d11[]}, [%[gate]]") /* q2 = start, q3 = end, q4 = gain_start, q5 = gain_end */ \
54 __ASM_EMIT("vcgt.f32 q8, q6, q2") /* q8 = [x0 > start] */ \
55 __ASM_EMIT("vcgt.f32 q9, q7, q2") \
56 __ASM_EMIT("vcge.f32 q6, q6, q3") /* q3 = [x0 >= end] */ \
57 __ASM_EMIT("vcge.f32 q7, q7, q3") \
58 __ASM_EMIT("vbif q0, q4, q8") /* q0 = [x0 <= start] ? gain_start : KV */ \
59 __ASM_EMIT("vbif q1, q4, q9") \
60 __ASM_EMIT("vbit q0, q5, q6") /* q0 = [x0 >= end] ? gain_end : [x0 <= start] ? gain_start : KV */ \
61 __ASM_EMIT("vbit q1, q5, q7") \
62 /* out: q0 = g0, q1 = g1 */
63
64 #define PROCESS_KNEE_SINGLE_X4 \
65 /* in: q0 = lx0 */ \
66 __ASM_EMIT("add %[off], %[gate], #0x10") \
67 __ASM_EMIT("vld4.f32 {d16[], d18[], d20[], d22[]}, [%[off]]") /* q8 = herm[0] q9=herm[1] q10=herm[2], q11=herm[3] */ \
68 __ASM_EMIT("vld4.f32 {d17[], d19[], d21[], d23[]}, [%[off]]") /* q8 = herm[0] q9=herm[1] q10=herm[2], q11=herm[3] */ \
69 __ASM_EMIT("vmul.f32 q2, q0, q8") /* q2 = herm[0]*lx0 */ \
70 __ASM_EMIT("vadd.f32 q2, q2, q9") /* q2 = herm[0]*lx0+herm[1] */ \
71 __ASM_EMIT("vmul.f32 q2, q2, q0") /* q2 = (herm[0]*lx0+herm[1])*lx0 */ \
72 __ASM_EMIT("vadd.f32 q2, q2, q10") /* q2 = (herm[0]*lx0+herm[1])*lx0+herm[2] */ \
73 __ASM_EMIT("vldm %[LOG2E], {q15}") \
74 __ASM_EMIT("vmul.f32 q2, q2, q0") /* q2 = ((herm[0]*lx0+herm[1])*lx0+herm[2])*lx0 */ \
75 __ASM_EMIT("vadd.f32 q0, q2, q11") /* q0 = TV = ((herm[0]*lx0+herm[1])*lx0+herm[2])*lx0+herm[3] */ \
76 EXP_CORE_X4 /* q0 = KV = expf(TV) */ \
77 __ASM_EMIT("vldm %[mem], {q6}") /* q6 = x0 */ \
78 __ASM_EMIT("vld4.f32 {d4[], d6[], d8[], d10[]}, [%[gate]]") /* q2 = start, q3 = end, q4 = gain_start, q5 = gain_end */ \
79 __ASM_EMIT("vld4.f32 {d5[], d7[], d9[], d11[]}, [%[gate]]") /* q2 = start, q3 = end, q4 = gain_start, q5 = gain_end */ \
80 __ASM_EMIT("vcgt.f32 q8, q6, q2") /* q8 = [x0 > start] */ \
81 __ASM_EMIT("vcge.f32 q6, q6, q3") /* q3 = [x0 >= end] */ \
82 __ASM_EMIT("vbif q0, q4, q8") /* q0 = [x0 <= start] ? gain_start : KV */ \
83 __ASM_EMIT("vbit q0, q5, q6") /* q0 = [x0 >= end] ? gain_end : [x0 <= start] ? gain_start : KV */ \
84 /* out: q0 = g0 */
85
86 #define PROCESS_GATE_FULL_X8 \
87 /* in: q0 = x0, q1 = x1 */ \
88 __ASM_EMIT("vld2.f32 {d26[], d28[]}, [%[gate]]") /* q13 = start, q14 = end */ \
89 __ASM_EMIT("vld2.f32 {d27[], d29[]}, [%[gate]]") /* q13 = start, q14 = end */ \
90 __ASM_EMIT("vabs.f32 q0, q0") /* q0 = fabsf(x0) */ \
91 __ASM_EMIT("vabs.f32 q1, q1") \
92 __ASM_EMIT("vcgt.f32 q2, q0, q13") /* q2 = [fabs(x0) > start] */ \
93 __ASM_EMIT("vcgt.f32 q3, q1, q13") \
94 __ASM_EMIT("vcgt.f32 q4, q14, q0") /* q4 = [fabs(x0) < end] */ \
95 __ASM_EMIT("vcgt.f32 q5, q14, q1") \
96 __ASM_EMIT("vand q6, q2, q4") /* q6 = [fabs(x0) > start] && [fabs(x0) < end] */ \
97 __ASM_EMIT("vand q7, q3, q5") \
98 __ASM_EMIT("vorr q6, q6, q7") \
99 __ASM_EMIT("vext.32 q7, q6, q6, #2") \
100 __ASM_EMIT("vorr q6, q6, q7") \
101 __ASM_EMIT("vext.32 q7, q6, q6, #1") \
102 __ASM_EMIT("vorr q6, q6, q7") \
103 __ASM_EMIT("vmov.32 %[off], d12[0]") \
104 __ASM_EMIT("cmp %[off], #0") \
105 __ASM_EMIT("bne 100f") \
106 __ASM_EMIT("add %[off], %[gate], #0x08") \
107 __ASM_EMIT("vld1.f32 {d0[], d1[]}, [%[off]]") /* q0 = gain_start */ \
108 __ASM_EMIT("add %[off], %[gate], #0x0c") \
109 __ASM_EMIT("vld1.f32 {d8[], d9[]}, [%[off]]") /* q4 = gain_end */ \
110 __ASM_EMIT("vmov q1, q0") \
111 __ASM_EMIT("vbit q0, q4, q2") /* q0 = [fabs(x0) > start] ? gain_end : gain_start */ \
112 __ASM_EMIT("vbit q1, q4, q3") \
113 __ASM_EMIT("b 200f") \
114 __ASM_EMIT("100:") \
115 __ASM_EMIT("vldm %[LOGC], {q14-q15}") \
116 __ASM_EMIT("vstm %[mem], {q0-q1}") /* mem[0x00] = fabfs(x0) */ \
117 LOGE_CORE_X8 /* q0 = lx0 = logf(fabsf(x0)) */ \
118 PROCESS_KNEE_SINGLE_X8 /* apply knee 0 */ \
119 __ASM_EMIT("200:") \
120 /* out: q0 = G0, q1= G1 */
121
122 #define PROCESS_GATE_FULL_X4 \
123 /* in: q0 = x0, q1 = x1 */ \
124 __ASM_EMIT("vldm %[LOGC], {q14-q15}") \
125 __ASM_EMIT("vabs.f32 q0, q0") /* q0 = fabsf(x0) */ \
126 __ASM_EMIT("vstm %[mem], {q0}") /* mem[0x00] = fabfs(x0) */ \
127 LOGE_CORE_X4 /* q0 = lx0 = logf(fabsf(x0)) */ \
128 PROCESS_KNEE_SINGLE_X4 /* apply knee 0 */ \
129 /* out: q0 = G0 */
130
131 void gate_x1_gain(float *dst, const float *src, const dsp::gate_knee_t *c, size_t count)
132 {
133 IF_ARCH_ARM(
134 float mem[8] __lsp_aligned16;
135 size_t off;
136 );
137
138 ARCH_ARM_ASM(
139 // x8 blocks
140 __ASM_EMIT("subs %[count], #8")
141 __ASM_EMIT("blo 2f")
142 __ASM_EMIT("1:")
143 __ASM_EMIT("vld1.32 {q0-q1}, [%[src]]!")
144 PROCESS_GATE_FULL_X8
145 __ASM_EMIT("subs %[count], #8")
146 __ASM_EMIT("vst1.32 {q0-q1}, [%[dst]]!")
147 __ASM_EMIT("bhs 1b")
148 __ASM_EMIT("2:")
149 // x4 block
150 __ASM_EMIT("adds %[count], #4")
151 __ASM_EMIT("blt 4f")
152 __ASM_EMIT("vld1.32 {q0}, [%[src]]!")
153 PROCESS_GATE_FULL_X4
154 __ASM_EMIT("sub %[count], #4")
155 __ASM_EMIT("vst1.32 {q0}, [%[dst]]!")
156 __ASM_EMIT("4:")
157 // Tail: 1x-3x block
158 __ASM_EMIT("adds %[count], #4")
159 __ASM_EMIT("bls 12f")
160 __ASM_EMIT("tst %[count], #1")
161 __ASM_EMIT("beq 6f")
162 __ASM_EMIT("vld1.32 {d0[0]}, [%[src]]!")
163 __ASM_EMIT("6:")
164 __ASM_EMIT("tst %[count], #2")
165 __ASM_EMIT("beq 8f")
166 __ASM_EMIT("vld1.32 {d1}, [%[src]]")
167 __ASM_EMIT("8:")
168 PROCESS_GATE_FULL_X4
169 __ASM_EMIT("tst %[count], #1")
170 __ASM_EMIT("beq 10f")
171 __ASM_EMIT("vst1.32 {d0[0]}, [%[dst]]!")
172 __ASM_EMIT("10:")
173 __ASM_EMIT("tst %[count], #2")
174 __ASM_EMIT("beq 12f")
175 __ASM_EMIT("vst1.32 {d1}, [%[dst]]")
176 __ASM_EMIT("12:")
177
178 : [dst] "+r" (dst), [src] "+r" (src),
179 [count] "+r" (count),
180 [off] "=&r" (off)
181 : [gate] "r" (c),
182 [L2C] "r" (&LOG2_CONST[0]),
183 [LOGC] "r" (&LOGE_C[0]),
184 [mem] "r" (&mem[0]),
185 [E2C] "r" (&EXP2_CONST[0]),
186 [LOG2E] "r" (&EXP_LOG2E[0])
187 : "cc", "memory",
188 "q0", "q1", "q2", "q3",
189 "q4", "q5", "q6", "q7",
190 "q8", "q9", "q10", "q11",
191 "q12", "q13", "q14", "q15"
192 );
193 }
194
195 void gate_x1_curve(float *dst, const float *src, const dsp::gate_knee_t *c, size_t count)
196 {
197 IF_ARCH_ARM(
198 float mem[8] __lsp_aligned16;
199 size_t off;
200 );
201
202 ARCH_ARM_ASM(
203 // x8 blocks
204 __ASM_EMIT("subs %[count], #8")
205 __ASM_EMIT("blo 2f")
206 __ASM_EMIT("1:")
207 __ASM_EMIT("vld1.32 {q0-q1}, [%[src]]")
208 PROCESS_GATE_FULL_X8
209 __ASM_EMIT("vld1.32 {q2-q3}, [%[src]]!")
210 __ASM_EMIT("subs %[count], #8")
211 __ASM_EMIT("vmul.f32 q0, q0, q2")
212 __ASM_EMIT("vmul.f32 q1, q1, q3")
213 __ASM_EMIT("vst1.32 {q0-q1}, [%[dst]]!")
214 __ASM_EMIT("bhs 1b")
215 __ASM_EMIT("2:")
216 // x4 block
217 __ASM_EMIT("adds %[count], #4")
218 __ASM_EMIT("blt 4f")
219 __ASM_EMIT("vld1.32 {q0}, [%[src]]")
220 PROCESS_GATE_FULL_X4
221 __ASM_EMIT("vld1.32 {q2}, [%[src]]!")
222 __ASM_EMIT("sub %[count], #4")
223 __ASM_EMIT("vmul.f32 q0, q0, q2")
224 __ASM_EMIT("vst1.32 {q0}, [%[dst]]!")
225 __ASM_EMIT("4:")
226 // Tail: 1x-3x block
227 __ASM_EMIT("adds %[count], #4")
228 __ASM_EMIT("bls 12f")
229 __ASM_EMIT("tst %[count], #1")
230 __ASM_EMIT("beq 6f")
231 __ASM_EMIT("vld1.32 {d0[0]}, [%[src]]!")
232 __ASM_EMIT("6:")
233 __ASM_EMIT("tst %[count], #2")
234 __ASM_EMIT("beq 8f")
235 __ASM_EMIT("vld1.32 {d1}, [%[src]]")
236 __ASM_EMIT("8:")
237 __ASM_EMIT("vmov q1, q0")
238 PROCESS_GATE_FULL_X4
239 __ASM_EMIT("vmul.f32 q0, q0, q1")
240 __ASM_EMIT("tst %[count], #1")
241 __ASM_EMIT("beq 10f")
242 __ASM_EMIT("vst1.32 {d0[0]}, [%[dst]]!")
243 __ASM_EMIT("10:")
244 __ASM_EMIT("tst %[count], #2")
245 __ASM_EMIT("beq 12f")
246 __ASM_EMIT("vst1.32 {d1}, [%[dst]]")
247 __ASM_EMIT("12:")
248
249 : [dst] "+r" (dst), [src] "+r" (src),
250 [count] "+r" (count),
251 [off] "=&r" (off)
252 : [gate] "r" (c),
253 [L2C] "r" (&LOG2_CONST[0]),
254 [LOGC] "r" (&LOGE_C[0]),
255 [mem] "r" (&mem[0]),
256 [E2C] "r" (&EXP2_CONST[0]),
257 [LOG2E] "r" (&EXP_LOG2E[0])
258 : "cc", "memory",
259 "q0", "q1", "q2", "q3",
260 "q4", "q5", "q6", "q7",
261 "q8", "q9", "q10", "q11",
262 "q12", "q13", "q14", "q15"
263 );
264 }
265
266 #undef PROCESS_GATE_FULL_X4
267 #undef PROCESS_GATE_FULL_X8
268 #undef PROCESS_KNEE_SINGLE_X4
269 #undef PROCESS_KNEE_SINGLE_X8
270
271 } /* namespace neon_d32 */
272 } /* namespace lsp */
273
274
275
276
277 #endif /* PRIVATE_DSP_ARCH_ARM_NEON_D32_DYNAMICS_GATE_H_ */