MacroDebug.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  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. #undef silk_LSHIFT8
  497. #define silk_LSHIFT8(a,b) silk_LSHIFT8_((a), (b), __FILE__, __LINE__)
  498. static OPUS_INLINE opus_int8 silk_LSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line){
  499. opus_int8 ret;
  500. int fail = 0;
  501. ret = a << shift;
  502. fail |= shift < 0;
  503. fail |= shift >= 8;
  504. fail |= (opus_int64)ret != ((opus_int64)a) << shift;
  505. if ( fail )
  506. {
  507. fprintf (stderr, "silk_LSHIFT8(%d, %d) in %s: line %d\n", a, shift, file, line);
  508. #ifdef FIXED_DEBUG_ASSERT
  509. silk_assert( 0 );
  510. #endif
  511. }
  512. return ret;
  513. }
  514. #undef silk_LSHIFT16
  515. #define silk_LSHIFT16(a,b) silk_LSHIFT16_((a), (b), __FILE__, __LINE__)
  516. static OPUS_INLINE opus_int16 silk_LSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line){
  517. opus_int16 ret;
  518. int fail = 0;
  519. ret = a << shift;
  520. fail |= shift < 0;
  521. fail |= shift >= 16;
  522. fail |= (opus_int64)ret != ((opus_int64)a) << shift;
  523. if ( fail )
  524. {
  525. fprintf (stderr, "silk_LSHIFT16(%d, %d) in %s: line %d\n", a, shift, file, line);
  526. #ifdef FIXED_DEBUG_ASSERT
  527. silk_assert( 0 );
  528. #endif
  529. }
  530. return ret;
  531. }
  532. #undef silk_LSHIFT32
  533. #define silk_LSHIFT32(a,b) silk_LSHIFT32_((a), (b), __FILE__, __LINE__)
  534. static OPUS_INLINE opus_int32 silk_LSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line){
  535. opus_int32 ret;
  536. int fail = 0;
  537. ret = a << shift;
  538. fail |= shift < 0;
  539. fail |= shift >= 32;
  540. fail |= (opus_int64)ret != ((opus_int64)a) << shift;
  541. if ( fail )
  542. {
  543. fprintf (stderr, "silk_LSHIFT32(%d, %d) in %s: line %d\n", a, shift, file, line);
  544. #ifdef FIXED_DEBUG_ASSERT
  545. silk_assert( 0 );
  546. #endif
  547. }
  548. return ret;
  549. }
  550. #undef silk_LSHIFT64
  551. #define silk_LSHIFT64(a,b) silk_LSHIFT64_((a), (b), __FILE__, __LINE__)
  552. static OPUS_INLINE opus_int64 silk_LSHIFT64_(opus_int64 a, opus_int shift, char *file, int line){
  553. opus_int64 ret;
  554. int fail = 0;
  555. ret = a << shift;
  556. fail |= shift < 0;
  557. fail |= shift >= 64;
  558. fail |= (ret>>shift) != ((opus_int64)a);
  559. if ( fail )
  560. {
  561. fprintf (stderr, "silk_LSHIFT64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line);
  562. #ifdef FIXED_DEBUG_ASSERT
  563. silk_assert( 0 );
  564. #endif
  565. }
  566. return ret;
  567. }
  568. #undef silk_LSHIFT_ovflw
  569. #define silk_LSHIFT_ovflw(a,b) silk_LSHIFT_ovflw_((a), (b), __FILE__, __LINE__)
  570. static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw_(opus_int32 a, opus_int32 shift, char *file, int line){
  571. if ( (shift < 0) || (shift >= 32) ) /* no check for overflow */
  572. {
  573. fprintf (stderr, "silk_LSHIFT_ovflw(%d, %d) in %s: line %d\n", a, shift, file, line);
  574. #ifdef FIXED_DEBUG_ASSERT
  575. silk_assert( 0 );
  576. #endif
  577. }
  578. return a << shift;
  579. }
  580. #undef silk_LSHIFT_uint
  581. #define silk_LSHIFT_uint(a,b) silk_LSHIFT_uint_((a), (b), __FILE__, __LINE__)
  582. static OPUS_INLINE opus_uint32 silk_LSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line){
  583. opus_uint32 ret;
  584. ret = a << shift;
  585. if ( (shift < 0) || ((opus_int64)ret != ((opus_int64)a) << shift))
  586. {
  587. fprintf (stderr, "silk_LSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line);
  588. #ifdef FIXED_DEBUG_ASSERT
  589. silk_assert( 0 );
  590. #endif
  591. }
  592. return ret;
  593. }
  594. #undef silk_RSHIFT8
  595. #define silk_RSHITF8(a,b) silk_RSHIFT8_((a), (b), __FILE__, __LINE__)
  596. static OPUS_INLINE opus_int8 silk_RSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line){
  597. if ( (shift < 0) || (shift>=8) )
  598. {
  599. fprintf (stderr, "silk_RSHITF8(%d, %d) in %s: line %d\n", a, shift, file, line);
  600. #ifdef FIXED_DEBUG_ASSERT
  601. silk_assert( 0 );
  602. #endif
  603. }
  604. return a >> shift;
  605. }
  606. #undef silk_RSHIFT16
  607. #define silk_RSHITF16(a,b) silk_RSHIFT16_((a), (b), __FILE__, __LINE__)
  608. static OPUS_INLINE opus_int16 silk_RSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line){
  609. if ( (shift < 0) || (shift>=16) )
  610. {
  611. fprintf (stderr, "silk_RSHITF16(%d, %d) in %s: line %d\n", a, shift, file, line);
  612. #ifdef FIXED_DEBUG_ASSERT
  613. silk_assert( 0 );
  614. #endif
  615. }
  616. return a >> shift;
  617. }
  618. #undef silk_RSHIFT32
  619. #define silk_RSHIFT32(a,b) silk_RSHIFT32_((a), (b), __FILE__, __LINE__)
  620. static OPUS_INLINE opus_int32 silk_RSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line){
  621. if ( (shift < 0) || (shift>=32) )
  622. {
  623. fprintf (stderr, "silk_RSHITF32(%d, %d) in %s: line %d\n", a, shift, file, line);
  624. #ifdef FIXED_DEBUG_ASSERT
  625. silk_assert( 0 );
  626. #endif
  627. }
  628. return a >> shift;
  629. }
  630. #undef silk_RSHIFT64
  631. #define silk_RSHIFT64(a,b) silk_RSHIFT64_((a), (b), __FILE__, __LINE__)
  632. static OPUS_INLINE opus_int64 silk_RSHIFT64_(opus_int64 a, opus_int64 shift, char *file, int line){
  633. if ( (shift < 0) || (shift>=64) )
  634. {
  635. fprintf (stderr, "silk_RSHITF64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)shift, file, line);
  636. #ifdef FIXED_DEBUG_ASSERT
  637. silk_assert( 0 );
  638. #endif
  639. }
  640. return a >> shift;
  641. }
  642. #undef silk_RSHIFT_uint
  643. #define silk_RSHIFT_uint(a,b) silk_RSHIFT_uint_((a), (b), __FILE__, __LINE__)
  644. static OPUS_INLINE opus_uint32 silk_RSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line){
  645. if ( (shift < 0) || (shift>32) )
  646. {
  647. fprintf (stderr, "silk_RSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line);
  648. #ifdef FIXED_DEBUG_ASSERT
  649. silk_assert( 0 );
  650. #endif
  651. }
  652. return a >> shift;
  653. }
  654. #undef silk_ADD_LSHIFT
  655. #define silk_ADD_LSHIFT(a,b,c) silk_ADD_LSHIFT_((a), (b), (c), __FILE__, __LINE__)
  656. static OPUS_INLINE int silk_ADD_LSHIFT_(int a, int b, int shift, char *file, int line){
  657. opus_int16 ret;
  658. ret = a + (b << shift);
  659. if ( (shift < 0) || (shift>15) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift)) )
  660. {
  661. fprintf (stderr, "silk_ADD_LSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
  662. #ifdef FIXED_DEBUG_ASSERT
  663. silk_assert( 0 );
  664. #endif
  665. }
  666. return ret; /* shift >= 0 */
  667. }
  668. #undef silk_ADD_LSHIFT32
  669. #define silk_ADD_LSHIFT32(a,b,c) silk_ADD_LSHIFT32_((a), (b), (c), __FILE__, __LINE__)
  670. static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
  671. opus_int32 ret;
  672. ret = a + (b << shift);
  673. if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift)) )
  674. {
  675. fprintf (stderr, "silk_ADD_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
  676. #ifdef FIXED_DEBUG_ASSERT
  677. silk_assert( 0 );
  678. #endif
  679. }
  680. return ret; /* shift >= 0 */
  681. }
  682. #undef silk_ADD_LSHIFT_uint
  683. #define silk_ADD_LSHIFT_uint(a,b,c) silk_ADD_LSHIFT_uint_((a), (b), (c), __FILE__, __LINE__)
  684. static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line){
  685. opus_uint32 ret;
  686. ret = a + (b << shift);
  687. if ( (shift < 0) || (shift>32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift)) )
  688. {
  689. fprintf (stderr, "silk_ADD_LSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line);
  690. #ifdef FIXED_DEBUG_ASSERT
  691. silk_assert( 0 );
  692. #endif
  693. }
  694. return ret; /* shift >= 0 */
  695. }
  696. #undef silk_ADD_RSHIFT
  697. #define silk_ADD_RSHIFT(a,b,c) silk_ADD_RSHIFT_((a), (b), (c), __FILE__, __LINE__)
  698. static OPUS_INLINE int silk_ADD_RSHIFT_(int a, int b, int shift, char *file, int line){
  699. opus_int16 ret;
  700. ret = a + (b >> shift);
  701. if ( (shift < 0) || (shift>15) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
  702. {
  703. fprintf (stderr, "silk_ADD_RSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
  704. #ifdef FIXED_DEBUG_ASSERT
  705. silk_assert( 0 );
  706. #endif
  707. }
  708. return ret; /* shift > 0 */
  709. }
  710. #undef silk_ADD_RSHIFT32
  711. #define silk_ADD_RSHIFT32(a,b,c) silk_ADD_RSHIFT32_((a), (b), (c), __FILE__, __LINE__)
  712. static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
  713. opus_int32 ret;
  714. ret = a + (b >> shift);
  715. if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
  716. {
  717. fprintf (stderr, "silk_ADD_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
  718. #ifdef FIXED_DEBUG_ASSERT
  719. silk_assert( 0 );
  720. #endif
  721. }
  722. return ret; /* shift > 0 */
  723. }
  724. #undef silk_ADD_RSHIFT_uint
  725. #define silk_ADD_RSHIFT_uint(a,b,c) silk_ADD_RSHIFT_uint_((a), (b), (c), __FILE__, __LINE__)
  726. static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line){
  727. opus_uint32 ret;
  728. ret = a + (b >> shift);
  729. if ( (shift < 0) || (shift>32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
  730. {
  731. fprintf (stderr, "silk_ADD_RSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line);
  732. #ifdef FIXED_DEBUG_ASSERT
  733. silk_assert( 0 );
  734. #endif
  735. }
  736. return ret; /* shift > 0 */
  737. }
  738. #undef silk_SUB_LSHIFT32
  739. #define silk_SUB_LSHIFT32(a,b,c) silk_SUB_LSHIFT32_((a), (b), (c), __FILE__, __LINE__)
  740. static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
  741. opus_int32 ret;
  742. ret = a - (b << shift);
  743. if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a - (((opus_int64)b) << shift)) )
  744. {
  745. fprintf (stderr, "silk_SUB_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
  746. #ifdef FIXED_DEBUG_ASSERT
  747. silk_assert( 0 );
  748. #endif
  749. }
  750. return ret; /* shift >= 0 */
  751. }
  752. #undef silk_SUB_RSHIFT32
  753. #define silk_SUB_RSHIFT32(a,b,c) silk_SUB_RSHIFT32_((a), (b), (c), __FILE__, __LINE__)
  754. static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
  755. opus_int32 ret;
  756. ret = a - (b >> shift);
  757. if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a - (((opus_int64)b) >> shift)) )
  758. {
  759. fprintf (stderr, "silk_SUB_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
  760. #ifdef FIXED_DEBUG_ASSERT
  761. silk_assert( 0 );
  762. #endif
  763. }
  764. return ret; /* shift > 0 */
  765. }
  766. #undef silk_RSHIFT_ROUND
  767. #define silk_RSHIFT_ROUND(a,b) silk_RSHIFT_ROUND_((a), (b), __FILE__, __LINE__)
  768. static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND_(opus_int32 a, opus_int32 shift, char *file, int line){
  769. opus_int32 ret;
  770. ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
  771. /* the marco definition can't handle a shift of zero */
  772. if ( (shift <= 0) || (shift>31) || ((opus_int64)ret != ((opus_int64)a + ((opus_int64)1 << (shift - 1))) >> shift) )
  773. {
  774. fprintf (stderr, "silk_RSHIFT_ROUND(%d, %d) in %s: line %d\n", a, shift, file, line);
  775. #ifdef FIXED_DEBUG_ASSERT
  776. silk_assert( 0 );
  777. #endif
  778. }
  779. return ret;
  780. }
  781. #undef silk_RSHIFT_ROUND64
  782. #define silk_RSHIFT_ROUND64(a,b) silk_RSHIFT_ROUND64_((a), (b), __FILE__, __LINE__)
  783. static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64_(opus_int64 a, opus_int32 shift, char *file, int line){
  784. opus_int64 ret;
  785. /* the marco definition can't handle a shift of zero */
  786. if ( (shift <= 0) || (shift>=64) )
  787. {
  788. fprintf (stderr, "silk_RSHIFT_ROUND64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line);
  789. #ifdef FIXED_DEBUG_ASSERT
  790. silk_assert( 0 );
  791. #endif
  792. }
  793. ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
  794. return ret;
  795. }
  796. /* silk_abs is used on floats also, so doesn't work... */
  797. /*#undef silk_abs
  798. static OPUS_INLINE opus_int32 silk_abs(opus_int32 a){
  799. silk_assert(a != 0x80000000);
  800. return (((a) > 0) ? (a) : -(a)); // Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN
  801. }*/
  802. #undef silk_abs_int64
  803. #define silk_abs_int64(a) silk_abs_int64_((a), __FILE__, __LINE__)
  804. static OPUS_INLINE opus_int64 silk_abs_int64_(opus_int64 a, char *file, int line){
  805. if ( a == silk_int64_MIN )
  806. {
  807. fprintf (stderr, "silk_abs_int64(%lld) in %s: line %d\n", (long long)a, file, line);
  808. #ifdef FIXED_DEBUG_ASSERT
  809. silk_assert( 0 );
  810. #endif
  811. }
  812. return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN */
  813. }
  814. #undef silk_abs_int32
  815. #define silk_abs_int32(a) silk_abs_int32_((a), __FILE__, __LINE__)
  816. static OPUS_INLINE opus_int32 silk_abs_int32_(opus_int32 a, char *file, int line){
  817. if ( a == silk_int32_MIN )
  818. {
  819. fprintf (stderr, "silk_abs_int32(%d) in %s: line %d\n", a, file, line);
  820. #ifdef FIXED_DEBUG_ASSERT
  821. silk_assert( 0 );
  822. #endif
  823. }
  824. return silk_abs(a);
  825. }
  826. #undef silk_CHECK_FIT8
  827. #define silk_CHECK_FIT8(a) silk_CHECK_FIT8_((a), __FILE__, __LINE__)
  828. static OPUS_INLINE opus_int8 silk_CHECK_FIT8_( opus_int64 a, char *file, int line ){
  829. opus_int8 ret;
  830. ret = (opus_int8)a;
  831. if ( (opus_int64)ret != a )
  832. {
  833. fprintf (stderr, "silk_CHECK_FIT8(%lld) in %s: line %d\n", (long long)a, file, line);
  834. #ifdef FIXED_DEBUG_ASSERT
  835. silk_assert( 0 );
  836. #endif
  837. }
  838. return( ret );
  839. }
  840. #undef silk_CHECK_FIT16
  841. #define silk_CHECK_FIT16(a) silk_CHECK_FIT16_((a), __FILE__, __LINE__)
  842. static OPUS_INLINE opus_int16 silk_CHECK_FIT16_( opus_int64 a, char *file, int line ){
  843. opus_int16 ret;
  844. ret = (opus_int16)a;
  845. if ( (opus_int64)ret != a )
  846. {
  847. fprintf (stderr, "silk_CHECK_FIT16(%lld) in %s: line %d\n", (long long)a, file, line);
  848. #ifdef FIXED_DEBUG_ASSERT
  849. silk_assert( 0 );
  850. #endif
  851. }
  852. return( ret );
  853. }
  854. #undef silk_CHECK_FIT32
  855. #define silk_CHECK_FIT32(a) silk_CHECK_FIT32_((a), __FILE__, __LINE__)
  856. static OPUS_INLINE opus_int32 silk_CHECK_FIT32_( opus_int64 a, char *file, int line ){
  857. opus_int32 ret;
  858. ret = (opus_int32)a;
  859. if ( (opus_int64)ret != a )
  860. {
  861. fprintf (stderr, "silk_CHECK_FIT32(%lld) in %s: line %d\n", (long long)a, file, line);
  862. #ifdef FIXED_DEBUG_ASSERT
  863. silk_assert( 0 );
  864. #endif
  865. }
  866. return( ret );
  867. }
  868. /* no checking for silk_NSHIFT_MUL_32_32
  869. no checking for silk_NSHIFT_MUL_16_16
  870. no checking needed for silk_min
  871. no checking needed for silk_max
  872. no checking needed for silk_sign
  873. */
  874. #endif
  875. #endif /* MACRO_DEBUG_H */