File: msmatrix.h

package info (click to toggle)
lsp-plugins 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 91,856 kB
  • sloc: cpp: 427,831; xml: 57,779; makefile: 9,961; php: 1,005; sh: 18
file content (435 lines) | stat: -rw-r--r-- 23,288 bytes parent folder | download
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
/*
 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
 *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
 *
 * This file is part of lsp-dsp-lib
 * Created on: 31 мар. 2020 г.
 *
 * lsp-dsp-lib 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 3 of the License, or
 * any later version.
 *
 * lsp-dsp-lib 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 lsp-dsp-lib. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef PRIVATE_DSP_ARCH_AARCH64_ASIMD_MSMATRIX_H_
#define PRIVATE_DSP_ARCH_AARCH64_ASIMD_MSMATRIX_H_

#ifndef PRIVATE_DSP_ARCH_AARCH64_ASIMD_IMPL
    #error "This header should not be included directly"
#endif /* PRIVATE_DSP_ARCH_AARCH64_ASIMD_IMPL */

namespace lsp
{
    namespace asimd
    {
        IF_ARCH_AARCH64(
            static const float msmatrix_const[] __lsp_aligned16 =
            {
                LSP_DSP_VEC4(0.5f)
            };
        );

        void lr_to_ms(float *m, float *s, const float *l, const float *r, size_t count)
        {
            ARCH_AARCH64_ASM(
                __ASM_EMIT("ldp         q24, q25, [%[HALF]]")           // v24  = 0.5, v25 = 0.5
                // x16 blocks
                __ASM_EMIT("subs        %[count], %[count], #16")
                __ASM_EMIT("b.lo        2f")
                __ASM_EMIT("1:")
                __ASM_EMIT("ldp         q0, q1, [%[l], #0x00]")         // v0   = l
                __ASM_EMIT("ldp         q2, q3, [%[l], #0x20]")
                __ASM_EMIT("ldp         q4, q5, [%[r], #0x00]")         // v4   = r
                __ASM_EMIT("ldp         q6, q7, [%[r], #0x20]")
                __ASM_EMIT("fadd        v16.4s, v0.4s, v4.4s")          // v16  = l + r
                __ASM_EMIT("fadd        v17.4s, v1.4s, v5.4s")
                __ASM_EMIT("fadd        v18.4s, v2.4s, v6.4s")
                __ASM_EMIT("fadd        v19.4s, v3.4s, v7.4s")
                __ASM_EMIT("fsub        v20.4s, v0.4s, v4.4s")          // v20  = l - r
                __ASM_EMIT("fsub        v21.4s, v1.4s, v5.4s")
                __ASM_EMIT("fsub        v22.4s, v2.4s, v6.4s")
                __ASM_EMIT("fsub        v23.4s, v3.4s, v7.4s")
                __ASM_EMIT("fmul        v0.4s, v16.4s, v24.4s")         // v0   = (l + r)/2
                __ASM_EMIT("fmul        v1.4s, v17.4s, v25.4s")
                __ASM_EMIT("fmul        v2.4s, v18.4s, v24.4s")
                __ASM_EMIT("fmul        v3.4s, v19.4s, v25.4s")
                __ASM_EMIT("fmul        v4.4s, v20.4s, v24.4s")         // v4   = (l - r)/2
                __ASM_EMIT("fmul        v5.4s, v21.4s, v25.4s")
                __ASM_EMIT("fmul        v6.4s, v22.4s, v24.4s")
                __ASM_EMIT("fmul        v7.4s, v23.4s, v25.4s")
                __ASM_EMIT("stp         q0, q1, [%[m], #0x00]")
                __ASM_EMIT("stp         q2, q3, [%[m], #0x20]")
                __ASM_EMIT("stp         q4, q5, [%[s], #0x00]")
                __ASM_EMIT("stp         q6, q7, [%[s], #0x20]")
                __ASM_EMIT("subs        %[count], %[count], #16")
                __ASM_EMIT("add         %[l], %[l], #0x40")
                __ASM_EMIT("add         %[r], %[r], #0x40")
                __ASM_EMIT("add         %[m], %[m], #0x40")
                __ASM_EMIT("add         %[s], %[s], #0x40")
                __ASM_EMIT("b.hs        1b")
                __ASM_EMIT("2:")
                // x8 block
                __ASM_EMIT("adds        %[count], %[count], #8")
                __ASM_EMIT("b.lt        4f")
                __ASM_EMIT("ldp         q0, q1, [%[l], #0x00]")         // v0   = l
                __ASM_EMIT("ldp         q4, q5, [%[r], #0x00]")         // v4   = r
                __ASM_EMIT("fadd        v16.4s, v0.4s, v4.4s")          // v16  = l + r
                __ASM_EMIT("fadd        v17.4s, v1.4s, v5.4s")
                __ASM_EMIT("fsub        v20.4s, v0.4s, v4.4s")          // v20  = l - r
                __ASM_EMIT("fsub        v21.4s, v1.4s, v5.4s")
                __ASM_EMIT("fmul        v0.4s, v16.4s, v24.4s")         // v0   = (l + r)/2
                __ASM_EMIT("fmul        v1.4s, v17.4s, v25.4s")
                __ASM_EMIT("fmul        v4.4s, v20.4s, v24.4s")         // v4   = (l - r)/2
                __ASM_EMIT("fmul        v5.4s, v21.4s, v25.4s")
                __ASM_EMIT("stp         q0, q1, [%[m], #0x00]")
                __ASM_EMIT("stp         q4, q5, [%[s], #0x00]")
                __ASM_EMIT("sub         %[count], %[count], #8")
                __ASM_EMIT("add         %[l], %[l], #0x20")
                __ASM_EMIT("add         %[r], %[r], #0x20")
                __ASM_EMIT("add         %[m], %[m], #0x20")
                __ASM_EMIT("add         %[s], %[s], #0x20")
                __ASM_EMIT("4:")
                // x4 block
                __ASM_EMIT("adds        %[count], %[count], #4")
                __ASM_EMIT("b.lt        6f")
                __ASM_EMIT("ldr         q0, [%[l]]")                    // v0   = l
                __ASM_EMIT("ldr         q4, [%[r]]")                    // v4   = r
                __ASM_EMIT("fadd        v16.4s, v0.4s, v4.4s")          // v16  = l + r
                __ASM_EMIT("fsub        v20.4s, v0.4s, v4.4s")          // v20  = l - r
                __ASM_EMIT("fmul        v0.4s, v16.4s, v24.4s")         // v0   = (l + r)/2
                __ASM_EMIT("fmul        v4.4s, v20.4s, v24.4s")         // v4   = (l - r)/2
                __ASM_EMIT("str         q0, [%[m]]")
                __ASM_EMIT("str         q4, [%[s]]")
                __ASM_EMIT("sub         %[count], %[count], #4")
                __ASM_EMIT("add         %[l], %[l], #0x10")
                __ASM_EMIT("add         %[r], %[r], #0x10")
                __ASM_EMIT("add         %[m], %[m], #0x10")
                __ASM_EMIT("add         %[s], %[s], #0x10")
                __ASM_EMIT("6:")
                // x1 blocks
                __ASM_EMIT("adds        %[count], %[count], #1")
                __ASM_EMIT("b.lt        8f")
                __ASM_EMIT("7:")
                __ASM_EMIT("ld1r        {v0.4s}, [%[l]]")               // v0   = l
                __ASM_EMIT("ld1r        {v4.4s}, [%[r]]")               // v4   = r
                __ASM_EMIT("fadd        v16.4s, v0.4s, v4.4s")          // v16  = l + r
                __ASM_EMIT("fsub        v20.4s, v0.4s, v4.4s")          // v20  = l - r
                __ASM_EMIT("fmul        v0.4s, v16.4s, v24.4s")         // v0   = (l + r)/2
                __ASM_EMIT("fmul        v4.4s, v20.4s, v24.4s")         // v4   = (l - r)/2
                __ASM_EMIT("st1         {v0.s}[0], [%[m]]")
                __ASM_EMIT("st1         {v4.s}[0], [%[s]]")
                __ASM_EMIT("subs        %[count], %[count], #1")
                __ASM_EMIT("add         %[l], %[l], #0x04")
                __ASM_EMIT("add         %[r], %[r], #0x04")
                __ASM_EMIT("add         %[m], %[m], #0x04")
                __ASM_EMIT("add         %[s], %[s], #0x04")
                __ASM_EMIT("b.ge        7b")
                __ASM_EMIT("8:")

                : [l] "+r" (l), [r] "+r" (r), [m] "+r" (m), [s] "+r" (s),
                  [count] "+r" (count)
                : [HALF] "r" (&msmatrix_const[0])
                : "cc", "memory",
                  "v0", "v1", "v2", "v3",
                  "v4", "v5", "v6", "v7",
                  "v16", "v17", "v18", "v19",
                  "v20", "v21", "v22", "v23",
                  "v24", "v25"
            );
        }

