cannam@154
|
1 /***********************************************************************
|
cannam@154
|
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
|
cannam@154
|
3 Copyright (c) 2013 Parrot
|
cannam@154
|
4 Redistribution and use in source and binary forms, with or without
|
cannam@154
|
5 modification, are permitted provided that the following conditions
|
cannam@154
|
6 are met:
|
cannam@154
|
7 - Redistributions of source code must retain the above copyright notice,
|
cannam@154
|
8 this list of conditions and the following disclaimer.
|
cannam@154
|
9 - Redistributions in binary form must reproduce the above copyright
|
cannam@154
|
10 notice, this list of conditions and the following disclaimer in the
|
cannam@154
|
11 documentation and/or other materials provided with the distribution.
|
cannam@154
|
12 - Neither the name of Internet Society, IETF or IETF Trust, nor the
|
cannam@154
|
13 names of specific contributors, may be used to endorse or promote
|
cannam@154
|
14 products derived from this software without specific prior written
|
cannam@154
|
15 permission.
|
cannam@154
|
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
cannam@154
|
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
cannam@154
|
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
cannam@154
|
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
cannam@154
|
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
cannam@154
|
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
cannam@154
|
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
cannam@154
|
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
cannam@154
|
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
cannam@154
|
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
cannam@154
|
26 POSSIBILITY OF SUCH DAMAGE.
|
cannam@154
|
27 ***********************************************************************/
|
cannam@154
|
28
|
cannam@154
|
29 #ifndef SILK_MACROS_ARMv5E_H
|
cannam@154
|
30 #define SILK_MACROS_ARMv5E_H
|
cannam@154
|
31
|
cannam@154
|
32 /* This macro only avoids the undefined behaviour from a left shift of
|
cannam@154
|
33 a negative value. It should only be used in macros that can't include
|
cannam@154
|
34 SigProc_FIX.h. In other cases, use silk_LSHIFT32(). */
|
cannam@154
|
35 #define SAFE_SHL(a,b) ((opus_int32)((opus_uint32)(a) << (b)))
|
cannam@154
|
36
|
cannam@154
|
37 /* (a32 * (opus_int32)((opus_int16)(b32))) >> 16 output have to be 32bit int */
|
cannam@154
|
38 #undef silk_SMULWB
|
cannam@154
|
39 static OPUS_INLINE opus_int32 silk_SMULWB_armv5e(opus_int32 a, opus_int16 b)
|
cannam@154
|
40 {
|
cannam@154
|
41 int res;
|
cannam@154
|
42 __asm__(
|
cannam@154
|
43 "#silk_SMULWB\n\t"
|
cannam@154
|
44 "smulwb %0, %1, %2\n\t"
|
cannam@154
|
45 : "=r"(res)
|
cannam@154
|
46 : "r"(a), "r"(b)
|
cannam@154
|
47 );
|
cannam@154
|
48 return res;
|
cannam@154
|
49 }
|
cannam@154
|
50 #define silk_SMULWB(a, b) (silk_SMULWB_armv5e(a, b))
|
cannam@154
|
51
|
cannam@154
|
52 /* a32 + (b32 * (opus_int32)((opus_int16)(c32))) >> 16 output have to be 32bit int */
|
cannam@154
|
53 #undef silk_SMLAWB
|
cannam@154
|
54 static OPUS_INLINE opus_int32 silk_SMLAWB_armv5e(opus_int32 a, opus_int32 b,
|
cannam@154
|
55 opus_int16 c)
|
cannam@154
|
56 {
|
cannam@154
|
57 int res;
|
cannam@154
|
58 __asm__(
|
cannam@154
|
59 "#silk_SMLAWB\n\t"
|
cannam@154
|
60 "smlawb %0, %1, %2, %3\n\t"
|
cannam@154
|
61 : "=r"(res)
|
cannam@154
|
62 : "r"(b), "r"(c), "r"(a)
|
cannam@154
|
63 );
|
cannam@154
|
64 return res;
|
cannam@154
|
65 }
|
cannam@154
|
66 #define silk_SMLAWB(a, b, c) (silk_SMLAWB_armv5e(a, b, c))
|
cannam@154
|
67
|
cannam@154
|
68 /* (a32 * (b32 >> 16)) >> 16 */
|
cannam@154
|
69 #undef silk_SMULWT
|
cannam@154
|
70 static OPUS_INLINE opus_int32 silk_SMULWT_armv5e(opus_int32 a, opus_int32 b)
|
cannam@154
|
71 {
|
cannam@154
|
72 int res;
|
cannam@154
|
73 __asm__(
|
cannam@154
|
74 "#silk_SMULWT\n\t"
|
cannam@154
|
75 "smulwt %0, %1, %2\n\t"
|
cannam@154
|
76 : "=r"(res)
|
cannam@154
|
77 : "r"(a), "r"(b)
|
cannam@154
|
78 );
|
cannam@154
|
79 return res;
|
cannam@154
|
80 }
|
cannam@154
|
81 #define silk_SMULWT(a, b) (silk_SMULWT_armv5e(a, b))
|
cannam@154
|
82
|
cannam@154
|
83 /* a32 + (b32 * (c32 >> 16)) >> 16 */
|
cannam@154
|
84 #undef silk_SMLAWT
|
cannam@154
|
85 static OPUS_INLINE opus_int32 silk_SMLAWT_armv5e(opus_int32 a, opus_int32 b,
|
cannam@154
|
86 opus_int32 c)
|
cannam@154
|
87 {
|
cannam@154
|
88 int res;
|
cannam@154
|
89 __asm__(
|
cannam@154
|
90 "#silk_SMLAWT\n\t"
|
cannam@154
|
91 "smlawt %0, %1, %2, %3\n\t"
|
cannam@154
|
92 : "=r"(res)
|
cannam@154
|
93 : "r"(b), "r"(c), "r"(a)
|
cannam@154
|
94 );
|
cannam@154
|
95 return res;
|
cannam@154
|
96 }
|
cannam@154
|
97 #define silk_SMLAWT(a, b, c) (silk_SMLAWT_armv5e(a, b, c))
|
cannam@154
|
98
|
cannam@154
|
99 /* (opus_int32)((opus_int16)(a3))) * (opus_int32)((opus_int16)(b32)) output have to be 32bit int */
|
cannam@154
|
100 #undef silk_SMULBB
|
cannam@154
|
101 static OPUS_INLINE opus_int32 silk_SMULBB_armv5e(opus_int32 a, opus_int32 b)
|
cannam@154
|
102 {
|
cannam@154
|
103 int res;
|
cannam@154
|
104 __asm__(
|
cannam@154
|
105 "#silk_SMULBB\n\t"
|
cannam@154
|
106 "smulbb %0, %1, %2\n\t"
|
cannam@154
|
107 : "=r"(res)
|
cannam@154
|
108 : "%r"(a), "r"(b)
|
cannam@154
|
109 );
|
cannam@154
|
110 return res;
|
cannam@154
|
111 }
|
cannam@154
|
112 #define silk_SMULBB(a, b) (silk_SMULBB_armv5e(a, b))
|
cannam@154
|
113
|
cannam@154
|
114 /* a32 + (opus_int32)((opus_int16)(b32)) * (opus_int32)((opus_int16)(c32)) output have to be 32bit int */
|
cannam@154
|
115 #undef silk_SMLABB
|
cannam@154
|
116 static OPUS_INLINE opus_int32 silk_SMLABB_armv5e(opus_int32 a, opus_int32 b,
|
cannam@154
|
117 opus_int32 c)
|
cannam@154
|
118 {
|
cannam@154
|
119 int res;
|
cannam@154
|
120 __asm__(
|
cannam@154
|
121 "#silk_SMLABB\n\t"
|
cannam@154
|
122 "smlabb %0, %1, %2, %3\n\t"
|
cannam@154
|
123 : "=r"(res)
|
cannam@154
|
124 : "%r"(b), "r"(c), "r"(a)
|
cannam@154
|
125 );
|
cannam@154
|
126 return res;
|
cannam@154
|
127 }
|
cannam@154
|
128 #define silk_SMLABB(a, b, c) (silk_SMLABB_armv5e(a, b, c))
|
cannam@154
|
129
|
cannam@154
|
130 /* (opus_int32)((opus_int16)(a32)) * (b32 >> 16) */
|
cannam@154
|
131 #undef silk_SMULBT
|
cannam@154
|
132 static OPUS_INLINE opus_int32 silk_SMULBT_armv5e(opus_int32 a, opus_int32 b)
|
cannam@154
|
133 {
|
cannam@154
|
134 int res;
|
cannam@154
|
135 __asm__(
|
cannam@154
|
136 "#silk_SMULBT\n\t"
|
cannam@154
|
137 "smulbt %0, %1, %2\n\t"
|
cannam@154
|
138 : "=r"(res)
|
cannam@154
|
139 : "r"(a), "r"(b)
|
cannam@154
|
140 );
|
cannam@154
|
141 return res;
|
cannam@154
|
142 }
|
cannam@154
|
143 #define silk_SMULBT(a, b) (silk_SMULBT_armv5e(a, b))
|
cannam@154
|
144
|
cannam@154
|
145 /* a32 + (opus_int32)((opus_int16)(b32)) * (c32 >> 16) */
|
cannam@154
|
146 #undef silk_SMLABT
|
cannam@154
|
147 static OPUS_INLINE opus_int32 silk_SMLABT_armv5e(opus_int32 a, opus_int32 b,
|
cannam@154
|
148 opus_int32 c)
|
cannam@154
|
149 {
|
cannam@154
|
150 int res;
|
cannam@154
|
151 __asm__(
|
cannam@154
|
152 "#silk_SMLABT\n\t"
|
cannam@154
|
153 "smlabt %0, %1, %2, %3\n\t"
|
cannam@154
|
154 : "=r"(res)
|
cannam@154
|
155 : "r"(b), "r"(c), "r"(a)
|
cannam@154
|
156 );
|
cannam@154
|
157 return res;
|
cannam@154
|
158 }
|
cannam@154
|
159 #define silk_SMLABT(a, b, c) (silk_SMLABT_armv5e(a, b, c))
|
cannam@154
|
160
|
cannam@154
|
161 /* add/subtract with output saturated */
|
cannam@154
|
162 #undef silk_ADD_SAT32
|
cannam@154
|
163 static OPUS_INLINE opus_int32 silk_ADD_SAT32_armv5e(opus_int32 a, opus_int32 b)
|
cannam@154
|
164 {
|
cannam@154
|
165 int res;
|
cannam@154
|
166 __asm__(
|
cannam@154
|
167 "#silk_ADD_SAT32\n\t"
|
cannam@154
|
168 "qadd %0, %1, %2\n\t"
|
cannam@154
|
169 : "=r"(res)
|
cannam@154
|
170 : "%r"(a), "r"(b)
|
cannam@154
|
171 );
|
cannam@154
|
172 return res;
|
cannam@154
|
173 }
|
cannam@154
|
174 #define silk_ADD_SAT32(a, b) (silk_ADD_SAT32_armv5e(a, b))
|
cannam@154
|
175
|
cannam@154
|
176 #undef silk_SUB_SAT32
|
cannam@154
|
177 static OPUS_INLINE opus_int32 silk_SUB_SAT32_armv5e(opus_int32 a, opus_int32 b)
|
cannam@154
|
178 {
|
cannam@154
|
179 int res;
|
cannam@154
|
180 __asm__(
|
cannam@154
|
181 "#silk_SUB_SAT32\n\t"
|
cannam@154
|
182 "qsub %0, %1, %2\n\t"
|
cannam@154
|
183 : "=r"(res)
|
cannam@154
|
184 : "r"(a), "r"(b)
|
cannam@154
|
185 );
|
cannam@154
|
186 return res;
|
cannam@154
|
187 }
|
cannam@154
|
188 #define silk_SUB_SAT32(a, b) (silk_SUB_SAT32_armv5e(a, b))
|
cannam@154
|
189
|
cannam@154
|
190 #undef silk_CLZ16
|
cannam@154
|
191 static OPUS_INLINE opus_int32 silk_CLZ16_armv5(opus_int16 in16)
|
cannam@154
|
192 {
|
cannam@154
|
193 int res;
|
cannam@154
|
194 __asm__(
|
cannam@154
|
195 "#silk_CLZ16\n\t"
|
cannam@154
|
196 "clz %0, %1;\n"
|
cannam@154
|
197 : "=r"(res)
|
cannam@154
|
198 : "r"(SAFE_SHL(in16,16)|0x8000)
|
cannam@154
|
199 );
|
cannam@154
|
200 return res;
|
cannam@154
|
201 }
|
cannam@154
|
202 #define silk_CLZ16(in16) (silk_CLZ16_armv5(in16))
|
cannam@154
|
203
|
cannam@154
|
204 #undef silk_CLZ32
|
cannam@154
|
205 static OPUS_INLINE opus_int32 silk_CLZ32_armv5(opus_int32 in32)
|
cannam@154
|
206 {
|
cannam@154
|
207 int res;
|
cannam@154
|
208 __asm__(
|
cannam@154
|
209 "#silk_CLZ32\n\t"
|
cannam@154
|
210 "clz %0, %1\n\t"
|
cannam@154
|
211 : "=r"(res)
|
cannam@154
|
212 : "r"(in32)
|
cannam@154
|
213 );
|
cannam@154
|
214 return res;
|
cannam@154
|
215 }
|
cannam@154
|
216 #define silk_CLZ32(in32) (silk_CLZ32_armv5(in32))
|
cannam@154
|
217
|
cannam@154
|
218 #undef SAFE_SHL
|
cannam@154
|
219
|
cannam@154
|
220 #endif /* SILK_MACROS_ARMv5E_H */
|