OLD | NEW |
1 /* Copyright (C) 2003-2008 Jean-Marc Valin | 1 /* Copyright (C) 2003-2008 Jean-Marc Valin |
2 Copyright (C) 2007-2012 Xiph.Org Foundation */ | 2 Copyright (C) 2007-2012 Xiph.Org Foundation */ |
3 /** | 3 /** |
4 @file fixed_debug.h | 4 @file fixed_debug.h |
5 @brief Fixed-point operations with debugging | 5 @brief Fixed-point operations with debugging |
6 */ | 6 */ |
7 /* | 7 /* |
8 Redistribution and use in source and binary forms, with or without | 8 Redistribution and use in source and binary forms, with or without |
9 modification, are permitted provided that the following conditions | 9 modification, are permitted provided that the following conditions |
10 are met: | 10 are met: |
(...skipping 15 matching lines...) Expand all Loading... |
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 */ | 30 */ |
31 | 31 |
32 #ifndef FIXED_DEBUG_H | 32 #ifndef FIXED_DEBUG_H |
33 #define FIXED_DEBUG_H | 33 #define FIXED_DEBUG_H |
34 | 34 |
35 #include <stdio.h> | 35 #include <stdio.h> |
| 36 #include "opus_defines.h" |
36 | 37 |
37 #ifdef CELT_C | 38 #ifdef CELT_C |
38 #include "opus_defines.h" | |
39 OPUS_EXPORT opus_int64 celt_mips=0; | 39 OPUS_EXPORT opus_int64 celt_mips=0; |
40 #else | 40 #else |
41 extern opus_int64 celt_mips; | 41 extern opus_int64 celt_mips; |
42 #endif | 42 #endif |
43 | 43 |
44 #define MULT16_16SU(a,b) ((opus_val32)(opus_val16)(a)*(opus_val32)(opus_uint16)(
b)) | 44 #define MULT16_16SU(a,b) ((opus_val32)(opus_val16)(a)*(opus_val32)(opus_uint16)(
b)) |
45 #define MULT32_32_Q31(a,b) ADD32(ADD32(SHL32(MULT16_16(SHR32((a),16),SHR((b),16)
),1), SHR32(MULT16_16SU(SHR32((a),16),((b)&0x0000ffff)),15)), SHR32(MULT16_16SU(
SHR32((b),16),((a)&0x0000ffff)),15)) | 45 #define MULT32_32_Q31(a,b) ADD32(ADD32(SHL32(MULT16_16(SHR32((a),16),SHR((b),16)
),1), SHR32(MULT16_16SU(SHR32((a),16),((b)&0x0000ffff)),15)), SHR32(MULT16_16SU(
SHR32((b),16),((a)&0x0000ffff)),15)) |
46 | 46 |
47 /** 16x32 multiplication, followed by a 16-bit shift right. Results fits in 32 b
its */ | 47 /** 16x32 multiplication, followed by a 16-bit shift right. Results fits in 32 b
its */ |
48 #define MULT16_32_Q16(a,b) ADD32(MULT16_16((a),SHR32((b),16)), SHR32(MULT16_16SU
((a),((b)&0x0000ffff)),16)) | 48 #define MULT16_32_Q16(a,b) ADD32(MULT16_16((a),SHR32((b),16)), SHR32(MULT16_16SU
((a),((b)&0x0000ffff)),16)) |
49 | 49 |
50 #define MULT16_32_P16(a,b) MULT16_32_PX(a,b,16) | 50 #define MULT16_32_P16(a,b) MULT16_32_PX(a,b,16) |
51 | 51 |
52 #define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits)))) | 52 #define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits)))) |
53 #define QCONST32(x,bits) ((opus_val32)(.5+(x)*(((opus_val32)1)<<(bits)))) | 53 #define QCONST32(x,bits) ((opus_val32)(.5+(x)*(((opus_val32)1)<<(bits)))) |
54 | 54 |
55 #define VERIFY_SHORT(x) ((x)<=32767&&(x)>=-32768) | 55 #define VERIFY_SHORT(x) ((x)<=32767&&(x)>=-32768) |
56 #define VERIFY_INT(x) ((x)<=2147483647LL&&(x)>=-2147483648LL) | 56 #define VERIFY_INT(x) ((x)<=2147483647LL&&(x)>=-2147483648LL) |
57 #define VERIFY_UINT(x) ((x)<=(2147483647LLU<<1)) | 57 #define VERIFY_UINT(x) ((x)<=(2147483647LLU<<1)) |
58 | 58 |
59 #define SHR(a,b) SHR32(a,b) | 59 #define SHR(a,b) SHR32(a,b) |
60 #define PSHR(a,b) PSHR32(a,b) | 60 #define PSHR(a,b) PSHR32(a,b) |
61 | 61 |
62 static inline short NEG16(int x) | 62 static OPUS_INLINE short NEG16(int x) |
63 { | 63 { |
64 int res; | 64 int res; |
65 if (!VERIFY_SHORT(x)) | 65 if (!VERIFY_SHORT(x)) |
66 { | 66 { |
67 fprintf (stderr, "NEG16: input is not short: %d\n", (int)x); | 67 fprintf (stderr, "NEG16: input is not short: %d\n", (int)x); |
68 #ifdef FIXED_DEBUG_ASSERT | 68 #ifdef FIXED_DEBUG_ASSERT |
69 celt_assert(0); | 69 celt_assert(0); |
70 #endif | 70 #endif |
71 } | 71 } |
72 res = -x; | 72 res = -x; |
73 if (!VERIFY_SHORT(res)) | 73 if (!VERIFY_SHORT(res)) |
74 { | 74 { |
75 fprintf (stderr, "NEG16: output is not short: %d\n", (int)res); | 75 fprintf (stderr, "NEG16: output is not short: %d\n", (int)res); |
76 #ifdef FIXED_DEBUG_ASSERT | 76 #ifdef FIXED_DEBUG_ASSERT |
77 celt_assert(0); | 77 celt_assert(0); |
78 #endif | 78 #endif |
79 } | 79 } |
80 celt_mips++; | 80 celt_mips++; |
81 return res; | 81 return res; |
82 } | 82 } |
83 static inline int NEG32(opus_int64 x) | 83 static OPUS_INLINE int NEG32(opus_int64 x) |
84 { | 84 { |
85 opus_int64 res; | 85 opus_int64 res; |
86 if (!VERIFY_INT(x)) | 86 if (!VERIFY_INT(x)) |
87 { | 87 { |
88 fprintf (stderr, "NEG16: input is not int: %d\n", (int)x); | 88 fprintf (stderr, "NEG16: input is not int: %d\n", (int)x); |
89 #ifdef FIXED_DEBUG_ASSERT | 89 #ifdef FIXED_DEBUG_ASSERT |
90 celt_assert(0); | 90 celt_assert(0); |
91 #endif | 91 #endif |
92 } | 92 } |
93 res = -x; | 93 res = -x; |
94 if (!VERIFY_INT(res)) | 94 if (!VERIFY_INT(res)) |
95 { | 95 { |
96 fprintf (stderr, "NEG16: output is not int: %d\n", (int)res); | 96 fprintf (stderr, "NEG16: output is not int: %d\n", (int)res); |
97 #ifdef FIXED_DEBUG_ASSERT | 97 #ifdef FIXED_DEBUG_ASSERT |
98 celt_assert(0); | 98 celt_assert(0); |
99 #endif | 99 #endif |
100 } | 100 } |
101 celt_mips+=2; | 101 celt_mips+=2; |
102 return res; | 102 return res; |
103 } | 103 } |
104 | 104 |
105 #define EXTRACT16(x) EXTRACT16_(x, __FILE__, __LINE__) | 105 #define EXTRACT16(x) EXTRACT16_(x, __FILE__, __LINE__) |
106 static inline short EXTRACT16_(int x, char *file, int line) | 106 static OPUS_INLINE short EXTRACT16_(int x, char *file, int line) |
107 { | 107 { |
108 int res; | 108 int res; |
109 if (!VERIFY_SHORT(x)) | 109 if (!VERIFY_SHORT(x)) |
110 { | 110 { |
111 fprintf (stderr, "EXTRACT16: input is not short: %d in %s: line %d\n", x,
file, line); | 111 fprintf (stderr, "EXTRACT16: input is not short: %d in %s: line %d\n", x,
file, line); |
112 #ifdef FIXED_DEBUG_ASSERT | 112 #ifdef FIXED_DEBUG_ASSERT |
113 celt_assert(0); | 113 celt_assert(0); |
114 #endif | 114 #endif |
115 } | 115 } |
116 res = x; | 116 res = x; |
117 celt_mips++; | 117 celt_mips++; |
118 return res; | 118 return res; |
119 } | 119 } |
120 | 120 |
121 #define EXTEND32(x) EXTEND32_(x, __FILE__, __LINE__) | 121 #define EXTEND32(x) EXTEND32_(x, __FILE__, __LINE__) |
122 static inline int EXTEND32_(int x, char *file, int line) | 122 static OPUS_INLINE int EXTEND32_(int x, char *file, int line) |
123 { | 123 { |
124 int res; | 124 int res; |
125 if (!VERIFY_SHORT(x)) | 125 if (!VERIFY_SHORT(x)) |
126 { | 126 { |
127 fprintf (stderr, "EXTEND32: input is not short: %d in %s: line %d\n", x, f
ile, line); | 127 fprintf (stderr, "EXTEND32: input is not short: %d in %s: line %d\n", x, f
ile, line); |
128 #ifdef FIXED_DEBUG_ASSERT | 128 #ifdef FIXED_DEBUG_ASSERT |
129 celt_assert(0); | 129 celt_assert(0); |
130 #endif | 130 #endif |
131 } | 131 } |
132 res = x; | 132 res = x; |
133 celt_mips++; | 133 celt_mips++; |
134 return res; | 134 return res; |
135 } | 135 } |
136 | 136 |
137 #define SHR16(a, shift) SHR16_(a, shift, __FILE__, __LINE__) | 137 #define SHR16(a, shift) SHR16_(a, shift, __FILE__, __LINE__) |
138 static inline short SHR16_(int a, int shift, char *file, int line) | 138 static OPUS_INLINE short SHR16_(int a, int shift, char *file, int line) |
139 { | 139 { |
140 int res; | 140 int res; |
141 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift)) | 141 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift)) |
142 { | 142 { |
143 fprintf (stderr, "SHR16: inputs are not short: %d >> %d in %s: line %d\n",
a, shift, file, line); | 143 fprintf (stderr, "SHR16: inputs are not short: %d >> %d in %s: line %d\n",
a, shift, file, line); |
144 #ifdef FIXED_DEBUG_ASSERT | 144 #ifdef FIXED_DEBUG_ASSERT |
145 celt_assert(0); | 145 celt_assert(0); |
146 #endif | 146 #endif |
147 } | 147 } |
148 res = a>>shift; | 148 res = a>>shift; |
149 if (!VERIFY_SHORT(res)) | 149 if (!VERIFY_SHORT(res)) |
150 { | 150 { |
151 fprintf (stderr, "SHR16: output is not short: %d in %s: line %d\n", res, f
ile, line); | 151 fprintf (stderr, "SHR16: output is not short: %d in %s: line %d\n", res, f
ile, line); |
152 #ifdef FIXED_DEBUG_ASSERT | 152 #ifdef FIXED_DEBUG_ASSERT |
153 celt_assert(0); | 153 celt_assert(0); |
154 #endif | 154 #endif |
155 } | 155 } |
156 celt_mips++; | 156 celt_mips++; |
157 return res; | 157 return res; |
158 } | 158 } |
159 #define SHL16(a, shift) SHL16_(a, shift, __FILE__, __LINE__) | 159 #define SHL16(a, shift) SHL16_(a, shift, __FILE__, __LINE__) |
160 static inline short SHL16_(int a, int shift, char *file, int line) | 160 static OPUS_INLINE short SHL16_(int a, int shift, char *file, int line) |
161 { | 161 { |
162 int res; | 162 int res; |
163 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift)) | 163 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift)) |
164 { | 164 { |
165 fprintf (stderr, "SHL16: inputs are not short: %d %d in %s: line %d\n", a,
shift, file, line); | 165 fprintf (stderr, "SHL16: inputs are not short: %d %d in %s: line %d\n", a,
shift, file, line); |
166 #ifdef FIXED_DEBUG_ASSERT | 166 #ifdef FIXED_DEBUG_ASSERT |
167 celt_assert(0); | 167 celt_assert(0); |
168 #endif | 168 #endif |
169 } | 169 } |
170 res = a<<shift; | 170 res = a<<shift; |
171 if (!VERIFY_SHORT(res)) | 171 if (!VERIFY_SHORT(res)) |
172 { | 172 { |
173 fprintf (stderr, "SHL16: output is not short: %d in %s: line %d\n", res, f
ile, line); | 173 fprintf (stderr, "SHL16: output is not short: %d in %s: line %d\n", res, f
ile, line); |
174 #ifdef FIXED_DEBUG_ASSERT | 174 #ifdef FIXED_DEBUG_ASSERT |
175 celt_assert(0); | 175 celt_assert(0); |
176 #endif | 176 #endif |
177 } | 177 } |
178 celt_mips++; | 178 celt_mips++; |
179 return res; | 179 return res; |
180 } | 180 } |
181 | 181 |
182 static inline int SHR32(opus_int64 a, int shift) | 182 static OPUS_INLINE int SHR32(opus_int64 a, int shift) |
183 { | 183 { |
184 opus_int64 res; | 184 opus_int64 res; |
185 if (!VERIFY_INT(a) || !VERIFY_SHORT(shift)) | 185 if (!VERIFY_INT(a) || !VERIFY_SHORT(shift)) |
186 { | 186 { |
187 fprintf (stderr, "SHR32: inputs are not int: %d %d\n", (int)a, shift); | 187 fprintf (stderr, "SHR32: inputs are not int: %d %d\n", (int)a, shift); |
188 #ifdef FIXED_DEBUG_ASSERT | 188 #ifdef FIXED_DEBUG_ASSERT |
189 celt_assert(0); | 189 celt_assert(0); |
190 #endif | 190 #endif |
191 } | 191 } |
192 res = a>>shift; | 192 res = a>>shift; |
193 if (!VERIFY_INT(res)) | 193 if (!VERIFY_INT(res)) |
194 { | 194 { |
195 fprintf (stderr, "SHR32: output is not int: %d\n", (int)res); | 195 fprintf (stderr, "SHR32: output is not int: %d\n", (int)res); |
196 #ifdef FIXED_DEBUG_ASSERT | 196 #ifdef FIXED_DEBUG_ASSERT |
197 celt_assert(0); | 197 celt_assert(0); |
198 #endif | 198 #endif |
199 } | 199 } |
200 celt_mips+=2; | 200 celt_mips+=2; |
201 return res; | 201 return res; |
202 } | 202 } |
203 #define SHL32(a, shift) SHL32_(a, shift, __FILE__, __LINE__) | 203 #define SHL32(a, shift) SHL32_(a, shift, __FILE__, __LINE__) |
204 static inline int SHL32_(opus_int64 a, int shift, char *file, int line) | 204 static OPUS_INLINE int SHL32_(opus_int64 a, int shift, char *file, int line) |
205 { | 205 { |
206 opus_int64 res; | 206 opus_int64 res; |
207 if (!VERIFY_INT(a) || !VERIFY_SHORT(shift)) | 207 if (!VERIFY_INT(a) || !VERIFY_SHORT(shift)) |
208 { | 208 { |
209 fprintf (stderr, "SHL32: inputs are not int: %lld %d in %s: line %d\n", a,
shift, file, line); | 209 fprintf (stderr, "SHL32: inputs are not int: %lld %d in %s: line %d\n", a,
shift, file, line); |
210 #ifdef FIXED_DEBUG_ASSERT | 210 #ifdef FIXED_DEBUG_ASSERT |
211 celt_assert(0); | 211 celt_assert(0); |
212 #endif | 212 #endif |
213 } | 213 } |
214 res = a<<shift; | 214 res = a<<shift; |
(...skipping 12 matching lines...) Expand all Loading... |
227 #define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) | 227 #define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) |
228 | 228 |
229 #define ROUND16(x,a) (celt_mips--,EXTRACT16(PSHR32((x),(a)))) | 229 #define ROUND16(x,a) (celt_mips--,EXTRACT16(PSHR32((x),(a)))) |
230 #define HALF16(x) (SHR16(x,1)) | 230 #define HALF16(x) (SHR16(x,1)) |
231 #define HALF32(x) (SHR32(x,1)) | 231 #define HALF32(x) (SHR32(x,1)) |
232 | 232 |
233 //#define SHR(a,shift) ((a) >> (shift)) | 233 //#define SHR(a,shift) ((a) >> (shift)) |
234 //#define SHL(a,shift) ((a) << (shift)) | 234 //#define SHL(a,shift) ((a) << (shift)) |
235 | 235 |
236 #define ADD16(a, b) ADD16_(a, b, __FILE__, __LINE__) | 236 #define ADD16(a, b) ADD16_(a, b, __FILE__, __LINE__) |
237 static inline short ADD16_(int a, int b, char *file, int line) | 237 static OPUS_INLINE short ADD16_(int a, int b, char *file, int line) |
238 { | 238 { |
239 int res; | 239 int res; |
240 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 240 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
241 { | 241 { |
242 fprintf (stderr, "ADD16: inputs are not short: %d %d in %s: line %d\n", a,
b, file, line); | 242 fprintf (stderr, "ADD16: inputs are not short: %d %d in %s: line %d\n", a,
b, file, line); |
243 #ifdef FIXED_DEBUG_ASSERT | 243 #ifdef FIXED_DEBUG_ASSERT |
244 celt_assert(0); | 244 celt_assert(0); |
245 #endif | 245 #endif |
246 } | 246 } |
247 res = a+b; | 247 res = a+b; |
248 if (!VERIFY_SHORT(res)) | 248 if (!VERIFY_SHORT(res)) |
249 { | 249 { |
250 fprintf (stderr, "ADD16: output is not short: %d+%d=%d in %s: line %d\n",
a,b,res, file, line); | 250 fprintf (stderr, "ADD16: output is not short: %d+%d=%d in %s: line %d\n",
a,b,res, file, line); |
251 #ifdef FIXED_DEBUG_ASSERT | 251 #ifdef FIXED_DEBUG_ASSERT |
252 celt_assert(0); | 252 celt_assert(0); |
253 #endif | 253 #endif |
254 } | 254 } |
255 celt_mips++; | 255 celt_mips++; |
256 return res; | 256 return res; |
257 } | 257 } |
258 | 258 |
259 #define SUB16(a, b) SUB16_(a, b, __FILE__, __LINE__) | 259 #define SUB16(a, b) SUB16_(a, b, __FILE__, __LINE__) |
260 static inline short SUB16_(int a, int b, char *file, int line) | 260 static OPUS_INLINE short SUB16_(int a, int b, char *file, int line) |
261 { | 261 { |
262 int res; | 262 int res; |
263 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 263 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
264 { | 264 { |
265 fprintf (stderr, "SUB16: inputs are not short: %d %d in %s: line %d\n", a,
b, file, line); | 265 fprintf (stderr, "SUB16: inputs are not short: %d %d in %s: line %d\n", a,
b, file, line); |
266 #ifdef FIXED_DEBUG_ASSERT | 266 #ifdef FIXED_DEBUG_ASSERT |
267 celt_assert(0); | 267 celt_assert(0); |
268 #endif | 268 #endif |
269 } | 269 } |
270 res = a-b; | 270 res = a-b; |
271 if (!VERIFY_SHORT(res)) | 271 if (!VERIFY_SHORT(res)) |
272 { | 272 { |
273 fprintf (stderr, "SUB16: output is not short: %d in %s: line %d\n", res, f
ile, line); | 273 fprintf (stderr, "SUB16: output is not short: %d in %s: line %d\n", res, f
ile, line); |
274 #ifdef FIXED_DEBUG_ASSERT | 274 #ifdef FIXED_DEBUG_ASSERT |
275 celt_assert(0); | 275 celt_assert(0); |
276 #endif | 276 #endif |
277 } | 277 } |
278 celt_mips++; | 278 celt_mips++; |
279 return res; | 279 return res; |
280 } | 280 } |
281 | 281 |
282 #define ADD32(a, b) ADD32_(a, b, __FILE__, __LINE__) | 282 #define ADD32(a, b) ADD32_(a, b, __FILE__, __LINE__) |
283 static inline int ADD32_(opus_int64 a, opus_int64 b, char *file, int line) | 283 static OPUS_INLINE int ADD32_(opus_int64 a, opus_int64 b, char *file, int line) |
284 { | 284 { |
285 opus_int64 res; | 285 opus_int64 res; |
286 if (!VERIFY_INT(a) || !VERIFY_INT(b)) | 286 if (!VERIFY_INT(a) || !VERIFY_INT(b)) |
287 { | 287 { |
288 fprintf (stderr, "ADD32: inputs are not int: %d %d in %s: line %d\n", (int
)a, (int)b, file, line); | 288 fprintf (stderr, "ADD32: inputs are not int: %d %d in %s: line %d\n", (int
)a, (int)b, file, line); |
289 #ifdef FIXED_DEBUG_ASSERT | 289 #ifdef FIXED_DEBUG_ASSERT |
290 celt_assert(0); | 290 celt_assert(0); |
291 #endif | 291 #endif |
292 } | 292 } |
293 res = a+b; | 293 res = a+b; |
294 if (!VERIFY_INT(res)) | 294 if (!VERIFY_INT(res)) |
295 { | 295 { |
296 fprintf (stderr, "ADD32: output is not int: %d in %s: line %d\n", (int)res
, file, line); | 296 fprintf (stderr, "ADD32: output is not int: %d in %s: line %d\n", (int)res
, file, line); |
297 #ifdef FIXED_DEBUG_ASSERT | 297 #ifdef FIXED_DEBUG_ASSERT |
298 celt_assert(0); | 298 celt_assert(0); |
299 #endif | 299 #endif |
300 } | 300 } |
301 celt_mips+=2; | 301 celt_mips+=2; |
302 return res; | 302 return res; |
303 } | 303 } |
304 | 304 |
305 #define SUB32(a, b) SUB32_(a, b, __FILE__, __LINE__) | 305 #define SUB32(a, b) SUB32_(a, b, __FILE__, __LINE__) |
306 static inline int SUB32_(opus_int64 a, opus_int64 b, char *file, int line) | 306 static OPUS_INLINE int SUB32_(opus_int64 a, opus_int64 b, char *file, int line) |
307 { | 307 { |
308 opus_int64 res; | 308 opus_int64 res; |
309 if (!VERIFY_INT(a) || !VERIFY_INT(b)) | 309 if (!VERIFY_INT(a) || !VERIFY_INT(b)) |
310 { | 310 { |
311 fprintf (stderr, "SUB32: inputs are not int: %d %d in %s: line %d\n", (int
)a, (int)b, file, line); | 311 fprintf (stderr, "SUB32: inputs are not int: %d %d in %s: line %d\n", (int
)a, (int)b, file, line); |
312 #ifdef FIXED_DEBUG_ASSERT | 312 #ifdef FIXED_DEBUG_ASSERT |
313 celt_assert(0); | 313 celt_assert(0); |
314 #endif | 314 #endif |
315 } | 315 } |
316 res = a-b; | 316 res = a-b; |
317 if (!VERIFY_INT(res)) | 317 if (!VERIFY_INT(res)) |
318 { | 318 { |
319 fprintf (stderr, "SUB32: output is not int: %d in %s: line %d\n", (int)res
, file, line); | 319 fprintf (stderr, "SUB32: output is not int: %d in %s: line %d\n", (int)res
, file, line); |
320 #ifdef FIXED_DEBUG_ASSERT | 320 #ifdef FIXED_DEBUG_ASSERT |
321 celt_assert(0); | 321 celt_assert(0); |
322 #endif | 322 #endif |
323 } | 323 } |
324 celt_mips+=2; | 324 celt_mips+=2; |
325 return res; | 325 return res; |
326 } | 326 } |
327 | 327 |
328 #undef UADD32 | 328 #undef UADD32 |
329 #define UADD32(a, b) UADD32_(a, b, __FILE__, __LINE__) | 329 #define UADD32(a, b) UADD32_(a, b, __FILE__, __LINE__) |
330 static inline unsigned int UADD32_(opus_uint64 a, opus_uint64 b, char *file, int
line) | 330 static OPUS_INLINE unsigned int UADD32_(opus_uint64 a, opus_uint64 b, char *file
, int line) |
331 { | 331 { |
332 opus_uint64 res; | 332 opus_uint64 res; |
333 if (!VERIFY_UINT(a) || !VERIFY_UINT(b)) | 333 if (!VERIFY_UINT(a) || !VERIFY_UINT(b)) |
334 { | 334 { |
335 fprintf (stderr, "UADD32: inputs are not uint32: %llu %llu in %s: line %d\
n", a, b, file, line); | 335 fprintf (stderr, "UADD32: inputs are not uint32: %llu %llu in %s: line %d\
n", a, b, file, line); |
336 #ifdef FIXED_DEBUG_ASSERT | 336 #ifdef FIXED_DEBUG_ASSERT |
337 celt_assert(0); | 337 celt_assert(0); |
338 #endif | 338 #endif |
339 } | 339 } |
340 res = a+b; | 340 res = a+b; |
341 if (!VERIFY_UINT(res)) | 341 if (!VERIFY_UINT(res)) |
342 { | 342 { |
343 fprintf (stderr, "UADD32: output is not uint32: %llu in %s: line %d\n", re
s, file, line); | 343 fprintf (stderr, "UADD32: output is not uint32: %llu in %s: line %d\n", re
s, file, line); |
344 #ifdef FIXED_DEBUG_ASSERT | 344 #ifdef FIXED_DEBUG_ASSERT |
345 celt_assert(0); | 345 celt_assert(0); |
346 #endif | 346 #endif |
347 } | 347 } |
348 celt_mips+=2; | 348 celt_mips+=2; |
349 return res; | 349 return res; |
350 } | 350 } |
351 | 351 |
352 #undef USUB32 | 352 #undef USUB32 |
353 #define USUB32(a, b) USUB32_(a, b, __FILE__, __LINE__) | 353 #define USUB32(a, b) USUB32_(a, b, __FILE__, __LINE__) |
354 static inline unsigned int USUB32_(opus_uint64 a, opus_uint64 b, char *file, int
line) | 354 static OPUS_INLINE unsigned int USUB32_(opus_uint64 a, opus_uint64 b, char *file
, int line) |
355 { | 355 { |
356 opus_uint64 res; | 356 opus_uint64 res; |
357 if (!VERIFY_UINT(a) || !VERIFY_UINT(b)) | 357 if (!VERIFY_UINT(a) || !VERIFY_UINT(b)) |
358 { | 358 { |
359 fprintf (stderr, "USUB32: inputs are not uint32: %llu %llu in %s: line %d\
n", a, b, file, line); | 359 fprintf (stderr, "USUB32: inputs are not uint32: %llu %llu in %s: line %d\
n", a, b, file, line); |
360 #ifdef FIXED_DEBUG_ASSERT | 360 #ifdef FIXED_DEBUG_ASSERT |
361 celt_assert(0); | 361 celt_assert(0); |
362 #endif | 362 #endif |
363 } | 363 } |
364 if (a<b) | 364 if (a<b) |
365 { | 365 { |
366 fprintf (stderr, "USUB32: inputs underflow: %llu < %llu in %s: line %d\n",
a, b, file, line); | 366 fprintf (stderr, "USUB32: inputs underflow: %llu < %llu in %s: line %d\n",
a, b, file, line); |
367 #ifdef FIXED_DEBUG_ASSERT | 367 #ifdef FIXED_DEBUG_ASSERT |
368 celt_assert(0); | 368 celt_assert(0); |
369 #endif | 369 #endif |
370 } | 370 } |
371 res = a-b; | 371 res = a-b; |
372 if (!VERIFY_UINT(res)) | 372 if (!VERIFY_UINT(res)) |
373 { | 373 { |
374 fprintf (stderr, "USUB32: output is not uint32: %llu - %llu = %llu in %s:
line %d\n", a, b, res, file, line); | 374 fprintf (stderr, "USUB32: output is not uint32: %llu - %llu = %llu in %s:
line %d\n", a, b, res, file, line); |
375 #ifdef FIXED_DEBUG_ASSERT | 375 #ifdef FIXED_DEBUG_ASSERT |
376 celt_assert(0); | 376 celt_assert(0); |
377 #endif | 377 #endif |
378 } | 378 } |
379 celt_mips+=2; | 379 celt_mips+=2; |
380 return res; | 380 return res; |
381 } | 381 } |
382 | 382 |
383 /* result fits in 16 bits */ | 383 /* result fits in 16 bits */ |
384 static inline short MULT16_16_16(int a, int b) | 384 static OPUS_INLINE short MULT16_16_16(int a, int b) |
385 { | 385 { |
386 int res; | 386 int res; |
387 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 387 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
388 { | 388 { |
389 fprintf (stderr, "MULT16_16_16: inputs are not short: %d %d\n", a, b); | 389 fprintf (stderr, "MULT16_16_16: inputs are not short: %d %d\n", a, b); |
390 #ifdef FIXED_DEBUG_ASSERT | 390 #ifdef FIXED_DEBUG_ASSERT |
391 celt_assert(0); | 391 celt_assert(0); |
392 #endif | 392 #endif |
393 } | 393 } |
394 res = a*b; | 394 res = a*b; |
395 if (!VERIFY_SHORT(res)) | 395 if (!VERIFY_SHORT(res)) |
396 { | 396 { |
397 fprintf (stderr, "MULT16_16_16: output is not short: %d\n", res); | 397 fprintf (stderr, "MULT16_16_16: output is not short: %d\n", res); |
398 #ifdef FIXED_DEBUG_ASSERT | 398 #ifdef FIXED_DEBUG_ASSERT |
399 celt_assert(0); | 399 celt_assert(0); |
400 #endif | 400 #endif |
401 } | 401 } |
402 celt_mips++; | 402 celt_mips++; |
403 return res; | 403 return res; |
404 } | 404 } |
405 | 405 |
406 #define MULT16_16(a, b) MULT16_16_(a, b, __FILE__, __LINE__) | 406 #define MULT16_16(a, b) MULT16_16_(a, b, __FILE__, __LINE__) |
407 static inline int MULT16_16_(int a, int b, char *file, int line) | 407 static OPUS_INLINE int MULT16_16_(int a, int b, char *file, int line) |
408 { | 408 { |
409 opus_int64 res; | 409 opus_int64 res; |
410 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 410 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
411 { | 411 { |
412 fprintf (stderr, "MULT16_16: inputs are not short: %d %d in %s: line %d\n"
, a, b, file, line); | 412 fprintf (stderr, "MULT16_16: inputs are not short: %d %d in %s: line %d\n"
, a, b, file, line); |
413 #ifdef FIXED_DEBUG_ASSERT | 413 #ifdef FIXED_DEBUG_ASSERT |
414 celt_assert(0); | 414 celt_assert(0); |
415 #endif | 415 #endif |
416 } | 416 } |
417 res = ((opus_int64)a)*b; | 417 res = ((opus_int64)a)*b; |
418 if (!VERIFY_INT(res)) | 418 if (!VERIFY_INT(res)) |
419 { | 419 { |
420 fprintf (stderr, "MULT16_16: output is not int: %d in %s: line %d\n", (int
)res, file, line); | 420 fprintf (stderr, "MULT16_16: output is not int: %d in %s: line %d\n", (int
)res, file, line); |
421 #ifdef FIXED_DEBUG_ASSERT | 421 #ifdef FIXED_DEBUG_ASSERT |
422 celt_assert(0); | 422 celt_assert(0); |
423 #endif | 423 #endif |
424 } | 424 } |
425 celt_mips++; | 425 celt_mips++; |
426 return res; | 426 return res; |
427 } | 427 } |
428 | 428 |
429 #define MAC16_16(c,a,b) (celt_mips-=2,ADD32((c),MULT16_16((a),(b)))) | 429 #define MAC16_16(c,a,b) (celt_mips-=2,ADD32((c),MULT16_16((a),(b)))) |
430 | 430 |
431 #define MULT16_32_QX(a, b, Q) MULT16_32_QX_(a, b, Q, __FILE__, __LINE__) | 431 #define MULT16_32_QX(a, b, Q) MULT16_32_QX_(a, b, Q, __FILE__, __LINE__) |
432 static inline int MULT16_32_QX_(int a, opus_int64 b, int Q, char *file, int line
) | 432 static OPUS_INLINE int MULT16_32_QX_(int a, opus_int64 b, int Q, char *file, int
line) |
433 { | 433 { |
434 opus_int64 res; | 434 opus_int64 res; |
435 if (!VERIFY_SHORT(a) || !VERIFY_INT(b)) | 435 if (!VERIFY_SHORT(a) || !VERIFY_INT(b)) |
436 { | 436 { |
437 fprintf (stderr, "MULT16_32_Q%d: inputs are not short+int: %d %d in %s: li
ne %d\n", Q, (int)a, (int)b, file, line); | 437 fprintf (stderr, "MULT16_32_Q%d: inputs are not short+int: %d %d in %s: li
ne %d\n", Q, (int)a, (int)b, file, line); |
438 #ifdef FIXED_DEBUG_ASSERT | 438 #ifdef FIXED_DEBUG_ASSERT |
439 celt_assert(0); | 439 celt_assert(0); |
440 #endif | 440 #endif |
441 } | 441 } |
442 if (ABS32(b)>=((opus_val32)(1)<<(15+Q))) | 442 if (ABS32(b)>=((opus_val32)(1)<<(15+Q))) |
(...skipping 12 matching lines...) Expand all Loading... |
455 #endif | 455 #endif |
456 } | 456 } |
457 if (Q==15) | 457 if (Q==15) |
458 celt_mips+=3; | 458 celt_mips+=3; |
459 else | 459 else |
460 celt_mips+=4; | 460 celt_mips+=4; |
461 return res; | 461 return res; |
462 } | 462 } |
463 | 463 |
464 #define MULT16_32_PX(a, b, Q) MULT16_32_PX_(a, b, Q, __FILE__, __LINE__) | 464 #define MULT16_32_PX(a, b, Q) MULT16_32_PX_(a, b, Q, __FILE__, __LINE__) |
465 static inline int MULT16_32_PX_(int a, opus_int64 b, int Q, char *file, int line
) | 465 static OPUS_INLINE int MULT16_32_PX_(int a, opus_int64 b, int Q, char *file, int
line) |
466 { | 466 { |
467 opus_int64 res; | 467 opus_int64 res; |
468 if (!VERIFY_SHORT(a) || !VERIFY_INT(b)) | 468 if (!VERIFY_SHORT(a) || !VERIFY_INT(b)) |
469 { | 469 { |
470 fprintf (stderr, "MULT16_32_P%d: inputs are not short+int: %d %d in %s: li
ne %d\n\n", Q, (int)a, (int)b, file, line); | 470 fprintf (stderr, "MULT16_32_P%d: inputs are not short+int: %d %d in %s: li
ne %d\n\n", Q, (int)a, (int)b, file, line); |
471 #ifdef FIXED_DEBUG_ASSERT | 471 #ifdef FIXED_DEBUG_ASSERT |
472 celt_assert(0); | 472 celt_assert(0); |
473 #endif | 473 #endif |
474 } | 474 } |
475 if (ABS32(b)>=((opus_int64)(1)<<(15+Q))) | 475 if (ABS32(b)>=((opus_int64)(1)<<(15+Q))) |
(...skipping 14 matching lines...) Expand all Loading... |
490 if (Q==15) | 490 if (Q==15) |
491 celt_mips+=4; | 491 celt_mips+=4; |
492 else | 492 else |
493 celt_mips+=5; | 493 celt_mips+=5; |
494 return res; | 494 return res; |
495 } | 495 } |
496 | 496 |
497 #define MULT16_32_Q15(a,b) MULT16_32_QX(a,b,15) | 497 #define MULT16_32_Q15(a,b) MULT16_32_QX(a,b,15) |
498 #define MAC16_32_Q15(c,a,b) (celt_mips-=2,ADD32((c),MULT16_32_Q15((a),(b)))) | 498 #define MAC16_32_Q15(c,a,b) (celt_mips-=2,ADD32((c),MULT16_32_Q15((a),(b)))) |
499 | 499 |
500 static inline int SATURATE(int a, int b) | 500 static OPUS_INLINE int SATURATE(int a, int b) |
501 { | 501 { |
502 if (a>b) | 502 if (a>b) |
503 a=b; | 503 a=b; |
504 if (a<-b) | 504 if (a<-b) |
505 a = -b; | 505 a = -b; |
506 celt_mips+=3; | 506 celt_mips+=3; |
507 return a; | 507 return a; |
508 } | 508 } |
509 | 509 |
510 static inline int MULT16_16_Q11_32(int a, int b) | 510 static OPUS_INLINE opus_int16 SATURATE16(opus_int32 a) |
| 511 { |
| 512 celt_mips+=3; |
| 513 if (a>32767) |
| 514 return 32767; |
| 515 else if (a<-32768) |
| 516 return -32768; |
| 517 else return a; |
| 518 } |
| 519 |
| 520 static OPUS_INLINE int MULT16_16_Q11_32(int a, int b) |
511 { | 521 { |
512 opus_int64 res; | 522 opus_int64 res; |
513 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 523 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
514 { | 524 { |
515 fprintf (stderr, "MULT16_16_Q11: inputs are not short: %d %d\n", a, b); | 525 fprintf (stderr, "MULT16_16_Q11: inputs are not short: %d %d\n", a, b); |
516 #ifdef FIXED_DEBUG_ASSERT | 526 #ifdef FIXED_DEBUG_ASSERT |
517 celt_assert(0); | 527 celt_assert(0); |
518 #endif | 528 #endif |
519 } | 529 } |
520 res = ((opus_int64)a)*b; | 530 res = ((opus_int64)a)*b; |
521 res >>= 11; | 531 res >>= 11; |
522 if (!VERIFY_INT(res)) | 532 if (!VERIFY_INT(res)) |
523 { | 533 { |
524 fprintf (stderr, "MULT16_16_Q11: output is not short: %d*%d=%d\n", (int)a,
(int)b, (int)res); | 534 fprintf (stderr, "MULT16_16_Q11: output is not short: %d*%d=%d\n", (int)a,
(int)b, (int)res); |
525 #ifdef FIXED_DEBUG_ASSERT | 535 #ifdef FIXED_DEBUG_ASSERT |
526 celt_assert(0); | 536 celt_assert(0); |
527 #endif | 537 #endif |
528 } | 538 } |
529 celt_mips+=3; | 539 celt_mips+=3; |
530 return res; | 540 return res; |
531 } | 541 } |
532 static inline short MULT16_16_Q13(int a, int b) | 542 static OPUS_INLINE short MULT16_16_Q13(int a, int b) |
533 { | 543 { |
534 opus_int64 res; | 544 opus_int64 res; |
535 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 545 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
536 { | 546 { |
537 fprintf (stderr, "MULT16_16_Q13: inputs are not short: %d %d\n", a, b); | 547 fprintf (stderr, "MULT16_16_Q13: inputs are not short: %d %d\n", a, b); |
538 #ifdef FIXED_DEBUG_ASSERT | 548 #ifdef FIXED_DEBUG_ASSERT |
539 celt_assert(0); | 549 celt_assert(0); |
540 #endif | 550 #endif |
541 } | 551 } |
542 res = ((opus_int64)a)*b; | 552 res = ((opus_int64)a)*b; |
543 res >>= 13; | 553 res >>= 13; |
544 if (!VERIFY_SHORT(res)) | 554 if (!VERIFY_SHORT(res)) |
545 { | 555 { |
546 fprintf (stderr, "MULT16_16_Q13: output is not short: %d*%d=%d\n", a, b, (
int)res); | 556 fprintf (stderr, "MULT16_16_Q13: output is not short: %d*%d=%d\n", a, b, (
int)res); |
547 #ifdef FIXED_DEBUG_ASSERT | 557 #ifdef FIXED_DEBUG_ASSERT |
548 celt_assert(0); | 558 celt_assert(0); |
549 #endif | 559 #endif |
550 } | 560 } |
551 celt_mips+=3; | 561 celt_mips+=3; |
552 return res; | 562 return res; |
553 } | 563 } |
554 static inline short MULT16_16_Q14(int a, int b) | 564 static OPUS_INLINE short MULT16_16_Q14(int a, int b) |
555 { | 565 { |
556 opus_int64 res; | 566 opus_int64 res; |
557 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 567 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
558 { | 568 { |
559 fprintf (stderr, "MULT16_16_Q14: inputs are not short: %d %d\n", a, b); | 569 fprintf (stderr, "MULT16_16_Q14: inputs are not short: %d %d\n", a, b); |
560 #ifdef FIXED_DEBUG_ASSERT | 570 #ifdef FIXED_DEBUG_ASSERT |
561 celt_assert(0); | 571 celt_assert(0); |
562 #endif | 572 #endif |
563 } | 573 } |
564 res = ((opus_int64)a)*b; | 574 res = ((opus_int64)a)*b; |
565 res >>= 14; | 575 res >>= 14; |
566 if (!VERIFY_SHORT(res)) | 576 if (!VERIFY_SHORT(res)) |
567 { | 577 { |
568 fprintf (stderr, "MULT16_16_Q14: output is not short: %d\n", (int)res); | 578 fprintf (stderr, "MULT16_16_Q14: output is not short: %d\n", (int)res); |
569 #ifdef FIXED_DEBUG_ASSERT | 579 #ifdef FIXED_DEBUG_ASSERT |
570 celt_assert(0); | 580 celt_assert(0); |
571 #endif | 581 #endif |
572 } | 582 } |
573 celt_mips+=3; | 583 celt_mips+=3; |
574 return res; | 584 return res; |
575 } | 585 } |
576 | 586 |
577 #define MULT16_16_Q15(a, b) MULT16_16_Q15_(a, b, __FILE__, __LINE__) | 587 #define MULT16_16_Q15(a, b) MULT16_16_Q15_(a, b, __FILE__, __LINE__) |
578 static inline short MULT16_16_Q15_(int a, int b, char *file, int line) | 588 static OPUS_INLINE short MULT16_16_Q15_(int a, int b, char *file, int line) |
579 { | 589 { |
580 opus_int64 res; | 590 opus_int64 res; |
581 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 591 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
582 { | 592 { |
583 fprintf (stderr, "MULT16_16_Q15: inputs are not short: %d %d in %s: line %
d\n", a, b, file, line); | 593 fprintf (stderr, "MULT16_16_Q15: inputs are not short: %d %d in %s: line %
d\n", a, b, file, line); |
584 #ifdef FIXED_DEBUG_ASSERT | 594 #ifdef FIXED_DEBUG_ASSERT |
585 celt_assert(0); | 595 celt_assert(0); |
586 #endif | 596 #endif |
587 } | 597 } |
588 res = ((opus_int64)a)*b; | 598 res = ((opus_int64)a)*b; |
589 res >>= 15; | 599 res >>= 15; |
590 if (!VERIFY_SHORT(res)) | 600 if (!VERIFY_SHORT(res)) |
591 { | 601 { |
592 fprintf (stderr, "MULT16_16_Q15: output is not short: %d in %s: line %d\n"
, (int)res, file, line); | 602 fprintf (stderr, "MULT16_16_Q15: output is not short: %d in %s: line %d\n"
, (int)res, file, line); |
593 #ifdef FIXED_DEBUG_ASSERT | 603 #ifdef FIXED_DEBUG_ASSERT |
594 celt_assert(0); | 604 celt_assert(0); |
595 #endif | 605 #endif |
596 } | 606 } |
597 celt_mips+=1; | 607 celt_mips+=1; |
598 return res; | 608 return res; |
599 } | 609 } |
600 | 610 |
601 static inline short MULT16_16_P13(int a, int b) | 611 static OPUS_INLINE short MULT16_16_P13(int a, int b) |
602 { | 612 { |
603 opus_int64 res; | 613 opus_int64 res; |
604 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 614 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
605 { | 615 { |
606 fprintf (stderr, "MULT16_16_P13: inputs are not short: %d %d\n", a, b); | 616 fprintf (stderr, "MULT16_16_P13: inputs are not short: %d %d\n", a, b); |
607 #ifdef FIXED_DEBUG_ASSERT | 617 #ifdef FIXED_DEBUG_ASSERT |
608 celt_assert(0); | 618 celt_assert(0); |
609 #endif | 619 #endif |
610 } | 620 } |
611 res = ((opus_int64)a)*b; | 621 res = ((opus_int64)a)*b; |
612 res += 4096; | 622 res += 4096; |
613 if (!VERIFY_INT(res)) | 623 if (!VERIFY_INT(res)) |
614 { | 624 { |
615 fprintf (stderr, "MULT16_16_P13: overflow: %d*%d=%d\n", a, b, (int)res); | 625 fprintf (stderr, "MULT16_16_P13: overflow: %d*%d=%d\n", a, b, (int)res); |
616 #ifdef FIXED_DEBUG_ASSERT | 626 #ifdef FIXED_DEBUG_ASSERT |
617 celt_assert(0); | 627 celt_assert(0); |
618 #endif | 628 #endif |
619 } | 629 } |
620 res >>= 13; | 630 res >>= 13; |
621 if (!VERIFY_SHORT(res)) | 631 if (!VERIFY_SHORT(res)) |
622 { | 632 { |
623 fprintf (stderr, "MULT16_16_P13: output is not short: %d*%d=%d\n", a, b, (
int)res); | 633 fprintf (stderr, "MULT16_16_P13: output is not short: %d*%d=%d\n", a, b, (
int)res); |
624 #ifdef FIXED_DEBUG_ASSERT | 634 #ifdef FIXED_DEBUG_ASSERT |
625 celt_assert(0); | 635 celt_assert(0); |
626 #endif | 636 #endif |
627 } | 637 } |
628 celt_mips+=4; | 638 celt_mips+=4; |
629 return res; | 639 return res; |
630 } | 640 } |
631 static inline short MULT16_16_P14(int a, int b) | 641 static OPUS_INLINE short MULT16_16_P14(int a, int b) |
632 { | 642 { |
633 opus_int64 res; | 643 opus_int64 res; |
634 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 644 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
635 { | 645 { |
636 fprintf (stderr, "MULT16_16_P14: inputs are not short: %d %d\n", a, b); | 646 fprintf (stderr, "MULT16_16_P14: inputs are not short: %d %d\n", a, b); |
637 #ifdef FIXED_DEBUG_ASSERT | 647 #ifdef FIXED_DEBUG_ASSERT |
638 celt_assert(0); | 648 celt_assert(0); |
639 #endif | 649 #endif |
640 } | 650 } |
641 res = ((opus_int64)a)*b; | 651 res = ((opus_int64)a)*b; |
642 res += 8192; | 652 res += 8192; |
643 if (!VERIFY_INT(res)) | 653 if (!VERIFY_INT(res)) |
644 { | 654 { |
645 fprintf (stderr, "MULT16_16_P14: overflow: %d*%d=%d\n", a, b, (int)res); | 655 fprintf (stderr, "MULT16_16_P14: overflow: %d*%d=%d\n", a, b, (int)res); |
646 #ifdef FIXED_DEBUG_ASSERT | 656 #ifdef FIXED_DEBUG_ASSERT |
647 celt_assert(0); | 657 celt_assert(0); |
648 #endif | 658 #endif |
649 } | 659 } |
650 res >>= 14; | 660 res >>= 14; |
651 if (!VERIFY_SHORT(res)) | 661 if (!VERIFY_SHORT(res)) |
652 { | 662 { |
653 fprintf (stderr, "MULT16_16_P14: output is not short: %d*%d=%d\n", a, b, (
int)res); | 663 fprintf (stderr, "MULT16_16_P14: output is not short: %d*%d=%d\n", a, b, (
int)res); |
654 #ifdef FIXED_DEBUG_ASSERT | 664 #ifdef FIXED_DEBUG_ASSERT |
655 celt_assert(0); | 665 celt_assert(0); |
656 #endif | 666 #endif |
657 } | 667 } |
658 celt_mips+=4; | 668 celt_mips+=4; |
659 return res; | 669 return res; |
660 } | 670 } |
661 static inline short MULT16_16_P15(int a, int b) | 671 static OPUS_INLINE short MULT16_16_P15(int a, int b) |
662 { | 672 { |
663 opus_int64 res; | 673 opus_int64 res; |
664 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 674 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
665 { | 675 { |
666 fprintf (stderr, "MULT16_16_P15: inputs are not short: %d %d\n", a, b); | 676 fprintf (stderr, "MULT16_16_P15: inputs are not short: %d %d\n", a, b); |
667 #ifdef FIXED_DEBUG_ASSERT | 677 #ifdef FIXED_DEBUG_ASSERT |
668 celt_assert(0); | 678 celt_assert(0); |
669 #endif | 679 #endif |
670 } | 680 } |
671 res = ((opus_int64)a)*b; | 681 res = ((opus_int64)a)*b; |
(...skipping 12 matching lines...) Expand all Loading... |
684 #ifdef FIXED_DEBUG_ASSERT | 694 #ifdef FIXED_DEBUG_ASSERT |
685 celt_assert(0); | 695 celt_assert(0); |
686 #endif | 696 #endif |
687 } | 697 } |
688 celt_mips+=2; | 698 celt_mips+=2; |
689 return res; | 699 return res; |
690 } | 700 } |
691 | 701 |
692 #define DIV32_16(a, b) DIV32_16_(a, b, __FILE__, __LINE__) | 702 #define DIV32_16(a, b) DIV32_16_(a, b, __FILE__, __LINE__) |
693 | 703 |
694 static inline int DIV32_16_(opus_int64 a, opus_int64 b, char *file, int line) | 704 static OPUS_INLINE int DIV32_16_(opus_int64 a, opus_int64 b, char *file, int lin
e) |
695 { | 705 { |
696 opus_int64 res; | 706 opus_int64 res; |
697 if (b==0) | 707 if (b==0) |
698 { | 708 { |
699 fprintf(stderr, "DIV32_16: divide by zero: %d/%d in %s: line %d\n", (int)a
, (int)b, file, line); | 709 fprintf(stderr, "DIV32_16: divide by zero: %d/%d in %s: line %d\n", (int)a
, (int)b, file, line); |
700 #ifdef FIXED_DEBUG_ASSERT | 710 #ifdef FIXED_DEBUG_ASSERT |
701 celt_assert(0); | 711 celt_assert(0); |
702 #endif | 712 #endif |
703 return 0; | 713 return 0; |
704 } | 714 } |
(...skipping 14 matching lines...) Expand all Loading... |
719 res = -32768; | 729 res = -32768; |
720 #ifdef FIXED_DEBUG_ASSERT | 730 #ifdef FIXED_DEBUG_ASSERT |
721 celt_assert(0); | 731 celt_assert(0); |
722 #endif | 732 #endif |
723 } | 733 } |
724 celt_mips+=35; | 734 celt_mips+=35; |
725 return res; | 735 return res; |
726 } | 736 } |
727 | 737 |
728 #define DIV32(a, b) DIV32_(a, b, __FILE__, __LINE__) | 738 #define DIV32(a, b) DIV32_(a, b, __FILE__, __LINE__) |
729 static inline int DIV32_(opus_int64 a, opus_int64 b, char *file, int line) | 739 static OPUS_INLINE int DIV32_(opus_int64 a, opus_int64 b, char *file, int line) |
730 { | 740 { |
731 opus_int64 res; | 741 opus_int64 res; |
732 if (b==0) | 742 if (b==0) |
733 { | 743 { |
734 fprintf(stderr, "DIV32: divide by zero: %d/%d in %s: line %d\n", (int)a, (
int)b, file, line); | 744 fprintf(stderr, "DIV32: divide by zero: %d/%d in %s: line %d\n", (int)a, (
int)b, file, line); |
735 #ifdef FIXED_DEBUG_ASSERT | 745 #ifdef FIXED_DEBUG_ASSERT |
736 celt_assert(0); | 746 celt_assert(0); |
737 #endif | 747 #endif |
738 return 0; | 748 return 0; |
739 } | 749 } |
(...skipping 14 matching lines...) Expand all Loading... |
754 #endif | 764 #endif |
755 } | 765 } |
756 celt_mips+=70; | 766 celt_mips+=70; |
757 return res; | 767 return res; |
758 } | 768 } |
759 | 769 |
760 #undef PRINT_MIPS | 770 #undef PRINT_MIPS |
761 #define PRINT_MIPS(file) do {fprintf (file, "total complexity = %llu MIPS\n", ce
lt_mips);} while (0); | 771 #define PRINT_MIPS(file) do {fprintf (file, "total complexity = %llu MIPS\n", ce
lt_mips);} while (0); |
762 | 772 |
763 #endif | 773 #endif |
OLD | NEW |