media/libopus/silk/MacroDebug.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 Copyright (C) 2012 Xiph.Org Foundation
michael@0 4 Redistribution and use in source and binary forms, with or without
michael@0 5 modification, are permitted provided that the following conditions
michael@0 6 are met:
michael@0 7 - Redistributions of source code must retain the above copyright notice,
michael@0 8 this list of conditions and the following disclaimer.
michael@0 9 - Redistributions in binary form must reproduce the above copyright
michael@0 10 notice, this list of conditions and the following disclaimer in the
michael@0 11 documentation and/or other materials provided with the distribution.
michael@0 12 - Neither the name of Internet Society, IETF or IETF Trust, nor the
michael@0 13 names of specific contributors, may be used to endorse or promote
michael@0 14 products derived from this software without specific prior written
michael@0 15 permission.
michael@0 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
michael@0 17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
michael@0 19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
michael@0 20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
michael@0 21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
michael@0 22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
michael@0 23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
michael@0 24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
michael@0 25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
michael@0 26 POSSIBILITY OF SUCH DAMAGE.
michael@0 27 ***********************************************************************/
michael@0 28
michael@0 29 #ifndef MACRO_DEBUG_H
michael@0 30 #define MACRO_DEBUG_H
michael@0 31
michael@0 32 /* Redefine macro functions with extensive assertion in DEBUG mode.
michael@0 33 As functions can't be undefined, this file can't work with SigProcFIX_MacroCount.h */
michael@0 34
michael@0 35 #if ( defined (FIXED_DEBUG) || ( 0 && defined (_DEBUG) ) ) && !defined (silk_MACRO_COUNT)
michael@0 36
michael@0 37 #undef silk_ADD16
michael@0 38 #define silk_ADD16(a,b) silk_ADD16_((a), (b), __FILE__, __LINE__)
michael@0 39 static OPUS_INLINE opus_int16 silk_ADD16_(opus_int16 a, opus_int16 b, char *file, int line){
michael@0 40 opus_int16 ret;
michael@0 41
michael@0 42 ret = a + b;
michael@0 43 if ( ret != silk_ADD_SAT16( a, b ) )
michael@0 44 {
michael@0 45 fprintf (stderr, "silk_ADD16(%d, %d) in %s: line %d\n", a, b, file, line);
michael@0 46 #ifdef FIXED_DEBUG_ASSERT
michael@0 47 silk_assert( 0 );
michael@0 48 #endif
michael@0 49 }
michael@0 50 return ret;
michael@0 51 }
michael@0 52
michael@0 53 #undef silk_ADD32
michael@0 54 #define silk_ADD32(a,b) silk_ADD32_((a), (b), __FILE__, __LINE__)
michael@0 55 static OPUS_INLINE opus_int32 silk_ADD32_(opus_int32 a, opus_int32 b, char *file, int line){
michael@0 56 opus_int32 ret;
michael@0 57
michael@0 58 ret = a + b;
michael@0 59 if ( ret != silk_ADD_SAT32( a, b ) )
michael@0 60 {
michael@0 61 fprintf (stderr, "silk_ADD32(%d, %d) in %s: line %d\n", a, b, file, line);
michael@0 62 #ifdef FIXED_DEBUG_ASSERT
michael@0 63 silk_assert( 0 );
michael@0 64 #endif
michael@0 65 }
michael@0 66 return ret;
michael@0 67 }
michael@0 68
michael@0 69 #undef silk_ADD64
michael@0 70 #define silk_ADD64(a,b) silk_ADD64_((a), (b), __FILE__, __LINE__)
michael@0 71 static OPUS_INLINE opus_int64 silk_ADD64_(opus_int64 a, opus_int64 b, char *file, int line){
michael@0 72 opus_int64 ret;
michael@0 73
michael@0 74 ret = a + b;
michael@0 75 if ( ret != silk_ADD_SAT64( a, b ) )
michael@0 76 {
michael@0 77 fprintf (stderr, "silk_ADD64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)b, file, line);
michael@0 78 #ifdef FIXED_DEBUG_ASSERT
michael@0 79 silk_assert( 0 );
michael@0 80 #endif
michael@0 81 }
michael@0 82 return ret;
michael@0 83 }
michael@0 84
michael@0 85 #undef silk_SUB16
michael@0 86 #define silk_SUB16(a,b) silk_SUB16_((a), (b), __FILE__, __LINE__)
michael@0 87 static OPUS_INLINE opus_int16 silk_SUB16_(opus_int16 a, opus_int16 b, char *file, int line){
michael@0 88 opus_int16 ret;
michael@0 89
michael@0 90 ret = a - b;
michael@0 91 if ( ret != silk_SUB_SAT16( a, b ) )
michael@0 92 {
michael@0 93 fprintf (stderr, "silk_SUB16(%d, %d) in %s: line %d\n", a, b, file, line);
michael@0 94 #ifdef FIXED_DEBUG_ASSERT
michael@0 95 silk_assert( 0 );
michael@0 96 #endif
michael@0 97 }
michael@0 98 return ret;
michael@0 99 }
michael@0 100
michael@0 101 #undef silk_SUB32
michael@0 102 #define silk_SUB32(a,b) silk_SUB32_((a), (b), __FILE__, __LINE__)
michael@0 103 static OPUS_INLINE opus_int32 silk_SUB32_(opus_int32 a, opus_int32 b, char *file, int line){
michael@0 104 opus_int32 ret;
michael@0 105
michael@0 106 ret = a - b;
michael@0 107 if ( ret != silk_SUB_SAT32( a, b ) )
michael@0 108 {
michael@0 109 fprintf (stderr, "silk_SUB32(%d, %d) in %s: line %d\n", a, b, file, line);
michael@0 110 #ifdef FIXED_DEBUG_ASSERT
michael@0 111 silk_assert( 0 );
michael@0 112 #endif
michael@0 113 }
michael@0 114 return ret;
michael@0 115 }
michael@0 116
michael@0 117 #undef silk_SUB64
michael@0 118 #define silk_SUB64(a,b) silk_SUB64_((a), (b), __FILE__, __LINE__)
michael@0 119 static OPUS_INLINE opus_int64 silk_SUB64_(opus_int64 a, opus_int64 b, char *file, int line){
michael@0 120 opus_int64 ret;
michael@0 121
michael@0 122 ret = a - b;
michael@0 123 if ( ret != silk_SUB_SAT64( a, b ) )
michael@0 124 {
michael@0 125 fprintf (stderr, "silk_SUB64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)b, file, line);
michael@0 126 #ifdef FIXED_DEBUG_ASSERT
michael@0 127 silk_assert( 0 );
michael@0 128 #endif
michael@0 129 }
michael@0 130 return ret;
michael@0 131 }
michael@0 132
michael@0 133 #undef silk_ADD_SAT16
michael@0 134 #define silk_ADD_SAT16(a,b) silk_ADD_SAT16_((a), (b), __FILE__, __LINE__)
michael@0 135 static OPUS_INLINE opus_int16 silk_ADD_SAT16_( opus_int16 a16, opus_int16 b16, char *file, int line) {
michael@0 136 opus_int16 res;
michael@0 137 res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) );
michael@0 138 if ( res != silk_SAT16( (opus_int32)a16 + (opus_int32)b16 ) )
michael@0 139 {
michael@0 140 fprintf (stderr, "silk_ADD_SAT16(%d, %d) in %s: line %d\n", a16, b16, file, line);
michael@0 141 #ifdef FIXED_DEBUG_ASSERT
michael@0 142 silk_assert( 0 );
michael@0 143 #endif
michael@0 144 }
michael@0 145 return res;
michael@0 146 }
michael@0 147
michael@0 148 #undef silk_ADD_SAT32
michael@0 149 #define silk_ADD_SAT32(a,b) silk_ADD_SAT32_((a), (b), __FILE__, __LINE__)
michael@0 150 static OPUS_INLINE opus_int32 silk_ADD_SAT32_(opus_int32 a32, opus_int32 b32, char *file, int line){
michael@0 151 opus_int32 res;
michael@0 152 res = ((((opus_uint32)(a32) + (opus_uint32)(b32)) & 0x80000000) == 0 ? \
michael@0 153 ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \
michael@0 154 ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) );
michael@0 155 if ( res != silk_SAT32( (opus_int64)a32 + (opus_int64)b32 ) )
michael@0 156 {
michael@0 157 fprintf (stderr, "silk_ADD_SAT32(%d, %d) in %s: line %d\n", a32, b32, file, line);
michael@0 158 #ifdef FIXED_DEBUG_ASSERT
michael@0 159 silk_assert( 0 );
michael@0 160 #endif
michael@0 161 }
michael@0 162 return res;
michael@0 163 }
michael@0 164
michael@0 165 #undef silk_ADD_SAT64
michael@0 166 #define silk_ADD_SAT64(a,b) silk_ADD_SAT64_((a), (b), __FILE__, __LINE__)
michael@0 167 static OPUS_INLINE opus_int64 silk_ADD_SAT64_( opus_int64 a64, opus_int64 b64, char *file, int line) {
michael@0 168 opus_int64 res;
michael@0 169 int fail = 0;
michael@0 170 res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \
michael@0 171 ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \
michael@0 172 ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) );
michael@0 173 if( res != a64 + b64 ) {
michael@0 174 /* Check that we saturated to the correct extreme value */
michael@0 175 if ( !(( res == silk_int64_MAX && ( ( a64 >> 1 ) + ( b64 >> 1 ) > ( silk_int64_MAX >> 3 ) ) ) ||
michael@0 176 ( res == silk_int64_MIN && ( ( a64 >> 1 ) + ( b64 >> 1 ) < ( silk_int64_MIN >> 3 ) ) ) ) )
michael@0 177 {
michael@0 178 fail = 1;
michael@0 179 }
michael@0 180 } else {
michael@0 181 /* Saturation not necessary */
michael@0 182 fail = res != a64 + b64;
michael@0 183 }
michael@0 184 if ( fail )
michael@0 185 {
michael@0 186 fprintf (stderr, "silk_ADD_SAT64(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line);
michael@0 187 #ifdef FIXED_DEBUG_ASSERT
michael@0 188 silk_assert( 0 );
michael@0 189 #endif
michael@0 190 }
michael@0 191 return res;
michael@0 192 }
michael@0 193
michael@0 194 #undef silk_SUB_SAT16
michael@0 195 #define silk_SUB_SAT16(a,b) silk_SUB_SAT16_((a), (b), __FILE__, __LINE__)
michael@0 196 static OPUS_INLINE opus_int16 silk_SUB_SAT16_( opus_int16 a16, opus_int16 b16, char *file, int line ) {
michael@0 197 opus_int16 res;
michael@0 198 res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) );
michael@0 199 if ( res != silk_SAT16( (opus_int32)a16 - (opus_int32)b16 ) )
michael@0 200 {
michael@0 201 fprintf (stderr, "silk_SUB_SAT16(%d, %d) in %s: line %d\n", a16, b16, file, line);
michael@0 202 #ifdef FIXED_DEBUG_ASSERT
michael@0 203 silk_assert( 0 );
michael@0 204 #endif
michael@0 205 }
michael@0 206 return res;
michael@0 207 }
michael@0 208
michael@0 209 #undef silk_SUB_SAT32
michael@0 210 #define silk_SUB_SAT32(a,b) silk_SUB_SAT32_((a), (b), __FILE__, __LINE__)
michael@0 211 static OPUS_INLINE opus_int32 silk_SUB_SAT32_( opus_int32 a32, opus_int32 b32, char *file, int line ) {
michael@0 212 opus_int32 res;
michael@0 213 res = ((((opus_uint32)(a32)-(opus_uint32)(b32)) & 0x80000000) == 0 ? \
michael@0 214 (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \
michael@0 215 ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) );
michael@0 216 if ( res != silk_SAT32( (opus_int64)a32 - (opus_int64)b32 ) )
michael@0 217 {
michael@0 218 fprintf (stderr, "silk_SUB_SAT32(%d, %d) in %s: line %d\n", a32, b32, file, line);
michael@0 219 #ifdef FIXED_DEBUG_ASSERT
michael@0 220 silk_assert( 0 );
michael@0 221 #endif
michael@0 222 }
michael@0 223 return res;
michael@0 224 }
michael@0 225
michael@0 226 #undef silk_SUB_SAT64
michael@0 227 #define silk_SUB_SAT64(a,b) silk_SUB_SAT64_((a), (b), __FILE__, __LINE__)
michael@0 228 static OPUS_INLINE opus_int64 silk_SUB_SAT64_( opus_int64 a64, opus_int64 b64, char *file, int line ) {
michael@0 229 opus_int64 res;
michael@0 230 int fail = 0;
michael@0 231 res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \
michael@0 232 (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \
michael@0 233 ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) );
michael@0 234 if( res != a64 - b64 ) {
michael@0 235 /* Check that we saturated to the correct extreme value */
michael@0 236 if( !(( res == silk_int64_MAX && ( ( a64 >> 1 ) + ( b64 >> 1 ) > ( silk_int64_MAX >> 3 ) ) ) ||
michael@0 237 ( res == silk_int64_MIN && ( ( a64 >> 1 ) + ( b64 >> 1 ) < ( silk_int64_MIN >> 3 ) ) ) ))
michael@0 238 {
michael@0 239 fail = 1;
michael@0 240 }
michael@0 241 } else {
michael@0 242 /* Saturation not necessary */
michael@0 243 fail = res != a64 - b64;
michael@0 244 }
michael@0 245 if ( fail )
michael@0 246 {
michael@0 247 fprintf (stderr, "silk_SUB_SAT64(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line);
michael@0 248 #ifdef FIXED_DEBUG_ASSERT
michael@0 249 silk_assert( 0 );
michael@0 250 #endif
michael@0 251 }
michael@0 252 return res;
michael@0 253 }
michael@0 254
michael@0 255 #undef silk_MUL
michael@0 256 #define silk_MUL(a,b) silk_MUL_((a), (b), __FILE__, __LINE__)
michael@0 257 static OPUS_INLINE opus_int32 silk_MUL_(opus_int32 a32, opus_int32 b32, char *file, int line){
michael@0 258 opus_int32 ret;
michael@0 259 opus_int64 ret64;
michael@0 260 ret = a32 * b32;
michael@0 261 ret64 = (opus_int64)a32 * (opus_int64)b32;
michael@0 262 if ( (opus_int64)ret != ret64 )
michael@0 263 {
michael@0 264 fprintf (stderr, "silk_MUL(%d, %d) in %s: line %d\n", a32, b32, file, line);
michael@0 265 #ifdef FIXED_DEBUG_ASSERT
michael@0 266 silk_assert( 0 );
michael@0 267 #endif
michael@0 268 }
michael@0 269 return ret;
michael@0 270 }
michael@0 271
michael@0 272 #undef silk_MUL_uint
michael@0 273 #define silk_MUL_uint(a,b) silk_MUL_uint_((a), (b), __FILE__, __LINE__)
michael@0 274 static OPUS_INLINE opus_uint32 silk_MUL_uint_(opus_uint32 a32, opus_uint32 b32, char *file, int line){
michael@0 275 opus_uint32 ret;
michael@0 276 ret = a32 * b32;
michael@0 277 if ( (opus_uint64)ret != (opus_uint64)a32 * (opus_uint64)b32 )
michael@0 278 {
michael@0 279 fprintf (stderr, "silk_MUL_uint(%u, %u) in %s: line %d\n", a32, b32, file, line);
michael@0 280 #ifdef FIXED_DEBUG_ASSERT
michael@0 281 silk_assert( 0 );
michael@0 282 #endif
michael@0 283 }
michael@0 284 return ret;
michael@0 285 }
michael@0 286
michael@0 287 #undef silk_MLA
michael@0 288 #define silk_MLA(a,b,c) silk_MLA_((a), (b), (c), __FILE__, __LINE__)
michael@0 289 static OPUS_INLINE opus_int32 silk_MLA_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
michael@0 290 opus_int32 ret;
michael@0 291 ret = a32 + b32 * c32;
michael@0 292 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int64)c32 )
michael@0 293 {
michael@0 294 fprintf (stderr, "silk_MLA(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
michael@0 295 #ifdef FIXED_DEBUG_ASSERT
michael@0 296 silk_assert( 0 );
michael@0 297 #endif
michael@0 298 }
michael@0 299 return ret;
michael@0 300 }
michael@0 301
michael@0 302 #undef silk_MLA_uint
michael@0 303 #define silk_MLA_uint(a,b,c) silk_MLA_uint_((a), (b), (c), __FILE__, __LINE__)
michael@0 304 static OPUS_INLINE opus_int32 silk_MLA_uint_(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32, char *file, int line){
michael@0 305 opus_uint32 ret;
michael@0 306 ret = a32 + b32 * c32;
michael@0 307 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int64)c32 )
michael@0 308 {
michael@0 309 fprintf (stderr, "silk_MLA_uint(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
michael@0 310 #ifdef FIXED_DEBUG_ASSERT
michael@0 311 silk_assert( 0 );
michael@0 312 #endif
michael@0 313 }
michael@0 314 return ret;
michael@0 315 }
michael@0 316
michael@0 317 #undef silk_SMULWB
michael@0 318 #define silk_SMULWB(a,b) silk_SMULWB_((a), (b), __FILE__, __LINE__)
michael@0 319 static OPUS_INLINE opus_int32 silk_SMULWB_(opus_int32 a32, opus_int32 b32, char *file, int line){
michael@0 320 opus_int32 ret;
michael@0 321 ret = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16);
michael@0 322 if ( (opus_int64)ret != ((opus_int64)a32 * (opus_int16)b32) >> 16 )
michael@0 323 {
michael@0 324 fprintf (stderr, "silk_SMULWB(%d, %d) in %s: line %d\n", a32, b32, file, line);
michael@0 325 #ifdef FIXED_DEBUG_ASSERT
michael@0 326 silk_assert( 0 );
michael@0 327 #endif
michael@0 328 }
michael@0 329 return ret;
michael@0 330 }
michael@0 331
michael@0 332 #undef silk_SMLAWB
michael@0 333 #define silk_SMLAWB(a,b,c) silk_SMLAWB_((a), (b), (c), __FILE__, __LINE__)
michael@0 334 static OPUS_INLINE opus_int32 silk_SMLAWB_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
michael@0 335 opus_int32 ret;
michael@0 336 ret = silk_ADD32( a32, silk_SMULWB( b32, c32 ) );
michael@0 337 if ( silk_ADD32( a32, silk_SMULWB( b32, c32 ) ) != silk_ADD_SAT32( a32, silk_SMULWB( b32, c32 ) ) )
michael@0 338 {
michael@0 339 fprintf (stderr, "silk_SMLAWB(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
michael@0 340 #ifdef FIXED_DEBUG_ASSERT
michael@0 341 silk_assert( 0 );
michael@0 342 #endif
michael@0 343 }
michael@0 344 return ret;
michael@0 345 }
michael@0 346
michael@0 347 #undef silk_SMULWT
michael@0 348 #define silk_SMULWT(a,b) silk_SMULWT_((a), (b), __FILE__, __LINE__)
michael@0 349 static OPUS_INLINE opus_int32 silk_SMULWT_(opus_int32 a32, opus_int32 b32, char *file, int line){
michael@0 350 opus_int32 ret;
michael@0 351 ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16);
michael@0 352 if ( (opus_int64)ret != ((opus_int64)a32 * (b32 >> 16)) >> 16 )
michael@0 353 {
michael@0 354 fprintf (stderr, "silk_SMULWT(%d, %d) in %s: line %d\n", a32, b32, file, line);
michael@0 355 #ifdef FIXED_DEBUG_ASSERT
michael@0 356 silk_assert( 0 );
michael@0 357 #endif
michael@0 358 }
michael@0 359 return ret;
michael@0 360 }
michael@0 361
michael@0 362 #undef silk_SMLAWT
michael@0 363 #define silk_SMLAWT(a,b,c) silk_SMLAWT_((a), (b), (c), __FILE__, __LINE__)
michael@0 364 static OPUS_INLINE opus_int32 silk_SMLAWT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
michael@0 365 opus_int32 ret;
michael@0 366 ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16));
michael@0 367 if ( (opus_int64)ret != (opus_int64)a32 + (((opus_int64)b32 * (c32 >> 16)) >> 16) )
michael@0 368 {
michael@0 369 fprintf (stderr, "silk_SMLAWT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
michael@0 370 #ifdef FIXED_DEBUG_ASSERT
michael@0 371 silk_assert( 0 );
michael@0 372 #endif
michael@0 373 }
michael@0 374 return ret;
michael@0 375 }
michael@0 376
michael@0 377 #undef silk_SMULL
michael@0 378 #define silk_SMULL(a,b) silk_SMULL_((a), (b), __FILE__, __LINE__)
michael@0 379 static OPUS_INLINE opus_int64 silk_SMULL_(opus_int64 a64, opus_int64 b64, char *file, int line){
michael@0 380 opus_int64 ret64;
michael@0 381 int fail = 0;
michael@0 382 ret64 = a64 * b64;
michael@0 383 if( b64 != 0 ) {
michael@0 384 fail = a64 != (ret64 / b64);
michael@0 385 } else if( a64 != 0 ) {
michael@0 386 fail = b64 != (ret64 / a64);
michael@0 387 }
michael@0 388 if ( fail )
michael@0 389 {
michael@0 390 fprintf (stderr, "silk_SMULL(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line);
michael@0 391 #ifdef FIXED_DEBUG_ASSERT
michael@0 392 silk_assert( 0 );
michael@0 393 #endif
michael@0 394 }
michael@0 395 return ret64;
michael@0 396 }
michael@0 397
michael@0 398 /* no checking needed for silk_SMULBB */
michael@0 399 #undef silk_SMLABB
michael@0 400 #define silk_SMLABB(a,b,c) silk_SMLABB_((a), (b), (c), __FILE__, __LINE__)
michael@0 401 static OPUS_INLINE opus_int32 silk_SMLABB_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
michael@0 402 opus_int32 ret;
michael@0 403 ret = a32 + (opus_int32)((opus_int16)b32) * (opus_int32)((opus_int16)c32);
michael@0 404 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int16)c32 )
michael@0 405 {
michael@0 406 fprintf (stderr, "silk_SMLABB(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
michael@0 407 #ifdef FIXED_DEBUG_ASSERT
michael@0 408 silk_assert( 0 );
michael@0 409 #endif
michael@0 410 }
michael@0 411 return ret;
michael@0 412 }
michael@0 413
michael@0 414 /* no checking needed for silk_SMULBT */
michael@0 415 #undef silk_SMLABT
michael@0 416 #define silk_SMLABT(a,b,c) silk_SMLABT_((a), (b), (c), __FILE__, __LINE__)
michael@0 417 static OPUS_INLINE opus_int32 silk_SMLABT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
michael@0 418 opus_int32 ret;
michael@0 419 ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16);
michael@0 420 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (c32 >> 16) )
michael@0 421 {
michael@0 422 fprintf (stderr, "silk_SMLABT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
michael@0 423 #ifdef FIXED_DEBUG_ASSERT
michael@0 424 silk_assert( 0 );
michael@0 425 #endif
michael@0 426 }
michael@0 427 return ret;
michael@0 428 }
michael@0 429
michael@0 430 /* no checking needed for silk_SMULTT */
michael@0 431 #undef silk_SMLATT
michael@0 432 #define silk_SMLATT(a,b,c) silk_SMLATT_((a), (b), (c), __FILE__, __LINE__)
michael@0 433 static OPUS_INLINE opus_int32 silk_SMLATT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
michael@0 434 opus_int32 ret;
michael@0 435 ret = a32 + (b32 >> 16) * (c32 >> 16);
michael@0 436 if ( (opus_int64)ret != (opus_int64)a32 + (b32 >> 16) * (c32 >> 16) )
michael@0 437 {
michael@0 438 fprintf (stderr, "silk_SMLATT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
michael@0 439 #ifdef FIXED_DEBUG_ASSERT
michael@0 440 silk_assert( 0 );
michael@0 441 #endif
michael@0 442 }
michael@0 443 return ret;
michael@0 444 }
michael@0 445
michael@0 446 #undef silk_SMULWW
michael@0 447 #define silk_SMULWW(a,b) silk_SMULWW_((a), (b), __FILE__, __LINE__)
michael@0 448 static OPUS_INLINE opus_int32 silk_SMULWW_(opus_int32 a32, opus_int32 b32, char *file, int line){
michael@0 449 opus_int32 ret, tmp1, tmp2;
michael@0 450 opus_int64 ret64;
michael@0 451 int fail = 0;
michael@0 452
michael@0 453 ret = silk_SMULWB( a32, b32 );
michael@0 454 tmp1 = silk_RSHIFT_ROUND( b32, 16 );
michael@0 455 tmp2 = silk_MUL( a32, tmp1 );
michael@0 456
michael@0 457 fail |= (opus_int64)tmp2 != (opus_int64) a32 * (opus_int64) tmp1;
michael@0 458
michael@0 459 tmp1 = ret;
michael@0 460 ret = silk_ADD32( tmp1, tmp2 );
michael@0 461 fail |= silk_ADD32( tmp1, tmp2 ) != silk_ADD_SAT32( tmp1, tmp2 );
michael@0 462
michael@0 463 ret64 = silk_RSHIFT64( silk_SMULL( a32, b32 ), 16 );
michael@0 464 fail |= (opus_int64)ret != ret64;
michael@0 465
michael@0 466 if ( fail )
michael@0 467 {
michael@0 468 fprintf (stderr, "silk_SMULWT(%d, %d) in %s: line %d\n", a32, b32, file, line);
michael@0 469 #ifdef FIXED_DEBUG_ASSERT
michael@0 470 silk_assert( 0 );
michael@0 471 #endif
michael@0 472 }
michael@0 473
michael@0 474 return ret;
michael@0 475 }
michael@0 476
michael@0 477 #undef silk_SMLAWW
michael@0 478 #define silk_SMLAWW(a,b,c) silk_SMLAWW_((a), (b), (c), __FILE__, __LINE__)
michael@0 479 static OPUS_INLINE opus_int32 silk_SMLAWW_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
michael@0 480 opus_int32 ret, tmp;
michael@0 481
michael@0 482 tmp = silk_SMULWW( b32, c32 );
michael@0 483 ret = silk_ADD32( a32, tmp );
michael@0 484 if ( ret != silk_ADD_SAT32( a32, tmp ) )
michael@0 485 {
michael@0 486 fprintf (stderr, "silk_SMLAWW(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
michael@0 487 #ifdef FIXED_DEBUG_ASSERT
michael@0 488 silk_assert( 0 );
michael@0 489 #endif
michael@0 490 }
michael@0 491 return ret;
michael@0 492 }
michael@0 493
michael@0 494 /* Multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode) */
michael@0 495 #undef silk_MLA_ovflw
michael@0 496 #define silk_MLA_ovflw(a32, b32, c32) ((a32) + ((b32) * (c32)))
michael@0 497 #undef silk_SMLABB_ovflw
michael@0 498 #define silk_SMLABB_ovflw(a32, b32, c32) ((a32) + ((opus_int32)((opus_int16)(b32))) * (opus_int32)((opus_int16)(c32)))
michael@0 499
michael@0 500 /* no checking needed for silk_SMULL
michael@0 501 no checking needed for silk_SMLAL
michael@0 502 no checking needed for silk_SMLALBB
michael@0 503 no checking needed for SigProcFIX_CLZ16
michael@0 504 no checking needed for SigProcFIX_CLZ32*/
michael@0 505
michael@0 506 #undef silk_DIV32
michael@0 507 #define silk_DIV32(a,b) silk_DIV32_((a), (b), __FILE__, __LINE__)
michael@0 508 static OPUS_INLINE opus_int32 silk_DIV32_(opus_int32 a32, opus_int32 b32, char *file, int line){
michael@0 509 if ( b32 == 0 )
michael@0 510 {
michael@0 511 fprintf (stderr, "silk_DIV32(%d, %d) in %s: line %d\n", a32, b32, file, line);
michael@0 512 #ifdef FIXED_DEBUG_ASSERT
michael@0 513 silk_assert( 0 );
michael@0 514 #endif
michael@0 515 }
michael@0 516 return a32 / b32;
michael@0 517 }
michael@0 518
michael@0 519 #undef silk_DIV32_16
michael@0 520 #define silk_DIV32_16(a,b) silk_DIV32_16_((a), (b), __FILE__, __LINE__)
michael@0 521 static OPUS_INLINE opus_int32 silk_DIV32_16_(opus_int32 a32, opus_int32 b32, char *file, int line){
michael@0 522 int fail = 0;
michael@0 523 fail |= b32 == 0;
michael@0 524 fail |= b32 > silk_int16_MAX;
michael@0 525 fail |= b32 < silk_int16_MIN;
michael@0 526 if ( fail )
michael@0 527 {
michael@0 528 fprintf (stderr, "silk_DIV32_16(%d, %d) in %s: line %d\n", a32, b32, file, line);
michael@0 529 #ifdef FIXED_DEBUG_ASSERT
michael@0 530 silk_assert( 0 );
michael@0 531 #endif
michael@0 532 }
michael@0 533 return a32 / b32;
michael@0 534 }
michael@0 535
michael@0 536 /* no checking needed for silk_SAT8
michael@0 537 no checking needed for silk_SAT16
michael@0 538 no checking needed for silk_SAT32
michael@0 539 no checking needed for silk_POS_SAT32
michael@0 540 no checking needed for silk_ADD_POS_SAT8
michael@0 541 no checking needed for silk_ADD_POS_SAT16
michael@0 542 no checking needed for silk_ADD_POS_SAT32
michael@0 543 no checking needed for silk_ADD_POS_SAT64 */
michael@0 544
michael@0 545 #undef silk_LSHIFT8
michael@0 546 #define silk_LSHIFT8(a,b) silk_LSHIFT8_((a), (b), __FILE__, __LINE__)
michael@0 547 static OPUS_INLINE opus_int8 silk_LSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line){
michael@0 548 opus_int8 ret;
michael@0 549 int fail = 0;
michael@0 550 ret = a << shift;
michael@0 551 fail |= shift < 0;
michael@0 552 fail |= shift >= 8;
michael@0 553 fail |= (opus_int64)ret != ((opus_int64)a) << shift;
michael@0 554 if ( fail )
michael@0 555 {
michael@0 556 fprintf (stderr, "silk_LSHIFT8(%d, %d) in %s: line %d\n", a, shift, file, line);
michael@0 557 #ifdef FIXED_DEBUG_ASSERT
michael@0 558 silk_assert( 0 );
michael@0 559 #endif
michael@0 560 }
michael@0 561 return ret;
michael@0 562 }
michael@0 563
michael@0 564 #undef silk_LSHIFT16
michael@0 565 #define silk_LSHIFT16(a,b) silk_LSHIFT16_((a), (b), __FILE__, __LINE__)
michael@0 566 static OPUS_INLINE opus_int16 silk_LSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line){
michael@0 567 opus_int16 ret;
michael@0 568 int fail = 0;
michael@0 569 ret = a << shift;
michael@0 570 fail |= shift < 0;
michael@0 571 fail |= shift >= 16;
michael@0 572 fail |= (opus_int64)ret != ((opus_int64)a) << shift;
michael@0 573 if ( fail )
michael@0 574 {
michael@0 575 fprintf (stderr, "silk_LSHIFT16(%d, %d) in %s: line %d\n", a, shift, file, line);
michael@0 576 #ifdef FIXED_DEBUG_ASSERT
michael@0 577 silk_assert( 0 );
michael@0 578 #endif
michael@0 579 }
michael@0 580 return ret;
michael@0 581 }
michael@0 582
michael@0 583 #undef silk_LSHIFT32
michael@0 584 #define silk_LSHIFT32(a,b) silk_LSHIFT32_((a), (b), __FILE__, __LINE__)
michael@0 585 static OPUS_INLINE opus_int32 silk_LSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line){
michael@0 586 opus_int32 ret;
michael@0 587 int fail = 0;
michael@0 588 ret = a << shift;
michael@0 589 fail |= shift < 0;
michael@0 590 fail |= shift >= 32;
michael@0 591 fail |= (opus_int64)ret != ((opus_int64)a) << shift;
michael@0 592 if ( fail )
michael@0 593 {
michael@0 594 fprintf (stderr, "silk_LSHIFT32(%d, %d) in %s: line %d\n", a, shift, file, line);
michael@0 595 #ifdef FIXED_DEBUG_ASSERT
michael@0 596 silk_assert( 0 );
michael@0 597 #endif
michael@0 598 }
michael@0 599 return ret;
michael@0 600 }
michael@0 601
michael@0 602 #undef silk_LSHIFT64
michael@0 603 #define silk_LSHIFT64(a,b) silk_LSHIFT64_((a), (b), __FILE__, __LINE__)
michael@0 604 static OPUS_INLINE opus_int64 silk_LSHIFT64_(opus_int64 a, opus_int shift, char *file, int line){
michael@0 605 opus_int64 ret;
michael@0 606 int fail = 0;
michael@0 607 ret = a << shift;
michael@0 608 fail |= shift < 0;
michael@0 609 fail |= shift >= 64;
michael@0 610 fail |= (ret>>shift) != ((opus_int64)a);
michael@0 611 if ( fail )
michael@0 612 {
michael@0 613 fprintf (stderr, "silk_LSHIFT64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line);
michael@0 614 #ifdef FIXED_DEBUG_ASSERT
michael@0 615 silk_assert( 0 );
michael@0 616 #endif
michael@0 617 }
michael@0 618 return ret;
michael@0 619 }
michael@0 620
michael@0 621 #undef silk_LSHIFT_ovflw
michael@0 622 #define silk_LSHIFT_ovflw(a,b) silk_LSHIFT_ovflw_((a), (b), __FILE__, __LINE__)
michael@0 623 static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw_(opus_int32 a, opus_int32 shift, char *file, int line){
michael@0 624 if ( (shift < 0) || (shift >= 32) ) /* no check for overflow */
michael@0 625 {
michael@0 626 fprintf (stderr, "silk_LSHIFT_ovflw(%d, %d) in %s: line %d\n", a, shift, file, line);
michael@0 627 #ifdef FIXED_DEBUG_ASSERT
michael@0 628 silk_assert( 0 );
michael@0 629 #endif
michael@0 630 }
michael@0 631 return a << shift;
michael@0 632 }
michael@0 633
michael@0 634 #undef silk_LSHIFT_uint
michael@0 635 #define silk_LSHIFT_uint(a,b) silk_LSHIFT_uint_((a), (b), __FILE__, __LINE__)
michael@0 636 static OPUS_INLINE opus_uint32 silk_LSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line){
michael@0 637 opus_uint32 ret;
michael@0 638 ret = a << shift;
michael@0 639 if ( (shift < 0) || ((opus_int64)ret != ((opus_int64)a) << shift))
michael@0 640 {
michael@0 641 fprintf (stderr, "silk_LSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line);
michael@0 642 #ifdef FIXED_DEBUG_ASSERT
michael@0 643 silk_assert( 0 );
michael@0 644 #endif
michael@0 645 }
michael@0 646 return ret;
michael@0 647 }
michael@0 648
michael@0 649 #undef silk_RSHIFT8
michael@0 650 #define silk_RSHITF8(a,b) silk_RSHIFT8_((a), (b), __FILE__, __LINE__)
michael@0 651 static OPUS_INLINE opus_int8 silk_RSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line){
michael@0 652 if ( (shift < 0) || (shift>=8) )
michael@0 653 {
michael@0 654 fprintf (stderr, "silk_RSHITF8(%d, %d) in %s: line %d\n", a, shift, file, line);
michael@0 655 #ifdef FIXED_DEBUG_ASSERT
michael@0 656 silk_assert( 0 );
michael@0 657 #endif
michael@0 658 }
michael@0 659 return a >> shift;
michael@0 660 }
michael@0 661
michael@0 662 #undef silk_RSHIFT16
michael@0 663 #define silk_RSHITF16(a,b) silk_RSHIFT16_((a), (b), __FILE__, __LINE__)
michael@0 664 static OPUS_INLINE opus_int16 silk_RSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line){
michael@0 665 if ( (shift < 0) || (shift>=16) )
michael@0 666 {
michael@0 667 fprintf (stderr, "silk_RSHITF16(%d, %d) in %s: line %d\n", a, shift, file, line);
michael@0 668 #ifdef FIXED_DEBUG_ASSERT
michael@0 669 silk_assert( 0 );
michael@0 670 #endif
michael@0 671 }
michael@0 672 return a >> shift;
michael@0 673 }
michael@0 674
michael@0 675 #undef silk_RSHIFT32
michael@0 676 #define silk_RSHIFT32(a,b) silk_RSHIFT32_((a), (b), __FILE__, __LINE__)
michael@0 677 static OPUS_INLINE opus_int32 silk_RSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line){
michael@0 678 if ( (shift < 0) || (shift>=32) )
michael@0 679 {
michael@0 680 fprintf (stderr, "silk_RSHITF32(%d, %d) in %s: line %d\n", a, shift, file, line);
michael@0 681 #ifdef FIXED_DEBUG_ASSERT
michael@0 682 silk_assert( 0 );
michael@0 683 #endif
michael@0 684 }
michael@0 685 return a >> shift;
michael@0 686 }
michael@0 687
michael@0 688 #undef silk_RSHIFT64
michael@0 689 #define silk_RSHIFT64(a,b) silk_RSHIFT64_((a), (b), __FILE__, __LINE__)
michael@0 690 static OPUS_INLINE opus_int64 silk_RSHIFT64_(opus_int64 a, opus_int64 shift, char *file, int line){
michael@0 691 if ( (shift < 0) || (shift>=64) )
michael@0 692 {
michael@0 693 fprintf (stderr, "silk_RSHITF64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)shift, file, line);
michael@0 694 #ifdef FIXED_DEBUG_ASSERT
michael@0 695 silk_assert( 0 );
michael@0 696 #endif
michael@0 697 }
michael@0 698 return a >> shift;
michael@0 699 }
michael@0 700
michael@0 701 #undef silk_RSHIFT_uint
michael@0 702 #define silk_RSHIFT_uint(a,b) silk_RSHIFT_uint_((a), (b), __FILE__, __LINE__)
michael@0 703 static OPUS_INLINE opus_uint32 silk_RSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line){
michael@0 704 if ( (shift < 0) || (shift>32) )
michael@0 705 {
michael@0 706 fprintf (stderr, "silk_RSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line);
michael@0 707 #ifdef FIXED_DEBUG_ASSERT
michael@0 708 silk_assert( 0 );
michael@0 709 #endif
michael@0 710 }
michael@0 711 return a >> shift;
michael@0 712 }
michael@0 713
michael@0 714 #undef silk_ADD_LSHIFT
michael@0 715 #define silk_ADD_LSHIFT(a,b,c) silk_ADD_LSHIFT_((a), (b), (c), __FILE__, __LINE__)
michael@0 716 static OPUS_INLINE int silk_ADD_LSHIFT_(int a, int b, int shift, char *file, int line){
michael@0 717 opus_int16 ret;
michael@0 718 ret = a + (b << shift);
michael@0 719 if ( (shift < 0) || (shift>15) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift)) )
michael@0 720 {
michael@0 721 fprintf (stderr, "silk_ADD_LSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
michael@0 722 #ifdef FIXED_DEBUG_ASSERT
michael@0 723 silk_assert( 0 );
michael@0 724 #endif
michael@0 725 }
michael@0 726 return ret; /* shift >= 0 */
michael@0 727 }
michael@0 728
michael@0 729 #undef silk_ADD_LSHIFT32
michael@0 730 #define silk_ADD_LSHIFT32(a,b,c) silk_ADD_LSHIFT32_((a), (b), (c), __FILE__, __LINE__)
michael@0 731 static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
michael@0 732 opus_int32 ret;
michael@0 733 ret = a + (b << shift);
michael@0 734 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift)) )
michael@0 735 {
michael@0 736 fprintf (stderr, "silk_ADD_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
michael@0 737 #ifdef FIXED_DEBUG_ASSERT
michael@0 738 silk_assert( 0 );
michael@0 739 #endif
michael@0 740 }
michael@0 741 return ret; /* shift >= 0 */
michael@0 742 }
michael@0 743
michael@0 744 #undef silk_ADD_LSHIFT_uint
michael@0 745 #define silk_ADD_LSHIFT_uint(a,b,c) silk_ADD_LSHIFT_uint_((a), (b), (c), __FILE__, __LINE__)
michael@0 746 static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line){
michael@0 747 opus_uint32 ret;
michael@0 748 ret = a + (b << shift);
michael@0 749 if ( (shift < 0) || (shift>32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift)) )
michael@0 750 {
michael@0 751 fprintf (stderr, "silk_ADD_LSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line);
michael@0 752 #ifdef FIXED_DEBUG_ASSERT
michael@0 753 silk_assert( 0 );
michael@0 754 #endif
michael@0 755 }
michael@0 756 return ret; /* shift >= 0 */
michael@0 757 }
michael@0 758
michael@0 759 #undef silk_ADD_RSHIFT
michael@0 760 #define silk_ADD_RSHIFT(a,b,c) silk_ADD_RSHIFT_((a), (b), (c), __FILE__, __LINE__)
michael@0 761 static OPUS_INLINE int silk_ADD_RSHIFT_(int a, int b, int shift, char *file, int line){
michael@0 762 opus_int16 ret;
michael@0 763 ret = a + (b >> shift);
michael@0 764 if ( (shift < 0) || (shift>15) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
michael@0 765 {
michael@0 766 fprintf (stderr, "silk_ADD_RSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
michael@0 767 #ifdef FIXED_DEBUG_ASSERT
michael@0 768 silk_assert( 0 );
michael@0 769 #endif
michael@0 770 }
michael@0 771 return ret; /* shift > 0 */
michael@0 772 }
michael@0 773
michael@0 774 #undef silk_ADD_RSHIFT32
michael@0 775 #define silk_ADD_RSHIFT32(a,b,c) silk_ADD_RSHIFT32_((a), (b), (c), __FILE__, __LINE__)
michael@0 776 static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
michael@0 777 opus_int32 ret;
michael@0 778 ret = a + (b >> shift);
michael@0 779 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
michael@0 780 {
michael@0 781 fprintf (stderr, "silk_ADD_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
michael@0 782 #ifdef FIXED_DEBUG_ASSERT
michael@0 783 silk_assert( 0 );
michael@0 784 #endif
michael@0 785 }
michael@0 786 return ret; /* shift > 0 */
michael@0 787 }
michael@0 788
michael@0 789 #undef silk_ADD_RSHIFT_uint
michael@0 790 #define silk_ADD_RSHIFT_uint(a,b,c) silk_ADD_RSHIFT_uint_((a), (b), (c), __FILE__, __LINE__)
michael@0 791 static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line){
michael@0 792 opus_uint32 ret;
michael@0 793 ret = a + (b >> shift);
michael@0 794 if ( (shift < 0) || (shift>32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
michael@0 795 {
michael@0 796 fprintf (stderr, "silk_ADD_RSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line);
michael@0 797 #ifdef FIXED_DEBUG_ASSERT
michael@0 798 silk_assert( 0 );
michael@0 799 #endif
michael@0 800 }
michael@0 801 return ret; /* shift > 0 */
michael@0 802 }
michael@0 803
michael@0 804 #undef silk_SUB_LSHIFT32
michael@0 805 #define silk_SUB_LSHIFT32(a,b,c) silk_SUB_LSHIFT32_((a), (b), (c), __FILE__, __LINE__)
michael@0 806 static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
michael@0 807 opus_int32 ret;
michael@0 808 ret = a - (b << shift);
michael@0 809 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a - (((opus_int64)b) << shift)) )
michael@0 810 {
michael@0 811 fprintf (stderr, "silk_SUB_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
michael@0 812 #ifdef FIXED_DEBUG_ASSERT
michael@0 813 silk_assert( 0 );
michael@0 814 #endif
michael@0 815 }
michael@0 816 return ret; /* shift >= 0 */
michael@0 817 }
michael@0 818
michael@0 819 #undef silk_SUB_RSHIFT32
michael@0 820 #define silk_SUB_RSHIFT32(a,b,c) silk_SUB_RSHIFT32_((a), (b), (c), __FILE__, __LINE__)
michael@0 821 static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
michael@0 822 opus_int32 ret;
michael@0 823 ret = a - (b >> shift);
michael@0 824 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a - (((opus_int64)b) >> shift)) )
michael@0 825 {
michael@0 826 fprintf (stderr, "silk_SUB_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
michael@0 827 #ifdef FIXED_DEBUG_ASSERT
michael@0 828 silk_assert( 0 );
michael@0 829 #endif
michael@0 830 }
michael@0 831 return ret; /* shift > 0 */
michael@0 832 }
michael@0 833
michael@0 834 #undef silk_RSHIFT_ROUND
michael@0 835 #define silk_RSHIFT_ROUND(a,b) silk_RSHIFT_ROUND_((a), (b), __FILE__, __LINE__)
michael@0 836 static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND_(opus_int32 a, opus_int32 shift, char *file, int line){
michael@0 837 opus_int32 ret;
michael@0 838 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
michael@0 839 /* the marco definition can't handle a shift of zero */
michael@0 840 if ( (shift <= 0) || (shift>31) || ((opus_int64)ret != ((opus_int64)a + ((opus_int64)1 << (shift - 1))) >> shift) )
michael@0 841 {
michael@0 842 fprintf (stderr, "silk_RSHIFT_ROUND(%d, %d) in %s: line %d\n", a, shift, file, line);
michael@0 843 #ifdef FIXED_DEBUG_ASSERT
michael@0 844 silk_assert( 0 );
michael@0 845 #endif
michael@0 846 }
michael@0 847 return ret;
michael@0 848 }
michael@0 849
michael@0 850 #undef silk_RSHIFT_ROUND64
michael@0 851 #define silk_RSHIFT_ROUND64(a,b) silk_RSHIFT_ROUND64_((a), (b), __FILE__, __LINE__)
michael@0 852 static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64_(opus_int64 a, opus_int32 shift, char *file, int line){
michael@0 853 opus_int64 ret;
michael@0 854 /* the marco definition can't handle a shift of zero */
michael@0 855 if ( (shift <= 0) || (shift>=64) )
michael@0 856 {
michael@0 857 fprintf (stderr, "silk_RSHIFT_ROUND64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line);
michael@0 858 #ifdef FIXED_DEBUG_ASSERT
michael@0 859 silk_assert( 0 );
michael@0 860 #endif
michael@0 861 }
michael@0 862 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
michael@0 863 return ret;
michael@0 864 }
michael@0 865
michael@0 866 /* silk_abs is used on floats also, so doesn't work... */
michael@0 867 /*#undef silk_abs
michael@0 868 static OPUS_INLINE opus_int32 silk_abs(opus_int32 a){
michael@0 869 silk_assert(a != 0x80000000);
michael@0 870 return (((a) > 0) ? (a) : -(a)); // Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN
michael@0 871 }*/
michael@0 872
michael@0 873 #undef silk_abs_int64
michael@0 874 #define silk_abs_int64(a) silk_abs_int64_((a), __FILE__, __LINE__)
michael@0 875 static OPUS_INLINE opus_int64 silk_abs_int64_(opus_int64 a, char *file, int line){
michael@0 876 if ( a == silk_int64_MIN )
michael@0 877 {
michael@0 878 fprintf (stderr, "silk_abs_int64(%lld) in %s: line %d\n", (long long)a, file, line);
michael@0 879 #ifdef FIXED_DEBUG_ASSERT
michael@0 880 silk_assert( 0 );
michael@0 881 #endif
michael@0 882 }
michael@0 883 return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN */
michael@0 884 }
michael@0 885
michael@0 886 #undef silk_abs_int32
michael@0 887 #define silk_abs_int32(a) silk_abs_int32_((a), __FILE__, __LINE__)
michael@0 888 static OPUS_INLINE opus_int32 silk_abs_int32_(opus_int32 a, char *file, int line){
michael@0 889 if ( a == silk_int32_MIN )
michael@0 890 {
michael@0 891 fprintf (stderr, "silk_abs_int32(%d) in %s: line %d\n", a, file, line);
michael@0 892 #ifdef FIXED_DEBUG_ASSERT
michael@0 893 silk_assert( 0 );
michael@0 894 #endif
michael@0 895 }
michael@0 896 return silk_abs(a);
michael@0 897 }
michael@0 898
michael@0 899 #undef silk_CHECK_FIT8
michael@0 900 #define silk_CHECK_FIT8(a) silk_CHECK_FIT8_((a), __FILE__, __LINE__)
michael@0 901 static OPUS_INLINE opus_int8 silk_CHECK_FIT8_( opus_int64 a, char *file, int line ){
michael@0 902 opus_int8 ret;
michael@0 903 ret = (opus_int8)a;
michael@0 904 if ( (opus_int64)ret != a )
michael@0 905 {
michael@0 906 fprintf (stderr, "silk_CHECK_FIT8(%lld) in %s: line %d\n", (long long)a, file, line);
michael@0 907 #ifdef FIXED_DEBUG_ASSERT
michael@0 908 silk_assert( 0 );
michael@0 909 #endif
michael@0 910 }
michael@0 911 return( ret );
michael@0 912 }
michael@0 913
michael@0 914 #undef silk_CHECK_FIT16
michael@0 915 #define silk_CHECK_FIT16(a) silk_CHECK_FIT16_((a), __FILE__, __LINE__)
michael@0 916 static OPUS_INLINE opus_int16 silk_CHECK_FIT16_( opus_int64 a, char *file, int line ){
michael@0 917 opus_int16 ret;
michael@0 918 ret = (opus_int16)a;
michael@0 919 if ( (opus_int64)ret != a )
michael@0 920 {
michael@0 921 fprintf (stderr, "silk_CHECK_FIT16(%lld) in %s: line %d\n", (long long)a, file, line);
michael@0 922 #ifdef FIXED_DEBUG_ASSERT
michael@0 923 silk_assert( 0 );
michael@0 924 #endif
michael@0 925 }
michael@0 926 return( ret );
michael@0 927 }
michael@0 928
michael@0 929 #undef silk_CHECK_FIT32
michael@0 930 #define silk_CHECK_FIT32(a) silk_CHECK_FIT32_((a), __FILE__, __LINE__)
michael@0 931 static OPUS_INLINE opus_int32 silk_CHECK_FIT32_( opus_int64 a, char *file, int line ){
michael@0 932 opus_int32 ret;
michael@0 933 ret = (opus_int32)a;
michael@0 934 if ( (opus_int64)ret != a )
michael@0 935 {
michael@0 936 fprintf (stderr, "silk_CHECK_FIT32(%lld) in %s: line %d\n", (long long)a, file, line);
michael@0 937 #ifdef FIXED_DEBUG_ASSERT
michael@0 938 silk_assert( 0 );
michael@0 939 #endif
michael@0 940 }
michael@0 941 return( ret );
michael@0 942 }
michael@0 943
michael@0 944 /* no checking for silk_NSHIFT_MUL_32_32
michael@0 945 no checking for silk_NSHIFT_MUL_16_16
michael@0 946 no checking needed for silk_min
michael@0 947 no checking needed for silk_max
michael@0 948 no checking needed for silk_sign
michael@0 949 */
michael@0 950
michael@0 951 #endif
michael@0 952 #endif /* MACRO_DEBUG_H */

mercurial