MacroDebug.h 33 KB

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