1 /* Copyright (C) 2007-2008 Jean-Marc Valin
2 * Copyright (C) 2008 Thorvald Natvig
3 * Copyright (C) 2011 Texas Instruments
8 @brief Resampler functions (NEON version)
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions
15 - Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
18 - Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
22 - Neither the name of the Xiph.org Foundation nor the names of its
23 contributors may be used to endorse or promote products derived from
24 this software without specific prior written permission.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
30 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 static inline int32_t saturate_32bit_to_16bit(int32_t a) {
45 asm ("ssat %[ret], #16, %[a]"
52 static inline int32_t saturate_32bit_to_16bit(int32_t a) {
54 asm ("vmov.s32 d0[0], %[a]\n"
56 "vmov.s16 %[ret], d0[0]\n"
64 #define WORD2INT(x) (saturate_32bit_to_16bit(x))
66 #define OVERRIDE_INNER_PRODUCT_SINGLE
67 /* Only works when len % 4 == 0 */
68 static inline int32_t inner_product_single(const int16_t *a, const int16_t *b, unsigned int len)
71 uint32_t remainder = len % 16;
72 len = len - remainder;
74 asm volatile (" cmp %[len], #0\n"
76 " vld1.16 {d16}, [%[b]]!\n"
77 " vld1.16 {d20}, [%[a]]!\n"
78 " subs %[remainder], %[remainder], #4\n"
79 " vmull.s16 q0, d16, d20\n"
83 " vld1.16 {d16, d17, d18, d19}, [%[b]]!\n"
84 " vld1.16 {d20, d21, d22, d23}, [%[a]]!\n"
85 " subs %[len], %[len], #16\n"
86 " vmull.s16 q0, d16, d20\n"
87 " vmlal.s16 q0, d17, d21\n"
88 " vmlal.s16 q0, d18, d22\n"
89 " vmlal.s16 q0, d19, d23\n"
92 " vld1.16 {d16, d17, d18, d19}, [%[b]]!\n"
93 " vld1.16 {d20, d21, d22, d23}, [%[a]]!\n"
94 " subs %[len], %[len], #16\n"
95 " vmlal.s16 q0, d16, d20\n"
96 " vmlal.s16 q0, d17, d21\n"
97 " vmlal.s16 q0, d18, d22\n"
98 " vmlal.s16 q0, d19, d23\n"
101 " cmp %[remainder], #0\n"
104 " vld1.16 {d16}, [%[b]]!\n"
105 " vld1.16 {d20}, [%[a]]!\n"
106 " subs %[remainder], %[remainder], #4\n"
107 " vmlal.s16 q0, d16, d20\n"
110 " vaddl.s32 q0, d0, d1\n"
111 " vadd.s64 d0, d0, d1\n"
112 " vqmovn.s64 d0, q0\n"
113 " vqrshrn.s32 d0, q0, #15\n"
114 " vmov.s16 %[ret], d0[0]\n"
115 : [ret] "=&r" (ret), [a] "+r" (a), [b] "+r" (b),
116 [len] "+r" (len), [remainder] "+r" (remainder)
119 "d16", "d17", "d18", "d19",
120 "d20", "d21", "d22", "d23");
124 #elif defined(FLOATING_POINT)
126 static inline int32_t saturate_float_to_16bit(float a) {
128 asm ("vmov.f32 d0[0], %[a]\n"
129 "vcvt.s32.f32 d0, d0, #15\n"
130 "vqrshrn.s32 d0, q0, #15\n"
131 "vmov.s16 %[ret], d0[0]\n"
138 #define WORD2INT(x) (saturate_float_to_16bit(x))
140 #define OVERRIDE_INNER_PRODUCT_SINGLE
141 /* Only works when len % 4 == 0 */
142 static inline float inner_product_single(const float *a, const float *b, unsigned int len)
145 uint32_t remainder = len % 16;
146 len = len - remainder;
148 asm volatile (" cmp %[len], #0\n"
150 " vld1.32 {q4}, [%[b]]!\n"
151 " vld1.32 {q8}, [%[a]]!\n"
152 " subs %[remainder], %[remainder], #4\n"
153 " vmul.f32 q0, q4, q8\n"
157 " vld1.32 {q4, q5}, [%[b]]!\n"
158 " vld1.32 {q8, q9}, [%[a]]!\n"
159 " vld1.32 {q6, q7}, [%[b]]!\n"
160 " vld1.32 {q10, q11}, [%[a]]!\n"
161 " subs %[len], %[len], #16\n"
162 " vmul.f32 q0, q4, q8\n"
163 " vmul.f32 q1, q5, q9\n"
164 " vmul.f32 q2, q6, q10\n"
165 " vmul.f32 q3, q7, q11\n"
168 " vld1.32 {q4, q5}, [%[b]]!\n"
169 " vld1.32 {q8, q9}, [%[a]]!\n"
170 " vld1.32 {q6, q7}, [%[b]]!\n"
171 " vld1.32 {q10, q11}, [%[a]]!\n"
172 " subs %[len], %[len], #16\n"
173 " vmla.f32 q0, q4, q8\n"
174 " vmla.f32 q1, q5, q9\n"
175 " vmla.f32 q2, q6, q10\n"
176 " vmla.f32 q3, q7, q11\n"
179 " vadd.f32 q4, q0, q1\n"
180 " vadd.f32 q5, q2, q3\n"
181 " cmp %[remainder], #0\n"
182 " vadd.f32 q0, q4, q5\n"
185 " vld1.32 {q6}, [%[b]]!\n"
186 " vld1.32 {q10}, [%[a]]!\n"
187 " subs %[remainder], %[remainder], #4\n"
188 " vmla.f32 q0, q6, q10\n"
191 " vadd.f32 d0, d0, d1\n"
192 " vpadd.f32 d0, d0, d0\n"
193 " vmov.f32 %[ret], d0[0]\n"
194 : [ret] "=&r" (ret), [a] "+r" (a), [b] "+r" (b),
195 [len] "+l" (len), [remainder] "+l" (remainder)
197 : "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8",