]> code.delx.au - pulseaudio/blob - src/pulsecore/mix_neon.c
ff05ccf282a04331cfc9ee0f16ae351d78291e33
[pulseaudio] / src / pulsecore / mix_neon.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2013 Peter Meerwald <pmeerw@pmeerw.net>
5
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
10
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15 ***/
16
17 #ifdef HAVE_CONFIG_H
18 #include <config.h>
19 #endif
20
21 #include <pulsecore/macro.h>
22 #include <pulsecore/endianmacros.h>
23
24 #include "cpu-arm.h"
25 #include "mix.h"
26
27 #include <arm_neon.h>
28
29 static pa_do_mix_func_t fallback;
30
31 /* special case: mix s16ne streams, 2 channels each */
32 static void pa_mix_ch2_s16ne_neon(pa_mix_info streams[], unsigned nstreams, uint8_t *data, unsigned length) {
33 const unsigned mask = sizeof(int16_t) * 8 - 1;
34 const uint8_t *end = data + (length & ~mask);
35
36 while (data < end) {
37 int32x4_t sum0, sum1;
38 unsigned i;
39
40 __asm__ __volatile__ (
41 "veor.s32 %q[sum0], %q[sum0] \n\t"
42 "veor.s32 %q[sum1], %q[sum1] \n\t"
43 : [sum0] "=w" (sum0), [sum1] "=w" (sum1)
44 :
45 : "cc" /* clobber list */
46 );
47
48 for (i = 0; i < nstreams; i++) {
49 pa_mix_info *m = streams + i;
50 int32_t cv0 = m->linear[0].i;
51 int32_t cv1 = m->linear[1].i;
52
53 __asm__ __volatile__ (
54 "vld2.s16 {d0,d2}, [%[ptr]]! \n\t"
55 "vmov.s32 d4[0], %[cv0] \n\t"
56 "vmov.s32 d4[1], %[cv1] \n\t"
57 "vshll.s16 q0, d0, #15 \n\t"
58 "vshll.s16 q1, d2, #15 \n\t"
59 "vqdmulh.s32 q0, q0, d4[0] \n\t"
60 "vqdmulh.s32 q1, q1, d4[1] \n\t"
61 "vqadd.s32 %q[sum0], %q[sum0], q0 \n\t"
62 "vqadd.s32 %q[sum1], %q[sum1], q1 \n\t"
63 : [ptr] "+r" (m->ptr), [sum0] "+w" (sum0), [sum1] "+w" (sum1)
64 : [cv0] "r" (cv0), [cv1] "r" (cv1)
65 : "memory", "cc", "q0", "q1", "d4" /* clobber list */
66 );
67 }
68
69 __asm__ __volatile__ (
70 "vqmovn.s32 d0, %q[sum0] \n\t"
71 "vqmovn.s32 d1, %q[sum1] \n\t"
72 "vst2.s16 {d0,d1}, [%[data]]! \n\t"
73 : [data] "+r" (data)
74 : [sum0] "w" (sum0), [sum1] "w" (sum1)
75 : "memory", "cc", "q0" /* clobber list */
76 );
77 }
78
79 fallback(streams, nstreams, 2, data, length & mask);
80 }
81
82 static void pa_mix_s16ne_neon(pa_mix_info streams[], unsigned nstreams, unsigned nchannels, void *data, unsigned length) {
83 if (nchannels == 2)
84 pa_mix_ch2_s16ne_neon(streams, nstreams, data, length);
85 else
86 fallback(streams, nstreams, nchannels, data, length);
87 }
88
89 void pa_mix_func_init_neon(pa_cpu_arm_flag_t flags) {
90 pa_log_info("Initialising ARM NEON optimized mixing functions.");
91
92 fallback = pa_get_mix_func(PA_SAMPLE_S16NE);
93 pa_set_mix_func(PA_SAMPLE_S16NE, (pa_do_mix_func_t) pa_mix_s16ne_neon);
94 }