| OLD | NEW |
| 1 /* Copyright (C) 2003-2008 Jean-Marc Valin | 1 /* Copyright (C) 2003-2008 Jean-Marc Valin |
| 2 Copyright (C) 2007-2012 Xiph.Org Foundation */ | 2 Copyright (C) 2007-2012 Xiph.Org Foundation */ |
| 3 /** | 3 /** |
| 4 @file fixed_debug.h | 4 @file fixed_debug.h |
| 5 @brief Fixed-point operations with debugging | 5 @brief Fixed-point operations with debugging |
| 6 */ | 6 */ |
| 7 /* | 7 /* |
| 8 Redistribution and use in source and binary forms, with or without | 8 Redistribution and use in source and binary forms, with or without |
| 9 modification, are permitted provided that the following conditions | 9 modification, are permitted provided that the following conditions |
| 10 are met: | 10 are met: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits)))) | 52 #define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits)))) |
| 53 #define QCONST32(x,bits) ((opus_val32)(.5+(x)*(((opus_val32)1)<<(bits)))) | 53 #define QCONST32(x,bits) ((opus_val32)(.5+(x)*(((opus_val32)1)<<(bits)))) |
| 54 | 54 |
| 55 #define VERIFY_SHORT(x) ((x)<=32767&&(x)>=-32768) | 55 #define VERIFY_SHORT(x) ((x)<=32767&&(x)>=-32768) |
| 56 #define VERIFY_INT(x) ((x)<=2147483647LL&&(x)>=-2147483648LL) | 56 #define VERIFY_INT(x) ((x)<=2147483647LL&&(x)>=-2147483648LL) |
| 57 #define VERIFY_UINT(x) ((x)<=(2147483647LLU<<1)) | 57 #define VERIFY_UINT(x) ((x)<=(2147483647LLU<<1)) |
| 58 | 58 |
| 59 #define SHR(a,b) SHR32(a,b) | 59 #define SHR(a,b) SHR32(a,b) |
| 60 #define PSHR(a,b) PSHR32(a,b) | 60 #define PSHR(a,b) PSHR32(a,b) |
| 61 | 61 |
| 62 /** Add two 32-bit values, ignore any overflows */ |
| 63 #define ADD32_ovflw(a,b) (celt_mips+=2,(opus_val32)((opus_uint32)(a)+(opus_uint3
2)(b))) |
| 64 /** Subtract two 32-bit values, ignore any overflows */ |
| 65 #define SUB32_ovflw(a,b) (celt_mips+=2,(opus_val32)((opus_uint32)(a)-(opus_uint3
2)(b))) |
| 66 /* Avoid MSVC warning C4146: unary minus operator applied to unsigned type */ |
| 67 /** Negate 32-bit value, ignore any overflows */ |
| 68 #define NEG32_ovflw(a) (celt_mips+=2,(opus_val32)(0-(opus_uint32)(a))) |
| 69 |
| 62 static OPUS_INLINE short NEG16(int x) | 70 static OPUS_INLINE short NEG16(int x) |
| 63 { | 71 { |
| 64 int res; | 72 int res; |
| 65 if (!VERIFY_SHORT(x)) | 73 if (!VERIFY_SHORT(x)) |
| 66 { | 74 { |
| 67 fprintf (stderr, "NEG16: input is not short: %d\n", (int)x); | 75 fprintf (stderr, "NEG16: input is not short: %d\n", (int)x); |
| 68 #ifdef FIXED_DEBUG_ASSERT | 76 #ifdef FIXED_DEBUG_ASSERT |
| 69 celt_assert(0); | 77 celt_assert(0); |
| 70 #endif | 78 #endif |
| 71 } | 79 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 #endif | 228 #endif |
| 221 } | 229 } |
| 222 celt_mips+=2; | 230 celt_mips+=2; |
| 223 return res; | 231 return res; |
| 224 } | 232 } |
| 225 | 233 |
| 226 #define PSHR32(a,shift) (celt_mips--,SHR32(ADD32((a),(((opus_val32)(1)<<((shift)
)>>1))),shift)) | 234 #define PSHR32(a,shift) (celt_mips--,SHR32(ADD32((a),(((opus_val32)(1)<<((shift)
)>>1))),shift)) |
| 227 #define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) | 235 #define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) |
| 228 | 236 |
| 229 #define ROUND16(x,a) (celt_mips--,EXTRACT16(PSHR32((x),(a)))) | 237 #define ROUND16(x,a) (celt_mips--,EXTRACT16(PSHR32((x),(a)))) |
| 238 #define SROUND16(x,a) (celt_mips--,EXTRACT16(SATURATE(PSHR32(x,a), 32767))); |
| 239 |
| 230 #define HALF16(x) (SHR16(x,1)) | 240 #define HALF16(x) (SHR16(x,1)) |
| 231 #define HALF32(x) (SHR32(x,1)) | 241 #define HALF32(x) (SHR32(x,1)) |
| 232 | 242 |
| 233 //#define SHR(a,shift) ((a) >> (shift)) | |
| 234 //#define SHL(a,shift) ((a) << (shift)) | |
| 235 | |
| 236 #define ADD16(a, b) ADD16_(a, b, __FILE__, __LINE__) | 243 #define ADD16(a, b) ADD16_(a, b, __FILE__, __LINE__) |
| 237 static OPUS_INLINE short ADD16_(int a, int b, char *file, int line) | 244 static OPUS_INLINE short ADD16_(int a, int b, char *file, int line) |
| 238 { | 245 { |
| 239 int res; | 246 int res; |
| 240 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) | 247 if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b)) |
| 241 { | 248 { |
| 242 fprintf (stderr, "ADD16: inputs are not short: %d %d in %s: line %d\n", a,
b, file, line); | 249 fprintf (stderr, "ADD16: inputs are not short: %d %d in %s: line %d\n", a,
b, file, line); |
| 243 #ifdef FIXED_DEBUG_ASSERT | 250 #ifdef FIXED_DEBUG_ASSERT |
| 244 celt_assert(0); | 251 celt_assert(0); |
| 245 #endif | 252 #endif |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 x = MIN32(x, 32767); | 782 x = MIN32(x, 32767); |
| 776 return EXTRACT16(x); | 783 return EXTRACT16(x); |
| 777 } | 784 } |
| 778 #define SIG2WORD16(x) (SIG2WORD16_generic(x)) | 785 #define SIG2WORD16(x) (SIG2WORD16_generic(x)) |
| 779 | 786 |
| 780 | 787 |
| 781 #undef PRINT_MIPS | 788 #undef PRINT_MIPS |
| 782 #define PRINT_MIPS(file) do {fprintf (file, "total complexity = %llu MIPS\n", ce
lt_mips);} while (0); | 789 #define PRINT_MIPS(file) do {fprintf (file, "total complexity = %llu MIPS\n", ce
lt_mips);} while (0); |
| 783 | 790 |
| 784 #endif | 791 #endif |
| OLD | NEW |