1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/celt/fixed_debug.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,773 @@ 1.4 +/* Copyright (C) 2003-2008 Jean-Marc Valin 1.5 + Copyright (C) 2007-2012 Xiph.Org Foundation */ 1.6 +/** 1.7 + @file fixed_debug.h 1.8 + @brief Fixed-point operations with debugging 1.9 +*/ 1.10 +/* 1.11 + Redistribution and use in source and binary forms, with or without 1.12 + modification, are permitted provided that the following conditions 1.13 + are met: 1.14 + 1.15 + - Redistributions of source code must retain the above copyright 1.16 + notice, this list of conditions and the following disclaimer. 1.17 + 1.18 + - Redistributions in binary form must reproduce the above copyright 1.19 + notice, this list of conditions and the following disclaimer in the 1.20 + documentation and/or other materials provided with the distribution. 1.21 + 1.22 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.23 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.24 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.25 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 1.26 + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.27 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.28 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.29 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.30 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.31 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.32 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.33 +*/ 1.34 + 1.35 +#ifndef FIXED_DEBUG_H 1.36 +#define FIXED_DEBUG_H 1.37 + 1.38 +#include <stdio.h> 1.39 +#include "opus_defines.h" 1.40 + 1.41 +#ifdef CELT_C 1.42 +OPUS_EXPORT opus_int64 celt_mips=0; 1.43 +#else 1.44 +extern opus_int64 celt_mips; 1.45 +#endif 1.46 + 1.47 +#define MULT16_16SU(a,b) ((opus_val32)(opus_val16)(a)*(opus_val32)(opus_uint16)(b)) 1.48 +#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)) 1.49 + 1.50 +/** 16x32 multiplication, followed by a 16-bit shift right. Results fits in 32 bits */ 1.51 +#define MULT16_32_Q16(a,b) ADD32(MULT16_16((a),SHR32((b),16)), SHR32(MULT16_16SU((a),((b)&0x0000ffff)),16)) 1.52 + 1.53 +#define MULT16_32_P16(a,b) MULT16_32_PX(a,b,16) 1.54 + 1.55 +#define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits)))) 1.56 +#define QCONST32(x,bits) ((opus_val32)(.5+(x)*(((opus_val32)1)<<(bits)))) 1.57 + 1.58 +#define VERIFY_SHORT(x) ((x)<=32767&&(x)>=-32768) 1.59 +#define VERIFY_INT(x) ((x)<=2147483647LL&&(x)>=-2147483648LL) 1.60 +#define VERIFY_UINT(x) ((x)<=(2147483647LLU<<1)) 1.61 + 1.62 +#define SHR(a,b) SHR32(a,b) 1.63 +#define PSHR(a,b) PSHR32(a,b) 1.64 + 1.65 +static OPUS_INLINE short NEG16(int x) 1.66 +{ 1.67 + int res; 1.68 + if (!VERIFY_SHORT(x)) 1.69 + { 1.70 + fprintf (stderr, "NEG16: input is not short: %d\n", (int)x); 1.71 +#ifdef FIXED_DEBUG_ASSERT 1.72 + celt_assert(0); 1.73 +#endif 1.74 + } 1.75 + res = -x; 1.76 + if (!VERIFY_SHORT(res)) 1.77 + { 1.78 + fprintf (stderr, "NEG16: output is not short: %d\n", (int)res); 1.79 +#ifdef FIXED_DEBUG_ASSERT 1.80 + celt_assert(0); 1.81 +#endif 1.82 + } 1.83 + celt_mips++; 1.84 + return res; 1.85 +} 1.86 +static OPUS_INLINE int NEG32(opus_int64 x) 1.87 +{ 1.88 + opus_int64 res; 1.89 + if (!VERIFY_INT(x)) 1.90 + { 1.91 + fprintf (stderr, "NEG16: input is not int: %d\n", (int)x); 1.92 +#ifdef FIXED_DEBUG_ASSERT 1.93 + celt_assert(0); 1.94 +#endif 1.95 + } 1.96 + res = -x; 1.97 + if (!VERIFY_INT(res)) 1.98 + { 1.99 + fprintf (stderr, "NEG16: output is not int: %d\n", (int)res); 1.100 +#ifdef FIXED_DEBUG_ASSERT 1.101 + celt_assert(0); 1.102 +#endif 1.103 + } 1.104 + celt_mips+=2; 1.105 + return res; 1.106 +} 1.107 + 1.108 +#define EXTRACT16(x) EXTRACT16_(x, __FILE__, __LINE__) 1.109 +static OPUS_INLINE short EXTRACT16_(int x, char *file, int line) 1.110 +{ 1.111 + int res; 1.112 + if (!VERIFY_SHORT(x)) 1.113 + { 1.114 + fprintf (stderr, "EXTRACT16: input is not short: %d in %s: line %d\n", x, file, line); 1.115 +#ifdef FIXED_DEBUG_ASSERT 1.116 + celt_assert(0); 1.117 +#endif 1.118 + } 1.119 + res = x; 1.120 + celt_mips++; 1.121 + return res; 1.122 +} 1.123 + 1.124 +#define EXTEND32(x) EXTEND32_(x, __FILE__, __LINE__) 1.125 +static OPUS_INLINE int EXTEND32_(int x, char *file, int line) 1.126 +{ 1.127 + int res; 1.128 + if (!VERIFY_SHORT(x)) 1.129 + { 1.130 + fprintf (stderr, "EXTEND32: input is not short: %d in %s: line %d\n", x, file, line); 1.131 +#ifdef FIXED_DEBUG_ASSERT 1.132 + celt_assert(0); 1.133 +#endif 1.134 + } 1.135 + res = x; 1.136 + celt_mips++; 1.137 + return res; 1.138 +} 1.139 + 1.140 +#define SHR16(a, shift) SHR16_(a, shift, __FILE__, __LINE__) 1.141 +static OPUS_INLINE short SHR16_(int a, int shift, char *file, int line) 1.142 +{ 1.143 + int res; 1.144 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift)) 1.145 + { 1.146 + fprintf (stderr, "SHR16: inputs are not short: %d >> %d in %s: line %d\n", a, shift, file, line); 1.147 +#ifdef FIXED_DEBUG_ASSERT 1.148 + celt_assert(0); 1.149 +#endif 1.150 + } 1.151 + res = a>>shift; 1.152 + if (!VERIFY_SHORT(res)) 1.153 + { 1.154 + fprintf (stderr, "SHR16: output is not short: %d in %s: line %d\n", res, file, line); 1.155 +#ifdef FIXED_DEBUG_ASSERT 1.156 + celt_assert(0); 1.157 +#endif 1.158 + } 1.159 + celt_mips++; 1.160 + return res; 1.161 +} 1.162 +#define SHL16(a, shift) SHL16_(a, shift, __FILE__, __LINE__) 1.163 +static OPUS_INLINE short SHL16_(int a, int shift, char *file, int line) 1.164 +{ 1.165 + int res; 1.166 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift)) 1.167 + { 1.168 + fprintf (stderr, "SHL16: inputs are not short: %d %d in %s: line %d\n", a, shift, file, line); 1.169 +#ifdef FIXED_DEBUG_ASSERT 1.170 + celt_assert(0); 1.171 +#endif 1.172 + } 1.173 + res = a<<shift; 1.174 + if (!VERIFY_SHORT(res)) 1.175 + { 1.176 + fprintf (stderr, "SHL16: output is not short: %d in %s: line %d\n", res, file, line); 1.177 +#ifdef FIXED_DEBUG_ASSERT 1.178 + celt_assert(0); 1.179 +#endif 1.180 + } 1.181 + celt_mips++; 1.182 + return res; 1.183 +} 1.184 + 1.185 +static OPUS_INLINE int SHR32(opus_int64 a, int shift) 1.186 +{ 1.187 + opus_int64 res; 1.188 + if (!VERIFY_INT(a) || !VERIFY_SHORT(shift)) 1.189 + { 1.190 + fprintf (stderr, "SHR32: inputs are not int: %d %d\n", (int)a, shift); 1.191 +#ifdef FIXED_DEBUG_ASSERT 1.192 + celt_assert(0); 1.193 +#endif 1.194 + } 1.195 + res = a>>shift; 1.196 + if (!VERIFY_INT(res)) 1.197 + { 1.198 + fprintf (stderr, "SHR32: output is not int: %d\n", (int)res); 1.199 +#ifdef FIXED_DEBUG_ASSERT 1.200 + celt_assert(0); 1.201 +#endif 1.202 + } 1.203 + celt_mips+=2; 1.204 + return res; 1.205 +} 1.206 +#define SHL32(a, shift) SHL32_(a, shift, __FILE__, __LINE__) 1.207 +static OPUS_INLINE int SHL32_(opus_int64 a, int shift, char *file, int line) 1.208 +{ 1.209 + opus_int64 res; 1.210 + if (!VERIFY_INT(a) || !VERIFY_SHORT(shift)) 1.211 + { 1.212 + fprintf (stderr, "SHL32: inputs are not int: %lld %d in %s: line %d\n", a, shift, file, line); 1.213 +#ifdef FIXED_DEBUG_ASSERT 1.214 + celt_assert(0); 1.215 +#endif 1.216 + } 1.217 + res = a<<shift; 1.218 + if (!VERIFY_INT(res)) 1.219 + { 1.220 + fprintf (stderr, "SHL32: output is not int: %lld<<%d = %lld in %s: line %d\n", a, shift, res, file, line); 1.221 +#ifdef FIXED_DEBUG_ASSERT 1.222 + celt_assert(0); 1.223 +#endif 1.224 + } 1.225 + celt_mips+=2; 1.226 + return res; 1.227 +} 1.228 + 1.229 +#define PSHR32(a,shift) (celt_mips--,SHR32(ADD32((a),(((opus_val32)(1)<<((shift))>>1))),shift)) 1.230 +#define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) 1.231 + 1.232 +#define ROUND16(x,a) (celt_mips--,EXTRACT16(PSHR32((x),(a)))) 1.233 +#define HALF16(x) (SHR16(x,1)) 1.234 +#define HALF32(x) (SHR32(x,1)) 1.235 + 1.236 +//#define SHR(a,shift) ((a) >> (shift)) 1.237 +//#define SHL(a,shift) ((a) << (shift)) 1.238 + 1.239 +#define ADD16(a, b) ADD16_(a, b, __FILE__, __LINE__) 1.240 +static OPUS_INLINE short ADD16_(int a, int b, char *file, int line) 1.241 +{ 1.242 + int res; 1.243 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) 1.244 + { 1.245 + fprintf (stderr, "ADD16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); 1.246 +#ifdef FIXED_DEBUG_ASSERT 1.247 + celt_assert(0); 1.248 +#endif 1.249 + } 1.250 + res = a+b; 1.251 + if (!VERIFY_SHORT(res)) 1.252 + { 1.253 + fprintf (stderr, "ADD16: output is not short: %d+%d=%d in %s: line %d\n", a,b,res, file, line); 1.254 +#ifdef FIXED_DEBUG_ASSERT 1.255 + celt_assert(0); 1.256 +#endif 1.257 + } 1.258 + celt_mips++; 1.259 + return res; 1.260 +} 1.261 + 1.262 +#define SUB16(a, b) SUB16_(a, b, __FILE__, __LINE__) 1.263 +static OPUS_INLINE short SUB16_(int a, int b, char *file, int line) 1.264 +{ 1.265 + int res; 1.266 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) 1.267 + { 1.268 + fprintf (stderr, "SUB16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); 1.269 +#ifdef FIXED_DEBUG_ASSERT 1.270 + celt_assert(0); 1.271 +#endif 1.272 + } 1.273 + res = a-b; 1.274 + if (!VERIFY_SHORT(res)) 1.275 + { 1.276 + fprintf (stderr, "SUB16: output is not short: %d in %s: line %d\n", res, file, line); 1.277 +#ifdef FIXED_DEBUG_ASSERT 1.278 + celt_assert(0); 1.279 +#endif 1.280 + } 1.281 + celt_mips++; 1.282 + return res; 1.283 +} 1.284 + 1.285 +#define ADD32(a, b) ADD32_(a, b, __FILE__, __LINE__) 1.286 +static OPUS_INLINE int ADD32_(opus_int64 a, opus_int64 b, char *file, int line) 1.287 +{ 1.288 + opus_int64 res; 1.289 + if (!VERIFY_INT(a) || !VERIFY_INT(b)) 1.290 + { 1.291 + fprintf (stderr, "ADD32: inputs are not int: %d %d in %s: line %d\n", (int)a, (int)b, file, line); 1.292 +#ifdef FIXED_DEBUG_ASSERT 1.293 + celt_assert(0); 1.294 +#endif 1.295 + } 1.296 + res = a+b; 1.297 + if (!VERIFY_INT(res)) 1.298 + { 1.299 + fprintf (stderr, "ADD32: output is not int: %d in %s: line %d\n", (int)res, file, line); 1.300 +#ifdef FIXED_DEBUG_ASSERT 1.301 + celt_assert(0); 1.302 +#endif 1.303 + } 1.304 + celt_mips+=2; 1.305 + return res; 1.306 +} 1.307 + 1.308 +#define SUB32(a, b) SUB32_(a, b, __FILE__, __LINE__) 1.309 +static OPUS_INLINE int SUB32_(opus_int64 a, opus_int64 b, char *file, int line) 1.310 +{ 1.311 + opus_int64 res; 1.312 + if (!VERIFY_INT(a) || !VERIFY_INT(b)) 1.313 + { 1.314 + fprintf (stderr, "SUB32: inputs are not int: %d %d in %s: line %d\n", (int)a, (int)b, file, line); 1.315 +#ifdef FIXED_DEBUG_ASSERT 1.316 + celt_assert(0); 1.317 +#endif 1.318 + } 1.319 + res = a-b; 1.320 + if (!VERIFY_INT(res)) 1.321 + { 1.322 + fprintf (stderr, "SUB32: output is not int: %d in %s: line %d\n", (int)res, file, line); 1.323 +#ifdef FIXED_DEBUG_ASSERT 1.324 + celt_assert(0); 1.325 +#endif 1.326 + } 1.327 + celt_mips+=2; 1.328 + return res; 1.329 +} 1.330 + 1.331 +#undef UADD32 1.332 +#define UADD32(a, b) UADD32_(a, b, __FILE__, __LINE__) 1.333 +static OPUS_INLINE unsigned int UADD32_(opus_uint64 a, opus_uint64 b, char *file, int line) 1.334 +{ 1.335 + opus_uint64 res; 1.336 + if (!VERIFY_UINT(a) || !VERIFY_UINT(b)) 1.337 + { 1.338 + fprintf (stderr, "UADD32: inputs are not uint32: %llu %llu in %s: line %d\n", a, b, file, line); 1.339 +#ifdef FIXED_DEBUG_ASSERT 1.340 + celt_assert(0); 1.341 +#endif 1.342 + } 1.343 + res = a+b; 1.344 + if (!VERIFY_UINT(res)) 1.345 + { 1.346 + fprintf (stderr, "UADD32: output is not uint32: %llu in %s: line %d\n", res, file, line); 1.347 +#ifdef FIXED_DEBUG_ASSERT 1.348 + celt_assert(0); 1.349 +#endif 1.350 + } 1.351 + celt_mips+=2; 1.352 + return res; 1.353 +} 1.354 + 1.355 +#undef USUB32 1.356 +#define USUB32(a, b) USUB32_(a, b, __FILE__, __LINE__) 1.357 +static OPUS_INLINE unsigned int USUB32_(opus_uint64 a, opus_uint64 b, char *file, int line) 1.358 +{ 1.359 + opus_uint64 res; 1.360 + if (!VERIFY_UINT(a) || !VERIFY_UINT(b)) 1.361 + { 1.362 + fprintf (stderr, "USUB32: inputs are not uint32: %llu %llu in %s: line %d\n", a, b, file, line); 1.363 +#ifdef FIXED_DEBUG_ASSERT 1.364 + celt_assert(0); 1.365 +#endif 1.366 + } 1.367 + if (a<b) 1.368 + { 1.369 + fprintf (stderr, "USUB32: inputs underflow: %llu < %llu in %s: line %d\n", a, b, file, line); 1.370 +#ifdef FIXED_DEBUG_ASSERT 1.371 + celt_assert(0); 1.372 +#endif 1.373 + } 1.374 + res = a-b; 1.375 + if (!VERIFY_UINT(res)) 1.376 + { 1.377 + fprintf (stderr, "USUB32: output is not uint32: %llu - %llu = %llu in %s: line %d\n", a, b, res, file, line); 1.378 +#ifdef FIXED_DEBUG_ASSERT 1.379 + celt_assert(0); 1.380 +#endif 1.381 + } 1.382 + celt_mips+=2; 1.383 + return res; 1.384 +} 1.385 + 1.386 +/* result fits in 16 bits */ 1.387 +static OPUS_INLINE short MULT16_16_16(int a, int b) 1.388 +{ 1.389 + int res; 1.390 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) 1.391 + { 1.392 + fprintf (stderr, "MULT16_16_16: inputs are not short: %d %d\n", a, b); 1.393 +#ifdef FIXED_DEBUG_ASSERT 1.394 + celt_assert(0); 1.395 +#endif 1.396 + } 1.397 + res = a*b; 1.398 + if (!VERIFY_SHORT(res)) 1.399 + { 1.400 + fprintf (stderr, "MULT16_16_16: output is not short: %d\n", res); 1.401 +#ifdef FIXED_DEBUG_ASSERT 1.402 + celt_assert(0); 1.403 +#endif 1.404 + } 1.405 + celt_mips++; 1.406 + return res; 1.407 +} 1.408 + 1.409 +#define MULT16_16(a, b) MULT16_16_(a, b, __FILE__, __LINE__) 1.410 +static OPUS_INLINE int MULT16_16_(int a, int b, char *file, int line) 1.411 +{ 1.412 + opus_int64 res; 1.413 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) 1.414 + { 1.415 + fprintf (stderr, "MULT16_16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); 1.416 +#ifdef FIXED_DEBUG_ASSERT 1.417 + celt_assert(0); 1.418 +#endif 1.419 + } 1.420 + res = ((opus_int64)a)*b; 1.421 + if (!VERIFY_INT(res)) 1.422 + { 1.423 + fprintf (stderr, "MULT16_16: output is not int: %d in %s: line %d\n", (int)res, file, line); 1.424 +#ifdef FIXED_DEBUG_ASSERT 1.425 + celt_assert(0); 1.426 +#endif 1.427 + } 1.428 + celt_mips++; 1.429 + return res; 1.430 +} 1.431 + 1.432 +#define MAC16_16(c,a,b) (celt_mips-=2,ADD32((c),MULT16_16((a),(b)))) 1.433 + 1.434 +#define MULT16_32_QX(a, b, Q) MULT16_32_QX_(a, b, Q, __FILE__, __LINE__) 1.435 +static OPUS_INLINE int MULT16_32_QX_(int a, opus_int64 b, int Q, char *file, int line) 1.436 +{ 1.437 + opus_int64 res; 1.438 + if (!VERIFY_SHORT(a) || !VERIFY_INT(b)) 1.439 + { 1.440 + fprintf (stderr, "MULT16_32_Q%d: inputs are not short+int: %d %d in %s: line %d\n", Q, (int)a, (int)b, file, line); 1.441 +#ifdef FIXED_DEBUG_ASSERT 1.442 + celt_assert(0); 1.443 +#endif 1.444 + } 1.445 + if (ABS32(b)>=((opus_val32)(1)<<(15+Q))) 1.446 + { 1.447 + fprintf (stderr, "MULT16_32_Q%d: second operand too large: %d %d in %s: line %d\n", Q, (int)a, (int)b, file, line); 1.448 +#ifdef FIXED_DEBUG_ASSERT 1.449 + celt_assert(0); 1.450 +#endif 1.451 + } 1.452 + res = (((opus_int64)a)*(opus_int64)b) >> Q; 1.453 + if (!VERIFY_INT(res)) 1.454 + { 1.455 + fprintf (stderr, "MULT16_32_Q%d: output is not int: %d*%d=%d in %s: line %d\n", Q, (int)a, (int)b,(int)res, file, line); 1.456 +#ifdef FIXED_DEBUG_ASSERT 1.457 + celt_assert(0); 1.458 +#endif 1.459 + } 1.460 + if (Q==15) 1.461 + celt_mips+=3; 1.462 + else 1.463 + celt_mips+=4; 1.464 + return res; 1.465 +} 1.466 + 1.467 +#define MULT16_32_PX(a, b, Q) MULT16_32_PX_(a, b, Q, __FILE__, __LINE__) 1.468 +static OPUS_INLINE int MULT16_32_PX_(int a, opus_int64 b, int Q, char *file, int line) 1.469 +{ 1.470 + opus_int64 res; 1.471 + if (!VERIFY_SHORT(a) || !VERIFY_INT(b)) 1.472 + { 1.473 + fprintf (stderr, "MULT16_32_P%d: inputs are not short+int: %d %d in %s: line %d\n\n", Q, (int)a, (int)b, file, line); 1.474 +#ifdef FIXED_DEBUG_ASSERT 1.475 + celt_assert(0); 1.476 +#endif 1.477 + } 1.478 + if (ABS32(b)>=((opus_int64)(1)<<(15+Q))) 1.479 + { 1.480 + fprintf (stderr, "MULT16_32_Q%d: second operand too large: %d %d in %s: line %d\n\n", Q, (int)a, (int)b,file, line); 1.481 +#ifdef FIXED_DEBUG_ASSERT 1.482 + celt_assert(0); 1.483 +#endif 1.484 + } 1.485 + res = ((((opus_int64)a)*(opus_int64)b) + (((opus_val32)(1)<<Q)>>1))>> Q; 1.486 + if (!VERIFY_INT(res)) 1.487 + { 1.488 + fprintf (stderr, "MULT16_32_P%d: output is not int: %d*%d=%d in %s: line %d\n\n", Q, (int)a, (int)b,(int)res, file, line); 1.489 +#ifdef FIXED_DEBUG_ASSERT 1.490 + celt_assert(0); 1.491 +#endif 1.492 + } 1.493 + if (Q==15) 1.494 + celt_mips+=4; 1.495 + else 1.496 + celt_mips+=5; 1.497 + return res; 1.498 +} 1.499 + 1.500 +#define MULT16_32_Q15(a,b) MULT16_32_QX(a,b,15) 1.501 +#define MAC16_32_Q15(c,a,b) (celt_mips-=2,ADD32((c),MULT16_32_Q15((a),(b)))) 1.502 + 1.503 +static OPUS_INLINE int SATURATE(int a, int b) 1.504 +{ 1.505 + if (a>b) 1.506 + a=b; 1.507 + if (a<-b) 1.508 + a = -b; 1.509 + celt_mips+=3; 1.510 + return a; 1.511 +} 1.512 + 1.513 +static OPUS_INLINE opus_int16 SATURATE16(opus_int32 a) 1.514 +{ 1.515 + celt_mips+=3; 1.516 + if (a>32767) 1.517 + return 32767; 1.518 + else if (a<-32768) 1.519 + return -32768; 1.520 + else return a; 1.521 +} 1.522 + 1.523 +static OPUS_INLINE int MULT16_16_Q11_32(int a, int b) 1.524 +{ 1.525 + opus_int64 res; 1.526 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) 1.527 + { 1.528 + fprintf (stderr, "MULT16_16_Q11: inputs are not short: %d %d\n", a, b); 1.529 +#ifdef FIXED_DEBUG_ASSERT 1.530 + celt_assert(0); 1.531 +#endif 1.532 + } 1.533 + res = ((opus_int64)a)*b; 1.534 + res >>= 11; 1.535 + if (!VERIFY_INT(res)) 1.536 + { 1.537 + fprintf (stderr, "MULT16_16_Q11: output is not short: %d*%d=%d\n", (int)a, (int)b, (int)res); 1.538 +#ifdef FIXED_DEBUG_ASSERT 1.539 + celt_assert(0); 1.540 +#endif 1.541 + } 1.542 + celt_mips+=3; 1.543 + return res; 1.544 +} 1.545 +static OPUS_INLINE short MULT16_16_Q13(int a, int b) 1.546 +{ 1.547 + opus_int64 res; 1.548 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) 1.549 + { 1.550 + fprintf (stderr, "MULT16_16_Q13: inputs are not short: %d %d\n", a, b); 1.551 +#ifdef FIXED_DEBUG_ASSERT 1.552 + celt_assert(0); 1.553 +#endif 1.554 + } 1.555 + res = ((opus_int64)a)*b; 1.556 + res >>= 13; 1.557 + if (!VERIFY_SHORT(res)) 1.558 + { 1.559 + fprintf (stderr, "MULT16_16_Q13: output is not short: %d*%d=%d\n", a, b, (int)res); 1.560 +#ifdef FIXED_DEBUG_ASSERT 1.561 + celt_assert(0); 1.562 +#endif 1.563 + } 1.564 + celt_mips+=3; 1.565 + return res; 1.566 +} 1.567 +static OPUS_INLINE short MULT16_16_Q14(int a, int b) 1.568 +{ 1.569 + opus_int64 res; 1.570 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) 1.571 + { 1.572 + fprintf (stderr, "MULT16_16_Q14: inputs are not short: %d %d\n", a, b); 1.573 +#ifdef FIXED_DEBUG_ASSERT 1.574 + celt_assert(0); 1.575 +#endif 1.576 + } 1.577 + res = ((opus_int64)a)*b; 1.578 + res >>= 14; 1.579 + if (!VERIFY_SHORT(res)) 1.580 + { 1.581 + fprintf (stderr, "MULT16_16_Q14: output is not short: %d\n", (int)res); 1.582 +#ifdef FIXED_DEBUG_ASSERT 1.583 + celt_assert(0); 1.584 +#endif 1.585 + } 1.586 + celt_mips+=3; 1.587 + return res; 1.588 +} 1.589 + 1.590 +#define MULT16_16_Q15(a, b) MULT16_16_Q15_(a, b, __FILE__, __LINE__) 1.591 +static OPUS_INLINE short MULT16_16_Q15_(int a, int b, char *file, int line) 1.592 +{ 1.593 + opus_int64 res; 1.594 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) 1.595 + { 1.596 + fprintf (stderr, "MULT16_16_Q15: inputs are not short: %d %d in %s: line %d\n", a, b, file, line); 1.597 +#ifdef FIXED_DEBUG_ASSERT 1.598 + celt_assert(0); 1.599 +#endif 1.600 + } 1.601 + res = ((opus_int64)a)*b; 1.602 + res >>= 15; 1.603 + if (!VERIFY_SHORT(res)) 1.604 + { 1.605 + fprintf (stderr, "MULT16_16_Q15: output is not short: %d in %s: line %d\n", (int)res, file, line); 1.606 +#ifdef FIXED_DEBUG_ASSERT 1.607 + celt_assert(0); 1.608 +#endif 1.609 + } 1.610 + celt_mips+=1; 1.611 + return res; 1.612 +} 1.613 + 1.614 +static OPUS_INLINE short MULT16_16_P13(int a, int b) 1.615 +{ 1.616 + opus_int64 res; 1.617 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) 1.618 + { 1.619 + fprintf (stderr, "MULT16_16_P13: inputs are not short: %d %d\n", a, b); 1.620 +#ifdef FIXED_DEBUG_ASSERT 1.621 + celt_assert(0); 1.622 +#endif 1.623 + } 1.624 + res = ((opus_int64)a)*b; 1.625 + res += 4096; 1.626 + if (!VERIFY_INT(res)) 1.627 + { 1.628 + fprintf (stderr, "MULT16_16_P13: overflow: %d*%d=%d\n", a, b, (int)res); 1.629 +#ifdef FIXED_DEBUG_ASSERT 1.630 + celt_assert(0); 1.631 +#endif 1.632 + } 1.633 + res >>= 13; 1.634 + if (!VERIFY_SHORT(res)) 1.635 + { 1.636 + fprintf (stderr, "MULT16_16_P13: output is not short: %d*%d=%d\n", a, b, (int)res); 1.637 +#ifdef FIXED_DEBUG_ASSERT 1.638 + celt_assert(0); 1.639 +#endif 1.640 + } 1.641 + celt_mips+=4; 1.642 + return res; 1.643 +} 1.644 +static OPUS_INLINE short MULT16_16_P14(int a, int b) 1.645 +{ 1.646 + opus_int64 res; 1.647 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) 1.648 + { 1.649 + fprintf (stderr, "MULT16_16_P14: inputs are not short: %d %d\n", a, b); 1.650 +#ifdef FIXED_DEBUG_ASSERT 1.651 + celt_assert(0); 1.652 +#endif 1.653 + } 1.654 + res = ((opus_int64)a)*b; 1.655 + res += 8192; 1.656 + if (!VERIFY_INT(res)) 1.657 + { 1.658 + fprintf (stderr, "MULT16_16_P14: overflow: %d*%d=%d\n", a, b, (int)res); 1.659 +#ifdef FIXED_DEBUG_ASSERT 1.660 + celt_assert(0); 1.661 +#endif 1.662 + } 1.663 + res >>= 14; 1.664 + if (!VERIFY_SHORT(res)) 1.665 + { 1.666 + fprintf (stderr, "MULT16_16_P14: output is not short: %d*%d=%d\n", a, b, (int)res); 1.667 +#ifdef FIXED_DEBUG_ASSERT 1.668 + celt_assert(0); 1.669 +#endif 1.670 + } 1.671 + celt_mips+=4; 1.672 + return res; 1.673 +} 1.674 +static OPUS_INLINE short MULT16_16_P15(int a, int b) 1.675 +{ 1.676 + opus_int64 res; 1.677 + if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) 1.678 + { 1.679 + fprintf (stderr, "MULT16_16_P15: inputs are not short: %d %d\n", a, b); 1.680 +#ifdef FIXED_DEBUG_ASSERT 1.681 + celt_assert(0); 1.682 +#endif 1.683 + } 1.684 + res = ((opus_int64)a)*b; 1.685 + res += 16384; 1.686 + if (!VERIFY_INT(res)) 1.687 + { 1.688 + fprintf (stderr, "MULT16_16_P15: overflow: %d*%d=%d\n", a, b, (int)res); 1.689 +#ifdef FIXED_DEBUG_ASSERT 1.690 + celt_assert(0); 1.691 +#endif 1.692 + } 1.693 + res >>= 15; 1.694 + if (!VERIFY_SHORT(res)) 1.695 + { 1.696 + fprintf (stderr, "MULT16_16_P15: output is not short: %d*%d=%d\n", a, b, (int)res); 1.697 +#ifdef FIXED_DEBUG_ASSERT 1.698 + celt_assert(0); 1.699 +#endif 1.700 + } 1.701 + celt_mips+=2; 1.702 + return res; 1.703 +} 1.704 + 1.705 +#define DIV32_16(a, b) DIV32_16_(a, b, __FILE__, __LINE__) 1.706 + 1.707 +static OPUS_INLINE int DIV32_16_(opus_int64 a, opus_int64 b, char *file, int line) 1.708 +{ 1.709 + opus_int64 res; 1.710 + if (b==0) 1.711 + { 1.712 + fprintf(stderr, "DIV32_16: divide by zero: %d/%d in %s: line %d\n", (int)a, (int)b, file, line); 1.713 +#ifdef FIXED_DEBUG_ASSERT 1.714 + celt_assert(0); 1.715 +#endif 1.716 + return 0; 1.717 + } 1.718 + if (!VERIFY_INT(a) || !VERIFY_SHORT(b)) 1.719 + { 1.720 + fprintf (stderr, "DIV32_16: inputs are not int/short: %d %d in %s: line %d\n", (int)a, (int)b, file, line); 1.721 +#ifdef FIXED_DEBUG_ASSERT 1.722 + celt_assert(0); 1.723 +#endif 1.724 + } 1.725 + res = a/b; 1.726 + if (!VERIFY_SHORT(res)) 1.727 + { 1.728 + fprintf (stderr, "DIV32_16: output is not short: %d / %d = %d in %s: line %d\n", (int)a,(int)b,(int)res, file, line); 1.729 + if (res>32767) 1.730 + res = 32767; 1.731 + if (res<-32768) 1.732 + res = -32768; 1.733 +#ifdef FIXED_DEBUG_ASSERT 1.734 + celt_assert(0); 1.735 +#endif 1.736 + } 1.737 + celt_mips+=35; 1.738 + return res; 1.739 +} 1.740 + 1.741 +#define DIV32(a, b) DIV32_(a, b, __FILE__, __LINE__) 1.742 +static OPUS_INLINE int DIV32_(opus_int64 a, opus_int64 b, char *file, int line) 1.743 +{ 1.744 + opus_int64 res; 1.745 + if (b==0) 1.746 + { 1.747 + fprintf(stderr, "DIV32: divide by zero: %d/%d in %s: line %d\n", (int)a, (int)b, file, line); 1.748 +#ifdef FIXED_DEBUG_ASSERT 1.749 + celt_assert(0); 1.750 +#endif 1.751 + return 0; 1.752 + } 1.753 + 1.754 + if (!VERIFY_INT(a) || !VERIFY_INT(b)) 1.755 + { 1.756 + fprintf (stderr, "DIV32: inputs are not int/short: %d %d in %s: line %d\n", (int)a, (int)b, file, line); 1.757 +#ifdef FIXED_DEBUG_ASSERT 1.758 + celt_assert(0); 1.759 +#endif 1.760 + } 1.761 + res = a/b; 1.762 + if (!VERIFY_INT(res)) 1.763 + { 1.764 + fprintf (stderr, "DIV32: output is not int: %d in %s: line %d\n", (int)res, file, line); 1.765 +#ifdef FIXED_DEBUG_ASSERT 1.766 + celt_assert(0); 1.767 +#endif 1.768 + } 1.769 + celt_mips+=70; 1.770 + return res; 1.771 +} 1.772 + 1.773 +#undef PRINT_MIPS 1.774 +#define PRINT_MIPS(file) do {fprintf (file, "total complexity = %llu MIPS\n", celt_mips);} while (0); 1.775 + 1.776 +#endif