media/libopus/silk/MacroCount.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /***********************************************************************
michael@0 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
michael@0 3 Redistribution and use in source and binary forms, with or without
michael@0 4 modification, are permitted provided that the following conditions
michael@0 5 are met:
michael@0 6 - Redistributions of source code must retain the above copyright notice,
michael@0 7 this list of conditions and the following disclaimer.
michael@0 8 - Redistributions in binary form must reproduce the above copyright
michael@0 9 notice, this list of conditions and the following disclaimer in the
michael@0 10 documentation and/or other materials provided with the distribution.
michael@0 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
michael@0 12 names of specific contributors, may be used to endorse or promote
michael@0 13 products derived from this software without specific prior written
michael@0 14 permission.
michael@0 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
michael@0 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
michael@0 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
michael@0 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
michael@0 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
michael@0 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
michael@0 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
michael@0 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
michael@0 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
michael@0 25 POSSIBILITY OF SUCH DAMAGE.
michael@0 26 ***********************************************************************/
michael@0 27
michael@0 28 #ifndef SIGPROCFIX_API_MACROCOUNT_H
michael@0 29 #define SIGPROCFIX_API_MACROCOUNT_H
michael@0 30 #include <stdio.h>
michael@0 31
michael@0 32 #ifdef silk_MACRO_COUNT
michael@0 33 #define varDefine opus_int64 ops_count = 0;
michael@0 34
michael@0 35 extern opus_int64 ops_count;
michael@0 36
michael@0 37 static OPUS_INLINE opus_int64 silk_SaveCount(){
michael@0 38 return(ops_count);
michael@0 39 }
michael@0 40
michael@0 41 static OPUS_INLINE opus_int64 silk_SaveResetCount(){
michael@0 42 opus_int64 ret;
michael@0 43
michael@0 44 ret = ops_count;
michael@0 45 ops_count = 0;
michael@0 46 return(ret);
michael@0 47 }
michael@0 48
michael@0 49 static OPUS_INLINE silk_PrintCount(){
michael@0 50 printf("ops_count = %d \n ", (opus_int32)ops_count);
michael@0 51 }
michael@0 52
michael@0 53 #undef silk_MUL
michael@0 54 static OPUS_INLINE opus_int32 silk_MUL(opus_int32 a32, opus_int32 b32){
michael@0 55 opus_int32 ret;
michael@0 56 ops_count += 4;
michael@0 57 ret = a32 * b32;
michael@0 58 return ret;
michael@0 59 }
michael@0 60
michael@0 61 #undef silk_MUL_uint
michael@0 62 static OPUS_INLINE opus_uint32 silk_MUL_uint(opus_uint32 a32, opus_uint32 b32){
michael@0 63 opus_uint32 ret;
michael@0 64 ops_count += 4;
michael@0 65 ret = a32 * b32;
michael@0 66 return ret;
michael@0 67 }
michael@0 68 #undef silk_MLA
michael@0 69 static OPUS_INLINE opus_int32 silk_MLA(opus_int32 a32, opus_int32 b32, opus_int32 c32){
michael@0 70 opus_int32 ret;
michael@0 71 ops_count += 4;
michael@0 72 ret = a32 + b32 * c32;
michael@0 73 return ret;
michael@0 74 }
michael@0 75
michael@0 76 #undef silk_MLA_uint
michael@0 77 static OPUS_INLINE opus_int32 silk_MLA_uint(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32){
michael@0 78 opus_uint32 ret;
michael@0 79 ops_count += 4;
michael@0 80 ret = a32 + b32 * c32;
michael@0 81 return ret;
michael@0 82 }
michael@0 83
michael@0 84 #undef silk_SMULWB
michael@0 85 static OPUS_INLINE opus_int32 silk_SMULWB(opus_int32 a32, opus_int32 b32){
michael@0 86 opus_int32 ret;
michael@0 87 ops_count += 5;
michael@0 88 ret = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16);
michael@0 89 return ret;
michael@0 90 }
michael@0 91 #undef silk_SMLAWB
michael@0 92 static OPUS_INLINE opus_int32 silk_SMLAWB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
michael@0 93 opus_int32 ret;
michael@0 94 ops_count += 5;
michael@0 95 ret = ((a32) + ((((b32) >> 16) * (opus_int32)((opus_int16)(c32))) + ((((b32) & 0x0000FFFF) * (opus_int32)((opus_int16)(c32))) >> 16)));
michael@0 96 return ret;
michael@0 97 }
michael@0 98
michael@0 99 #undef silk_SMULWT
michael@0 100 static OPUS_INLINE opus_int32 silk_SMULWT(opus_int32 a32, opus_int32 b32){
michael@0 101 opus_int32 ret;
michael@0 102 ops_count += 4;
michael@0 103 ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16);
michael@0 104 return ret;
michael@0 105 }
michael@0 106 #undef silk_SMLAWT
michael@0 107 static OPUS_INLINE opus_int32 silk_SMLAWT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
michael@0 108 opus_int32 ret;
michael@0 109 ops_count += 4;
michael@0 110 ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16));
michael@0 111 return ret;
michael@0 112 }
michael@0 113
michael@0 114 #undef silk_SMULBB
michael@0 115 static OPUS_INLINE opus_int32 silk_SMULBB(opus_int32 a32, opus_int32 b32){
michael@0 116 opus_int32 ret;
michael@0 117 ops_count += 1;
michael@0 118 ret = (opus_int32)((opus_int16)a32) * (opus_int32)((opus_int16)b32);
michael@0 119 return ret;
michael@0 120 }
michael@0 121 #undef silk_SMLABB
michael@0 122 static OPUS_INLINE opus_int32 silk_SMLABB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
michael@0 123 opus_int32 ret;
michael@0 124 ops_count += 1;
michael@0 125 ret = a32 + (opus_int32)((opus_int16)b32) * (opus_int32)((opus_int16)c32);
michael@0 126 return ret;
michael@0 127 }
michael@0 128
michael@0 129 #undef silk_SMULBT
michael@0 130 static OPUS_INLINE opus_int32 silk_SMULBT(opus_int32 a32, opus_int32 b32 ){
michael@0 131 opus_int32 ret;
michael@0 132 ops_count += 4;
michael@0 133 ret = ((opus_int32)((opus_int16)a32)) * (b32 >> 16);
michael@0 134 return ret;
michael@0 135 }
michael@0 136
michael@0 137 #undef silk_SMLABT
michael@0 138 static OPUS_INLINE opus_int32 silk_SMLABT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
michael@0 139 opus_int32 ret;
michael@0 140 ops_count += 1;
michael@0 141 ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16);
michael@0 142 return ret;
michael@0 143 }
michael@0 144
michael@0 145 #undef silk_SMULTT
michael@0 146 static OPUS_INLINE opus_int32 silk_SMULTT(opus_int32 a32, opus_int32 b32){
michael@0 147 opus_int32 ret;
michael@0 148 ops_count += 1;
michael@0 149 ret = (a32 >> 16) * (b32 >> 16);
michael@0 150 return ret;
michael@0 151 }
michael@0 152
michael@0 153 #undef silk_SMLATT
michael@0 154 static OPUS_INLINE opus_int32 silk_SMLATT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
michael@0 155 opus_int32 ret;
michael@0 156 ops_count += 1;
michael@0 157 ret = a32 + (b32 >> 16) * (c32 >> 16);
michael@0 158 return ret;
michael@0 159 }
michael@0 160
michael@0 161
michael@0 162 /* multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode)*/
michael@0 163 #undef silk_MLA_ovflw
michael@0 164 #define silk_MLA_ovflw silk_MLA
michael@0 165
michael@0 166 #undef silk_SMLABB_ovflw
michael@0 167 #define silk_SMLABB_ovflw silk_SMLABB
michael@0 168
michael@0 169 #undef silk_SMLABT_ovflw
michael@0 170 #define silk_SMLABT_ovflw silk_SMLABT
michael@0 171
michael@0 172 #undef silk_SMLATT_ovflw
michael@0 173 #define silk_SMLATT_ovflw silk_SMLATT
michael@0 174
michael@0 175 #undef silk_SMLAWB_ovflw
michael@0 176 #define silk_SMLAWB_ovflw silk_SMLAWB
michael@0 177
michael@0 178 #undef silk_SMLAWT_ovflw
michael@0 179 #define silk_SMLAWT_ovflw silk_SMLAWT
michael@0 180
michael@0 181 #undef silk_SMULL
michael@0 182 static OPUS_INLINE opus_int64 silk_SMULL(opus_int32 a32, opus_int32 b32){
michael@0 183 opus_int64 ret;
michael@0 184 ops_count += 8;
michael@0 185 ret = ((opus_int64)(a32) * /*(opus_int64)*/(b32));
michael@0 186 return ret;
michael@0 187 }
michael@0 188
michael@0 189 #undef silk_SMLAL
michael@0 190 static OPUS_INLINE opus_int64 silk_SMLAL(opus_int64 a64, opus_int32 b32, opus_int32 c32){
michael@0 191 opus_int64 ret;
michael@0 192 ops_count += 8;
michael@0 193 ret = a64 + ((opus_int64)(b32) * /*(opus_int64)*/(c32));
michael@0 194 return ret;
michael@0 195 }
michael@0 196 #undef silk_SMLALBB
michael@0 197 static OPUS_INLINE opus_int64 silk_SMLALBB(opus_int64 a64, opus_int16 b16, opus_int16 c16){
michael@0 198 opus_int64 ret;
michael@0 199 ops_count += 4;
michael@0 200 ret = a64 + ((opus_int64)(b16) * /*(opus_int64)*/(c16));
michael@0 201 return ret;
michael@0 202 }
michael@0 203
michael@0 204 #undef SigProcFIX_CLZ16
michael@0 205 static OPUS_INLINE opus_int32 SigProcFIX_CLZ16(opus_int16 in16)
michael@0 206 {
michael@0 207 opus_int32 out32 = 0;
michael@0 208 ops_count += 10;
michael@0 209 if( in16 == 0 ) {
michael@0 210 return 16;
michael@0 211 }
michael@0 212 /* test nibbles */
michael@0 213 if( in16 & 0xFF00 ) {
michael@0 214 if( in16 & 0xF000 ) {
michael@0 215 in16 >>= 12;
michael@0 216 } else {
michael@0 217 out32 += 4;
michael@0 218 in16 >>= 8;
michael@0 219 }
michael@0 220 } else {
michael@0 221 if( in16 & 0xFFF0 ) {
michael@0 222 out32 += 8;
michael@0 223 in16 >>= 4;
michael@0 224 } else {
michael@0 225 out32 += 12;
michael@0 226 }
michael@0 227 }
michael@0 228 /* test bits and return */
michael@0 229 if( in16 & 0xC ) {
michael@0 230 if( in16 & 0x8 )
michael@0 231 return out32 + 0;
michael@0 232 else
michael@0 233 return out32 + 1;
michael@0 234 } else {
michael@0 235 if( in16 & 0xE )
michael@0 236 return out32 + 2;
michael@0 237 else
michael@0 238 return out32 + 3;
michael@0 239 }
michael@0 240 }
michael@0 241
michael@0 242 #undef SigProcFIX_CLZ32
michael@0 243 static OPUS_INLINE opus_int32 SigProcFIX_CLZ32(opus_int32 in32)
michael@0 244 {
michael@0 245 /* test highest 16 bits and convert to opus_int16 */
michael@0 246 ops_count += 2;
michael@0 247 if( in32 & 0xFFFF0000 ) {
michael@0 248 return SigProcFIX_CLZ16((opus_int16)(in32 >> 16));
michael@0 249 } else {
michael@0 250 return SigProcFIX_CLZ16((opus_int16)in32) + 16;
michael@0 251 }
michael@0 252 }
michael@0 253
michael@0 254 #undef silk_DIV32
michael@0 255 static OPUS_INLINE opus_int32 silk_DIV32(opus_int32 a32, opus_int32 b32){
michael@0 256 ops_count += 64;
michael@0 257 return a32 / b32;
michael@0 258 }
michael@0 259
michael@0 260 #undef silk_DIV32_16
michael@0 261 static OPUS_INLINE opus_int32 silk_DIV32_16(opus_int32 a32, opus_int32 b32){
michael@0 262 ops_count += 32;
michael@0 263 return a32 / b32;
michael@0 264 }
michael@0 265
michael@0 266 #undef silk_SAT8
michael@0 267 static OPUS_INLINE opus_int8 silk_SAT8(opus_int64 a){
michael@0 268 opus_int8 tmp;
michael@0 269 ops_count += 1;
michael@0 270 tmp = (opus_int8)((a) > silk_int8_MAX ? silk_int8_MAX : \
michael@0 271 ((a) < silk_int8_MIN ? silk_int8_MIN : (a)));
michael@0 272 return(tmp);
michael@0 273 }
michael@0 274
michael@0 275 #undef silk_SAT16
michael@0 276 static OPUS_INLINE opus_int16 silk_SAT16(opus_int64 a){
michael@0 277 opus_int16 tmp;
michael@0 278 ops_count += 1;
michael@0 279 tmp = (opus_int16)((a) > silk_int16_MAX ? silk_int16_MAX : \
michael@0 280 ((a) < silk_int16_MIN ? silk_int16_MIN : (a)));
michael@0 281 return(tmp);
michael@0 282 }
michael@0 283 #undef silk_SAT32
michael@0 284 static OPUS_INLINE opus_int32 silk_SAT32(opus_int64 a){
michael@0 285 opus_int32 tmp;
michael@0 286 ops_count += 1;
michael@0 287 tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : \
michael@0 288 ((a) < silk_int32_MIN ? silk_int32_MIN : (a)));
michael@0 289 return(tmp);
michael@0 290 }
michael@0 291 #undef silk_POS_SAT32
michael@0 292 static OPUS_INLINE opus_int32 silk_POS_SAT32(opus_int64 a){
michael@0 293 opus_int32 tmp;
michael@0 294 ops_count += 1;
michael@0 295 tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : (a));
michael@0 296 return(tmp);
michael@0 297 }
michael@0 298
michael@0 299 #undef silk_ADD_POS_SAT8
michael@0 300 static OPUS_INLINE opus_int8 silk_ADD_POS_SAT8(opus_int64 a, opus_int64 b){
michael@0 301 opus_int8 tmp;
michael@0 302 ops_count += 1;
michael@0 303 tmp = (opus_int8)((((a)+(b)) & 0x80) ? silk_int8_MAX : ((a)+(b)));
michael@0 304 return(tmp);
michael@0 305 }
michael@0 306 #undef silk_ADD_POS_SAT16
michael@0 307 static OPUS_INLINE opus_int16 silk_ADD_POS_SAT16(opus_int64 a, opus_int64 b){
michael@0 308 opus_int16 tmp;
michael@0 309 ops_count += 1;
michael@0 310 tmp = (opus_int16)((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b)));
michael@0 311 return(tmp);
michael@0 312 }
michael@0 313
michael@0 314 #undef silk_ADD_POS_SAT32
michael@0 315 static OPUS_INLINE opus_int32 silk_ADD_POS_SAT32(opus_int64 a, opus_int64 b){
michael@0 316 opus_int32 tmp;
michael@0 317 ops_count += 1;
michael@0 318 tmp = (opus_int32)((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b)));
michael@0 319 return(tmp);
michael@0 320 }
michael@0 321
michael@0 322 #undef silk_ADD_POS_SAT64
michael@0 323 static OPUS_INLINE opus_int64 silk_ADD_POS_SAT64(opus_int64 a, opus_int64 b){
michael@0 324 opus_int64 tmp;
michael@0 325 ops_count += 1;
michael@0 326 tmp = ((((a)+(b)) & 0x8000000000000000LL) ? silk_int64_MAX : ((a)+(b)));
michael@0 327 return(tmp);
michael@0 328 }
michael@0 329
michael@0 330 #undef silk_LSHIFT8
michael@0 331 static OPUS_INLINE opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift){
michael@0 332 opus_int8 ret;
michael@0 333 ops_count += 1;
michael@0 334 ret = a << shift;
michael@0 335 return ret;
michael@0 336 }
michael@0 337 #undef silk_LSHIFT16
michael@0 338 static OPUS_INLINE opus_int16 silk_LSHIFT16(opus_int16 a, opus_int32 shift){
michael@0 339 opus_int16 ret;
michael@0 340 ops_count += 1;
michael@0 341 ret = a << shift;
michael@0 342 return ret;
michael@0 343 }
michael@0 344 #undef silk_LSHIFT32
michael@0 345 static OPUS_INLINE opus_int32 silk_LSHIFT32(opus_int32 a, opus_int32 shift){
michael@0 346 opus_int32 ret;
michael@0 347 ops_count += 1;
michael@0 348 ret = a << shift;
michael@0 349 return ret;
michael@0 350 }
michael@0 351 #undef silk_LSHIFT64
michael@0 352 static OPUS_INLINE opus_int64 silk_LSHIFT64(opus_int64 a, opus_int shift){
michael@0 353 ops_count += 1;
michael@0 354 return a << shift;
michael@0 355 }
michael@0 356
michael@0 357 #undef silk_LSHIFT_ovflw
michael@0 358 static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw(opus_int32 a, opus_int32 shift){
michael@0 359 ops_count += 1;
michael@0 360 return a << shift;
michael@0 361 }
michael@0 362
michael@0 363 #undef silk_LSHIFT_uint
michael@0 364 static OPUS_INLINE opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift){
michael@0 365 opus_uint32 ret;
michael@0 366 ops_count += 1;
michael@0 367 ret = a << shift;
michael@0 368 return ret;
michael@0 369 }
michael@0 370
michael@0 371 #undef silk_RSHIFT8
michael@0 372 static OPUS_INLINE opus_int8 silk_RSHIFT8(opus_int8 a, opus_int32 shift){
michael@0 373 ops_count += 1;
michael@0 374 return a >> shift;
michael@0 375 }
michael@0 376 #undef silk_RSHIFT16
michael@0 377 static OPUS_INLINE opus_int16 silk_RSHIFT16(opus_int16 a, opus_int32 shift){
michael@0 378 ops_count += 1;
michael@0 379 return a >> shift;
michael@0 380 }
michael@0 381 #undef silk_RSHIFT32
michael@0 382 static OPUS_INLINE opus_int32 silk_RSHIFT32(opus_int32 a, opus_int32 shift){
michael@0 383 ops_count += 1;
michael@0 384 return a >> shift;
michael@0 385 }
michael@0 386 #undef silk_RSHIFT64
michael@0 387 static OPUS_INLINE opus_int64 silk_RSHIFT64(opus_int64 a, opus_int64 shift){
michael@0 388 ops_count += 1;
michael@0 389 return a >> shift;
michael@0 390 }
michael@0 391
michael@0 392 #undef silk_RSHIFT_uint
michael@0 393 static OPUS_INLINE opus_uint32 silk_RSHIFT_uint(opus_uint32 a, opus_int32 shift){
michael@0 394 ops_count += 1;
michael@0 395 return a >> shift;
michael@0 396 }
michael@0 397
michael@0 398 #undef silk_ADD_LSHIFT
michael@0 399 static OPUS_INLINE opus_int32 silk_ADD_LSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
michael@0 400 opus_int32 ret;
michael@0 401 ops_count += 1;
michael@0 402 ret = a + (b << shift);
michael@0 403 return ret; /* shift >= 0*/
michael@0 404 }
michael@0 405 #undef silk_ADD_LSHIFT32
michael@0 406 static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
michael@0 407 opus_int32 ret;
michael@0 408 ops_count += 1;
michael@0 409 ret = a + (b << shift);
michael@0 410 return ret; /* shift >= 0*/
michael@0 411 }
michael@0 412 #undef silk_ADD_LSHIFT_uint
michael@0 413 static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
michael@0 414 opus_uint32 ret;
michael@0 415 ops_count += 1;
michael@0 416 ret = a + (b << shift);
michael@0 417 return ret; /* shift >= 0*/
michael@0 418 }
michael@0 419 #undef silk_ADD_RSHIFT
michael@0 420 static OPUS_INLINE opus_int32 silk_ADD_RSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
michael@0 421 opus_int32 ret;
michael@0 422 ops_count += 1;
michael@0 423 ret = a + (b >> shift);
michael@0 424 return ret; /* shift > 0*/
michael@0 425 }
michael@0 426 #undef silk_ADD_RSHIFT32
michael@0 427 static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
michael@0 428 opus_int32 ret;
michael@0 429 ops_count += 1;
michael@0 430 ret = a + (b >> shift);
michael@0 431 return ret; /* shift > 0*/
michael@0 432 }
michael@0 433 #undef silk_ADD_RSHIFT_uint
michael@0 434 static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
michael@0 435 opus_uint32 ret;
michael@0 436 ops_count += 1;
michael@0 437 ret = a + (b >> shift);
michael@0 438 return ret; /* shift > 0*/
michael@0 439 }
michael@0 440 #undef silk_SUB_LSHIFT32
michael@0 441 static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
michael@0 442 opus_int32 ret;
michael@0 443 ops_count += 1;
michael@0 444 ret = a - (b << shift);
michael@0 445 return ret; /* shift >= 0*/
michael@0 446 }
michael@0 447 #undef silk_SUB_RSHIFT32
michael@0 448 static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
michael@0 449 opus_int32 ret;
michael@0 450 ops_count += 1;
michael@0 451 ret = a - (b >> shift);
michael@0 452 return ret; /* shift > 0*/
michael@0 453 }
michael@0 454
michael@0 455 #undef silk_RSHIFT_ROUND
michael@0 456 static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift){
michael@0 457 opus_int32 ret;
michael@0 458 ops_count += 3;
michael@0 459 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
michael@0 460 return ret;
michael@0 461 }
michael@0 462
michael@0 463 #undef silk_RSHIFT_ROUND64
michael@0 464 static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift){
michael@0 465 opus_int64 ret;
michael@0 466 ops_count += 6;
michael@0 467 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
michael@0 468 return ret;
michael@0 469 }
michael@0 470
michael@0 471 #undef silk_abs_int64
michael@0 472 static OPUS_INLINE opus_int64 silk_abs_int64(opus_int64 a){
michael@0 473 ops_count += 1;
michael@0 474 return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN*/
michael@0 475 }
michael@0 476
michael@0 477 #undef silk_abs_int32
michael@0 478 static OPUS_INLINE opus_int32 silk_abs_int32(opus_int32 a){
michael@0 479 ops_count += 1;
michael@0 480 return silk_abs(a);
michael@0 481 }
michael@0 482
michael@0 483
michael@0 484 #undef silk_min
michael@0 485 static silk_min(a, b){
michael@0 486 ops_count += 1;
michael@0 487 return (((a) < (b)) ? (a) : (b));
michael@0 488 }
michael@0 489 #undef silk_max
michael@0 490 static silk_max(a, b){
michael@0 491 ops_count += 1;
michael@0 492 return (((a) > (b)) ? (a) : (b));
michael@0 493 }
michael@0 494 #undef silk_sign
michael@0 495 static silk_sign(a){
michael@0 496 ops_count += 1;
michael@0 497 return ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 ));
michael@0 498 }
michael@0 499
michael@0 500 #undef silk_ADD16
michael@0 501 static OPUS_INLINE opus_int16 silk_ADD16(opus_int16 a, opus_int16 b){
michael@0 502 opus_int16 ret;
michael@0 503 ops_count += 1;
michael@0 504 ret = a + b;
michael@0 505 return ret;
michael@0 506 }
michael@0 507
michael@0 508 #undef silk_ADD32
michael@0 509 static OPUS_INLINE opus_int32 silk_ADD32(opus_int32 a, opus_int32 b){
michael@0 510 opus_int32 ret;
michael@0 511 ops_count += 1;
michael@0 512 ret = a + b;
michael@0 513 return ret;
michael@0 514 }
michael@0 515
michael@0 516 #undef silk_ADD64
michael@0 517 static OPUS_INLINE opus_int64 silk_ADD64(opus_int64 a, opus_int64 b){
michael@0 518 opus_int64 ret;
michael@0 519 ops_count += 2;
michael@0 520 ret = a + b;
michael@0 521 return ret;
michael@0 522 }
michael@0 523
michael@0 524 #undef silk_SUB16
michael@0 525 static OPUS_INLINE opus_int16 silk_SUB16(opus_int16 a, opus_int16 b){
michael@0 526 opus_int16 ret;
michael@0 527 ops_count += 1;
michael@0 528 ret = a - b;
michael@0 529 return ret;
michael@0 530 }
michael@0 531
michael@0 532 #undef silk_SUB32
michael@0 533 static OPUS_INLINE opus_int32 silk_SUB32(opus_int32 a, opus_int32 b){
michael@0 534 opus_int32 ret;
michael@0 535 ops_count += 1;
michael@0 536 ret = a - b;
michael@0 537 return ret;
michael@0 538 }
michael@0 539
michael@0 540 #undef silk_SUB64
michael@0 541 static OPUS_INLINE opus_int64 silk_SUB64(opus_int64 a, opus_int64 b){
michael@0 542 opus_int64 ret;
michael@0 543 ops_count += 2;
michael@0 544 ret = a - b;
michael@0 545 return ret;
michael@0 546 }
michael@0 547
michael@0 548 #undef silk_ADD_SAT16
michael@0 549 static OPUS_INLINE opus_int16 silk_ADD_SAT16( opus_int16 a16, opus_int16 b16 ) {
michael@0 550 opus_int16 res;
michael@0 551 /* Nb will be counted in AKP_add32 and silk_SAT16*/
michael@0 552 res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) );
michael@0 553 return res;
michael@0 554 }
michael@0 555
michael@0 556 #undef silk_ADD_SAT32
michael@0 557 static OPUS_INLINE opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32){
michael@0 558 opus_int32 res;
michael@0 559 ops_count += 1;
michael@0 560 res = ((((a32) + (b32)) & 0x80000000) == 0 ? \
michael@0 561 ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \
michael@0 562 ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) );
michael@0 563 return res;
michael@0 564 }
michael@0 565
michael@0 566 #undef silk_ADD_SAT64
michael@0 567 static OPUS_INLINE opus_int64 silk_ADD_SAT64( opus_int64 a64, opus_int64 b64 ) {
michael@0 568 opus_int64 res;
michael@0 569 ops_count += 1;
michael@0 570 res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \
michael@0 571 ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \
michael@0 572 ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) );
michael@0 573 return res;
michael@0 574 }
michael@0 575
michael@0 576 #undef silk_SUB_SAT16
michael@0 577 static OPUS_INLINE opus_int16 silk_SUB_SAT16( opus_int16 a16, opus_int16 b16 ) {
michael@0 578 opus_int16 res;
michael@0 579 silk_assert(0);
michael@0 580 /* Nb will be counted in sub-macros*/
michael@0 581 res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) );
michael@0 582 return res;
michael@0 583 }
michael@0 584
michael@0 585 #undef silk_SUB_SAT32
michael@0 586 static OPUS_INLINE opus_int32 silk_SUB_SAT32( opus_int32 a32, opus_int32 b32 ) {
michael@0 587 opus_int32 res;
michael@0 588 ops_count += 1;
michael@0 589 res = ((((a32)-(b32)) & 0x80000000) == 0 ? \
michael@0 590 (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \
michael@0 591 ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) );
michael@0 592 return res;
michael@0 593 }
michael@0 594
michael@0 595 #undef silk_SUB_SAT64
michael@0 596 static OPUS_INLINE opus_int64 silk_SUB_SAT64( opus_int64 a64, opus_int64 b64 ) {
michael@0 597 opus_int64 res;
michael@0 598 ops_count += 1;
michael@0 599 res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \
michael@0 600 (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \
michael@0 601 ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) );
michael@0 602
michael@0 603 return res;
michael@0 604 }
michael@0 605
michael@0 606 #undef silk_SMULWW
michael@0 607 static OPUS_INLINE opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32){
michael@0 608 opus_int32 ret;
michael@0 609 /* Nb will be counted in sub-macros*/
michael@0 610 ret = silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16));
michael@0 611 return ret;
michael@0 612 }
michael@0 613
michael@0 614 #undef silk_SMLAWW
michael@0 615 static OPUS_INLINE opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_int32 c32){
michael@0 616 opus_int32 ret;
michael@0 617 /* Nb will be counted in sub-macros*/
michael@0 618 ret = silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16));
michael@0 619 return ret;
michael@0 620 }
michael@0 621
michael@0 622 #undef silk_min_int
michael@0 623 static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b)
michael@0 624 {
michael@0 625 ops_count += 1;
michael@0 626 return (((a) < (b)) ? (a) : (b));
michael@0 627 }
michael@0 628
michael@0 629 #undef silk_min_16
michael@0 630 static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b)
michael@0 631 {
michael@0 632 ops_count += 1;
michael@0 633 return (((a) < (b)) ? (a) : (b));
michael@0 634 }
michael@0 635 #undef silk_min_32
michael@0 636 static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b)
michael@0 637 {
michael@0 638 ops_count += 1;
michael@0 639 return (((a) < (b)) ? (a) : (b));
michael@0 640 }
michael@0 641 #undef silk_min_64
michael@0 642 static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b)
michael@0 643 {
michael@0 644 ops_count += 1;
michael@0 645 return (((a) < (b)) ? (a) : (b));
michael@0 646 }
michael@0 647
michael@0 648 /* silk_min() versions with typecast in the function call */
michael@0 649 #undef silk_max_int
michael@0 650 static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b)
michael@0 651 {
michael@0 652 ops_count += 1;
michael@0 653 return (((a) > (b)) ? (a) : (b));
michael@0 654 }
michael@0 655 #undef silk_max_16
michael@0 656 static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b)
michael@0 657 {
michael@0 658 ops_count += 1;
michael@0 659 return (((a) > (b)) ? (a) : (b));
michael@0 660 }
michael@0 661 #undef silk_max_32
michael@0 662 static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b)
michael@0 663 {
michael@0 664 ops_count += 1;
michael@0 665 return (((a) > (b)) ? (a) : (b));
michael@0 666 }
michael@0 667
michael@0 668 #undef silk_max_64
michael@0 669 static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b)
michael@0 670 {
michael@0 671 ops_count += 1;
michael@0 672 return (((a) > (b)) ? (a) : (b));
michael@0 673 }
michael@0 674
michael@0 675
michael@0 676 #undef silk_LIMIT_int
michael@0 677 static OPUS_INLINE opus_int silk_LIMIT_int(opus_int a, opus_int limit1, opus_int limit2)
michael@0 678 {
michael@0 679 opus_int ret;
michael@0 680 ops_count += 6;
michael@0 681
michael@0 682 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
michael@0 683 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
michael@0 684
michael@0 685 return(ret);
michael@0 686 }
michael@0 687
michael@0 688 #undef silk_LIMIT_16
michael@0 689 static OPUS_INLINE opus_int16 silk_LIMIT_16(opus_int16 a, opus_int16 limit1, opus_int16 limit2)
michael@0 690 {
michael@0 691 opus_int16 ret;
michael@0 692 ops_count += 6;
michael@0 693
michael@0 694 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
michael@0 695 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
michael@0 696
michael@0 697 return(ret);
michael@0 698 }
michael@0 699
michael@0 700
michael@0 701 #undef silk_LIMIT_32
michael@0 702 static OPUS_INLINE opus_int silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2)
michael@0 703 {
michael@0 704 opus_int32 ret;
michael@0 705 ops_count += 6;
michael@0 706
michael@0 707 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
michael@0 708 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
michael@0 709 return(ret);
michael@0 710 }
michael@0 711
michael@0 712 #else
michael@0 713 #define varDefine
michael@0 714 #define silk_SaveCount()
michael@0 715
michael@0 716 #endif
michael@0 717 #endif
michael@0 718

mercurial