MacroCount.h 21 KB

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