        void ms_to_lr(float *l, float *r, const float *m, const float *s, size_t count)
        {
            ARCH_AARCH64_ASM(
                // x16 blocks
                __ASM_EMIT("subs        %[count], %[count], #16")
                __ASM_EMIT("b.lo        2f")
                __ASM_EMIT("1:")
                __ASM_EMIT("ldp         q0, q1, [%[m], #0x00]")         // v0   = m
                __ASM_EMIT("ldp         q2, q3, [%[m], #0x20]")
                __ASM_EMIT("ldp         q4, q5, [%[s], #0x00]")         // v4   = s
                __ASM_EMIT("ldp         q6, q7, [%[s], #0x20]")
                __ASM_EMIT("fadd        v16.4s, v0.4s, v4.4s")          // v16  = m + s
                __ASM_EMIT("fadd        v17.4s, v1.4s, v5.4s")
                __ASM_EMIT("fadd        v18.4s, v2.4s, v6.4s")
                __ASM_EMIT("fadd        v19.4s, v3.4s, v7.4s")
                __ASM_EMIT("fsub        v20.4s, v0.4s, v4.4s")          // v20  = m - s
                __ASM_EMIT("fsub        v21.4s, v1.4s, v5.4s")
                __ASM_EMIT("fsub        v22.4s, v2.4s, v6.4s")
                __ASM_EMIT("fsub        v23.4s, v3.4s, v7.4s")
                __ASM_EMIT("stp         q16, q17, [%[l], #0x00]")
                __ASM_EMIT("stp         q18, q19, [%[l], #0x20]")
                __ASM_EMIT("stp         q20, q21, [%[r], #0x00]")
                __ASM_EMIT("stp         q22, q23, [%[r], #0x20]")
                __ASM_EMIT("subs        %[count], %[count], #16")
                __ASM_EMIT("add         %[l], %[l], #0x40")
                __ASM_EMIT("add         %[r], %[r], #0x40")
                __ASM_EMIT("add         %[m], %[m], #0x40")
                __ASM_EMIT("add         %[s], %[s], #0x40")
                __ASM_EMIT("b.hs        1b")
                __ASM_EMIT("2:")
                // x8 block
                __ASM_EMIT("adds        %[count], %[count], #8")
                __ASM_EMIT("b.lt        4f")
                __ASM_EMIT("ldp         q0, q1, [%[m], #0x00]")         // v0   = m
                __ASM_EMIT("ldp         q4, q5, [%[s], #0x00]")         // v4   = s
                __ASM_EMIT("fadd        v16.4s, v0.4s, v4.4s")          // v16  = m + s
                __ASM_EMIT("fadd        v17.4s, v1.4s, v5.4s")
                __ASM_EMIT("fsub        v20.4s, v0.4s, v4.4s")          // v20  = m - s
                __ASM_EMIT("fsub        v21.4s, v1.4s, v5.4s")
                __ASM_EMIT("stp         q16, q17, [%[l], #0x00]")
                __ASM_EMIT("stp         q20, q21, [%[r], #0x00]")
                __ASM_EMIT("sub         %[count], %[count], #8")
                __ASM_EMIT("add         %[l], %[l], #0x20")
                __ASM_EMIT("add         %[r], %[r], #0x20")
                __ASM_EMIT("add         %[m], %[m], #0x20")
                __ASM_EMIT("add         %[s], %[s], #0x20")
                __ASM_EMIT("4:")
                // x4 block
                __ASM_EMIT("adds        %[count], %[count], #4")
                __ASM_EMIT("b.lt        6f")
                __ASM_EMIT("ldr         q0, [%[m]]")                    // v0   = m
                __ASM_EMIT("ldr         q4, [%[s]]")                    // v4   = s
                __ASM_EMIT("fadd        v16.4s, v0.4s, v4.4s")          // v16  = m + s
                __ASM_EMIT("fsub        v20.4s, v0.4s, v4.4s")          // v20  = m - s
                __ASM_EMIT("str         q16, [%[l]]")
                __ASM_EMIT("str         q20, [%[r]]")
                __ASM_EMIT("sub         %[count], %[count], #4")
                __ASM_EMIT("add         %[l], %[l], #0x10")
                __ASM_EMIT("add         %[r], %[r], #0x10")
                __ASM_EMIT("add         %[m], %[m], #0x10")
                __ASM_EMIT("add         %[s], %[s], #0x10")
                __ASM_EMIT("6:")
                // x1 blocks
                __ASM_EMIT("adds        %[count], %[count], #1")
                __ASM_EMIT("b.lt        8f")
                __ASM_EMIT("7:")
                __ASM_EMIT("ld1r        {v0.4s}, [%[m]]")               // v0   = m
                __ASM_EMIT("ld1r        {v4.4s}, [%[s]]")               // v4   = s
                __ASM_EMIT("fadd        v16.4s, v0.4s, v4.4s")          // v16  = m + s
                __ASM_EMIT("fsub        v20.4s, v0.4s, v4.4s")          // v20  = m - s
                __ASM_EMIT("st1         {v16.s}[0], [%[l]]")
                __ASM_EMIT("st1         {v20.s}[0], [%[r]]")
                __ASM_EMIT("subs        %[count], %[count], #1")
                __ASM_EMIT("add         %[l], %[l], #0x04")
                __ASM_EMIT("add         %[r], %[r], #0x04")
                __ASM_EMIT("add         %[m], %[m], #0x04")
                __ASM_EMIT("add         %[s], %[s], #0x04")
                __ASM_EMIT("b.ge        7b")
                __ASM_EMIT("8:")

                : [l] "+r" (l), [r] "+r" (r), [m] "+r" (m), [s] "+r" (s),
                  [count] "+r" (count)
                : [HALF] "r" (&msmatrix_const[0])
                : "cc", "memory",
                  "v0", "v1", "v2", "v3",
                  "v4", "v5", "v6", "v7",
                  "v16", "v17", "v18", "v19",
                  "v20", "v21", "v22", "v23"
            );
        }

