MacroCount.h 20 KB

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