]> code.delx.au - pulseaudio/blob - src/pulsecore/svolume_arm.c
svolume_arm: Fix a const warning.
[pulseaudio] / src / pulsecore / svolume_arm.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2009 Wim Taymans <wim.taymans@collabora.co.uk>
6
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2.1 of the License,
10 or (at your option) any later version.
11
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA.
21 ***/
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <pulsecore/random.h>
28 #include <pulsecore/macro.h>
29 #include <pulsecore/endianmacros.h>
30
31 #include "cpu-arm.h"
32
33 #include "sample-util.h"
34
35 #if defined (__arm__) && defined (HAVE_ARMV6)
36
37 #define MOD_INC() \
38 " subs r0, r6, %2 \n\t" \
39 " itt cs \n\t" \
40 " addcs r0, %1 \n\t" \
41 " movcs r6, r0 \n\t"
42
43 static void pa_volume_s16ne_arm(int16_t *samples, const int32_t *volumes, unsigned channels, unsigned length) {
44 /* Channels must be at least 4, and always a multiple of the original number.
45 * This is also the max amount we overread the volume array, which should
46 * have enough padding. */
47 const int32_t *ve = volumes + (channels == 3 ? 6 : PA_MAX (4U, channels));
48
49 __asm__ __volatile__ (
50 " mov r6, %1 \n\t" /* r6 = volumes */
51 " mov %3, %3, LSR #1 \n\t" /* length /= sizeof (int16_t) */
52 " tst %3, #1 \n\t" /* check for odd samples */
53 " beq 2f \n\t"
54
55 "1: \n\t" /* odd samples volumes */
56 " ldr r0, [r6], #4 \n\t" /* r0 = volume */
57 " ldrh r2, [%0] \n\t" /* r2 = sample */
58
59 " smulwb r0, r0, r2 \n\t" /* r0 = (r0 * r2) >> 16 */
60 " ssat r0, #16, r0 \n\t" /* r0 = PA_CLAMP(r0, 0x7FFF) */
61
62 " strh r0, [%0], #2 \n\t" /* sample = r0 */
63
64 MOD_INC()
65
66 "2: \n\t"
67 " mov %3, %3, LSR #1 \n\t"
68 " tst %3, #1 \n\t" /* check for odd samples */
69 " beq 4f \n\t"
70
71 "3: \n\t"
72 " ldrd r2, [r6], #8 \n\t" /* 2 samples at a time */
73 " ldr r0, [%0] \n\t"
74
75 #ifdef WORDS_BIGENDIAN
76 " smulwt r2, r2, r0 \n\t"
77 " smulwb r3, r3, r0 \n\t"
78 #else
79 " smulwb r2, r2, r0 \n\t"
80 " smulwt r3, r3, r0 \n\t"
81 #endif
82
83 " ssat r2, #16, r2 \n\t"
84 " ssat r3, #16, r3 \n\t"
85
86 #ifdef WORDS_BIGENDIAN
87 " pkhbt r0, r3, r2, LSL #16 \n\t"
88 #else
89 " pkhbt r0, r2, r3, LSL #16 \n\t"
90 #endif
91 " str r0, [%0], #4 \n\t"
92
93 MOD_INC()
94
95 "4: \n\t"
96 " movs %3, %3, LSR #1 \n\t"
97 " beq 6f \n\t"
98
99 "5: \n\t"
100 " ldrd r2, [r6], #8 \n\t" /* 4 samples at a time */
101 " ldrd r4, [r6], #8 \n\t"
102 " ldrd r0, [%0] \n\t"
103
104 #ifdef WORDS_BIGENDIAN
105 " smulwt r2, r2, r0 \n\t"
106 " smulwb r3, r3, r0 \n\t"
107 " smulwt r4, r4, r1 \n\t"
108 " smulwb r5, r5, r1 \n\t"
109 #else
110 " smulwb r2, r2, r0 \n\t"
111 " smulwt r3, r3, r0 \n\t"
112 " smulwb r4, r4, r1 \n\t"
113 " smulwt r5, r5, r1 \n\t"
114 #endif
115
116 " ssat r2, #16, r2 \n\t"
117 " ssat r3, #16, r3 \n\t"
118 " ssat r4, #16, r4 \n\t"
119 " ssat r5, #16, r5 \n\t"
120
121 #ifdef WORDS_BIGENDIAN
122 " pkhbt r0, r3, r2, LSL #16 \n\t"
123 " pkhbt r1, r5, r4, LSL #16 \n\t"
124 #else
125 " pkhbt r0, r2, r3, LSL #16 \n\t"
126 " pkhbt r1, r4, r5, LSL #16 \n\t"
127 #endif
128 " strd r0, [%0], #8 \n\t"
129
130 MOD_INC()
131
132 " subs %3, %3, #1 \n\t"
133 " bne 5b \n\t"
134 "6: \n\t"
135
136 : "+r" (samples), "+r" (volumes), "+r" (ve), "+r" (length)
137 :
138 : "r6", "r5", "r4", "r3", "r2", "r1", "r0", "cc"
139 );
140 }
141
142 #endif /* defined (__arm__) && defined (HAVE_ARMV6) */
143
144 void pa_volume_func_init_arm(pa_cpu_arm_flag_t flags) {
145 #if defined (__arm__) && defined (HAVE_ARMV6)
146 pa_log_info("Initialising ARM optimized volume functions.");
147
148 pa_set_volume_func(PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_arm);
149 #endif /* defined (__arm__) && defined (HAVE_ARMV6) */
150 }