        #define LR_TO_PART(OP) \
                __ASM_EMIT("ldp         q24, q25, [%[HALF]]")           /* v24  = 0.5, v25 = 0.5 */ \
                /* x16 blocks */ \
                __ASM_EMIT("subs        %[count], %[count], #16") \
                __ASM_EMIT("b.lo        2f") \
                __ASM_EMIT("1:") \
                __ASM_EMIT("ldp         q0, q1, [%[l], #0x00]")         /* v0   = l */ \
                __ASM_EMIT("ldp         q2, q3, [%[l], #0x20]") \
                __ASM_EMIT("ldp         q4, q5, [%[r], #0x00]")         /* v4   = r */ \
                __ASM_EMIT("ldp         q6, q7, [%[r], #0x20]") \
                __ASM_EMIT(OP "         v16.4s, v0.4s, v4.4s")          /* v16  = l op r */ \
                __ASM_EMIT(OP "         v17.4s, v1.4s, v5.4s") \
                __ASM_EMIT(OP "         v18.4s, v2.4s, v6.4s") \
                __ASM_EMIT(OP "         v19.4s, v3.4s, v7.4s") \
                __ASM_EMIT("fmul        v0.4s, v16.4s, v24.4s")         /* v0   = (l op r)/2 */ \
                __ASM_EMIT("fmul        v1.4s, v17.4s, v25.4s") \
                __ASM_EMIT("fmul        v2.4s, v18.4s, v24.4s") \
                __ASM_EMIT("fmul        v3.4s, v19.4s, v25.4s") \
                __ASM_EMIT("stp         q0, q1, [%[dst], #0x00]") \
                __ASM_EMIT("stp         q2, q3, [%[dst], #0x20]") \
                __ASM_EMIT("subs        %[count], %[count], #16") \
                __ASM_EMIT("add         %[l], %[l], #0x40") \
                __ASM_EMIT("add         %[r], %[r], #0x40") \
                __ASM_EMIT("add         %[dst], %[dst], #0x40") \
                __ASM_EMIT("b.hs        1b") \
                __ASM_EMIT("2:") \
                /* x8 block */ \
                __ASM_EMIT("adds        %[count], %[count], #8") \
                __ASM_EMIT("b.lt        4f") \
                __ASM_EMIT("ldp         q0, q1, [%[l], #0x00]")         /* v0   = l */ \
                __ASM_EMIT("ldp         q4, q5, [%[r], #0x00]")         /* v4   = r */ \
                __ASM_EMIT(OP "         v16.4s, v0.4s, v4.4s")          /* v16  = l op r */ \
                __ASM_EMIT(OP "         v17.4s, v1.4s, v5.4s") \
                __ASM_EMIT("fmul        v0.4s, v16.4s, v24.4s")         /* v0   = (l op r)/2 */ \
                __ASM_EMIT("fmul        v1.4s, v17.4s, v25.4s") \
                __ASM_EMIT("stp         q0, q1, [%[dst], #0x00]") \
                __ASM_EMIT("sub         %[count], %[count], #8") \
                __ASM_EMIT("add         %[l], %[l], #0x20") \
                __ASM_EMIT("add         %[r], %[r], #0x20") \
                __ASM_EMIT("add         %[dst], %[dst], #0x20") \
                __ASM_EMIT("4:") \
                /* x4 block */ \
                __ASM_EMIT("adds        %[count], %[count], #4") \
                __ASM_EMIT("b.lt        6f") \
                __ASM_EMIT("ldr         q0, [%[l]]")                    /* v0   = l */ \
                __ASM_EMIT("ldr         q4, [%[r]]")                    /* v4   = r */ \
                __ASM_EMIT(OP "         v16.4s, v0.4s, v4.4s")          /* v16  = l op r */ \
                __ASM_EMIT("fmul        v0.4s, v16.4s, v24.4s")         /* v0   = (l op r)/2 */ \
                __ASM_EMIT("str         q0, [%[dst]]") \
                __ASM_EMIT("sub         %[count], %[count], #4") \
                __ASM_EMIT("add         %[l], %[l], #0x10") \
                __ASM_EMIT("add         %[r], %[r], #0x10") \
                __ASM_EMIT("add         %[dst], %[dst], #0x10") \
                __ASM_EMIT("6:") \
                /* x1 blocks */ \
                __ASM_EMIT("adds        %[count], %[count], #1") \
                __ASM_EMIT("b.lt        8f") \
                __ASM_EMIT("7:") \
                __ASM_EMIT("ld1r        {v0.4s}, [%[l]]")               /* v0   = l */ \
                __ASM_EMIT("ld1r        {v4.4s}, [%[r]]")               /* v4   = r */ \
                __ASM_EMIT(OP "         v16.4s, v0.4s, v4.4s")          /* v16  = l op r */ \
                __ASM_EMIT("fmul        v0.4s, v16.4s, v24.4s")         /* v0   = (l op r)/2 */ \
                __ASM_EMIT("st1         {v0.s}[0], [%[dst]]") \
                __ASM_EMIT("subs        %[count], %[count], #1") \
                __ASM_EMIT("add         %[l], %[l], #0x04") \
                __ASM_EMIT("add         %[r], %[r], #0x04") \
                __ASM_EMIT("add         %[dst], %[dst], #0x04") \
                __ASM_EMIT("b.ge        7b") \
                __ASM_EMIT("8:")

        void lr_to_mid(float *m, const float *l, const float *r, size_t count)
        {
            ARCH_AARCH64_ASM(
                LR_TO_PART("fadd")
                : [l] "+r" (l), [r] "+r" (r), [dst] "+r" (m),
                  [count] "+r" (count)
                : [HALF] "r" (&msmatrix_const[0])
                : "cc", "memory",
                  "v0", "v1", "v2", "v3",
                  "v4", "v5", "v6", "v7",
                  "v16", "v17", "v18", "v19",
                  "v24", "v25"
            );
        }

        void lr_to_side(float *s, const float *l, const float *r, size_t count)
        {
            ARCH_AARCH64_ASM(
                LR_TO_PART("fsub")
                : [l] "+r" (l), [r] "+r" (r), [dst] "+r" (s),
                  [count] "+r" (count)
                : [HALF] "r" (&msmatrix_const[0])
                : "cc", "memory",
                  "v0", "v1", "v2", "v3",
                  "v4", "v5", "v6", "v7",
                  "v16", "v17", "v18", "v19",
                  "v24", "v25"
            );
        }

        #undef LR_TO_PART

        #define MS_TO_PART(OP) \
            /* x16 blocks */ \
            __ASM_EMIT("subs        %[count], %[count], #16") \
            __ASM_EMIT("b.lo        2f") \
            __ASM_EMIT("1:") \
            __ASM_EMIT("ldp         q0, q1, [%[m], #0x00]")         /* v0   = m */ \
            __ASM_EMIT("ldp         q2, q3, [%[m], #0x20]") \
            __ASM_EMIT("ldp         q4, q5, [%[s], #0x00]")         /* v4   = s */ \
            __ASM_EMIT("ldp         q6, q7, [%[s], #0x20]") \
            __ASM_EMIT(OP "         v16.4s, v0.4s, v4.4s")          /* v16  = m op s */ \
            __ASM_EMIT(OP "         v17.4s, v1.4s, v5.4s") \
            __ASM_EMIT(OP "         v18.4s, v2.4s, v6.4s") \
            __ASM_EMIT(OP "         v19.4s, v3.4s, v7.4s") \
            __ASM_EMIT("stp         q0, q1, [%[dst], #0x00]") \
            __ASM_EMIT("stp         q2, q3, [%[dst], #0x20]") \
            __ASM_EMIT("subs        %[count], %[count], #16") \
            __ASM_EMIT("add         %[m], %[m], #0x40") \
            __ASM_EMIT("add         %[s], %[s], #0x40") \
            __ASM_EMIT("add         %[dst], %[dst], #0x40") \
            __ASM_EMIT("b.hs        1b") \
            __ASM_EMIT("2:") \
            /* x8 block */ \
            __ASM_EMIT("adds        %[count], %[count], #8") \
            __ASM_EMIT("b.lt        4f") \
            __ASM_EMIT("ldp         q0, q1, [%[m], #0x00]")         /* v0   = m */ \
            __ASM_EMIT("ldp         q4, q5, [%[s], #0x00]")         /* v4   = s */ \
            __ASM_EMIT(OP "         v16.4s, v0.4s, v4.4s")          /* v16  = m op s */ \
            __ASM_EMIT(OP "         v17.4s, v1.4s, v5.4s") \
            __ASM_EMIT("stp         q0, q1, [%[dst], #0x00]") \
            __ASM_EMIT("sub         %[count], %[count], #8") \
            __ASM_EMIT("add         %[m], %[m], #0x20") \
            __ASM_EMIT("add         %[s], %[s], #0x20") \
            __ASM_EMIT("add         %[dst], %[dst], #0x20") \
            __ASM_EMIT("4:") \
            /* x4 block */ \
            __ASM_EMIT("adds        %[count], %[count], #4") \
            __ASM_EMIT("b.lt        6f") \
            __ASM_EMIT("ldr         q0, [%[m]]")                    /* v0   = m */ \
            __ASM_EMIT("ldr         q4, [%[s]]")                    /* v4   = s */ \
            __ASM_EMIT(OP "         v16.4s, v0.4s, v4.4s")          /* v16  = m op s */ \
            __ASM_EMIT("str         q0, [%[dst]]") \
            __ASM_EMIT("sub         %[count], %[count], #4") \
            __ASM_EMIT("add         %[m], %[m], #0x10") \
            __ASM_EMIT("add         %[s], %[s], #0x10") \
            __ASM_EMIT("add         %[dst], %[dst], #0x10") \
            __ASM_EMIT("6:") \
            /* x1 blocks */ \
            __ASM_EMIT("adds        %[count], %[count], #1") \
            __ASM_EMIT("b.lt        8f") \
            __ASM_EMIT("7:") \
            __ASM_EMIT("ld1r        {v0.4s}, [%[m]]")               /* v0   = m */ \
            __ASM_EMIT("ld1r        {v4.4s}, [%[s]]")               /* v4   = s */ \
            __ASM_EMIT(OP "         v16.4s, v0.4s, v4.4s")          /* v16  = m op s */ \
            __ASM_EMIT("st1         {v0.s}[0], [%[dst]]") \
            __ASM_EMIT("subs        %[count], %[count], #1") \
            __ASM_EMIT("add         %[m], %[m], #0x04") \
            __ASM_EMIT("add         %[s], %[s], #0x04") \
            __ASM_EMIT("add         %[dst], %[dst], #0x04") \
            __ASM_EMIT("b.ge        7b") \
            __ASM_EMIT("8:")

        void ms_to_left(float *l, const float *m, const float *s, size_t count)
        {
            ARCH_AARCH64_ASM(
                MS_TO_PART("fadd")
                : [m] "+r" (m), [s] "+r" (s), [dst] "+r" (l),
                  [count] "+r" (count)
                :
                : "cc", "memory",
                  "v0", "v1", "v2", "v3",
                  "v4", "v5", "v6", "v7",
                  "v16", "v17", "v18", "v19"
            );
        }

        void ms_to_right(float *r, const float *m, const float *s, size_t count)
        {
            ARCH_AARCH64_ASM(
                MS_TO_PART("fsub")
                : [m] "+r" (m), [s] "+r" (s), [dst] "+r" (r),
                  [count] "+r" (count)
                :
                : "cc", "memory",
                  "v0", "v1", "v2", "v3",
                  "v4", "v5", "v6", "v7",
                  "v16", "v17", "v18", "v19"
            );
        }

        #undef MS_TO_PART
    }
}

#endif /* PRIVATE_DSP_ARCH_AARCH64_ASIMD_MSMATRIX_H_ */