MacroCount.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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_LSHIFT8
  288. static OPUS_INLINE opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift){
  289. opus_int8 ret;
  290. ops_count += 1;
  291. ret = a << shift;
  292. return ret;
  293. }
  294. #undef silk_LSHIFT16
  295. static OPUS_INLINE opus_int16 silk_LSHIFT16(opus_int16 a, opus_int32 shift){
  296. opus_int16 ret;
  297. ops_count += 1;
  298. ret = a << shift;
  299. return ret;
  300. }
  301. #undef silk_LSHIFT32
  302. static OPUS_INLINE opus_int32 silk_LSHIFT32(opus_int32 a, opus_int32 shift){
  303. opus_int32 ret;
  304. ops_count += 1;
  305. ret = a << shift;
  306. return ret;
  307. }
  308. #undef silk_LSHIFT64
  309. static OPUS_INLINE opus_int64 silk_LSHIFT64(opus_int64 a, opus_int shift){
  310. ops_count += 1;
  311. return a << shift;
  312. }
  313. #undef silk_LSHIFT_ovflw
  314. static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw(opus_int32 a, opus_int32 shift){
  315. ops_count += 1;
  316. return a << shift;
  317. }
  318. #undef silk_LSHIFT_uint
  319. static OPUS_INLINE opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift){
  320. opus_uint32 ret;
  321. ops_count += 1;
  322. ret = a << shift;
  323. return ret;
  324. }
  325. #undef silk_RSHIFT8
  326. static OPUS_INLINE opus_int8 silk_RSHIFT8(opus_int8 a, opus_int32 shift){
  327. ops_count += 1;
  328. return a >> shift;
  329. }
  330. #undef silk_RSHIFT16
  331. static OPUS_INLINE opus_int16 silk_RSHIFT16(opus_int16 a, opus_int32 shift){
  332. ops_count += 1;
  333. return a >> shift;
  334. }
  335. #undef silk_RSHIFT32
  336. static OPUS_INLINE opus_int32 silk_RSHIFT32(opus_int32 a, opus_int32 shift){
  337. ops_count += 1;
  338. return a >> shift;
  339. }
  340. #undef silk_RSHIFT64
  341. static OPUS_INLINE opus_int64 silk_RSHIFT64(opus_int64 a, opus_int64 shift){
  342. ops_count += 1;
  343. return a >> shift;
  344. }
  345. #undef silk_RSHIFT_uint
  346. static OPUS_INLINE opus_uint32 silk_RSHIFT_uint(opus_uint32 a, opus_int32 shift){
  347. ops_count += 1;
  348. return a >> shift;
  349. }
  350. #undef silk_ADD_LSHIFT
  351. static OPUS_INLINE opus_int32 silk_ADD_LSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
  352. opus_int32 ret;
  353. ops_count += 1;
  354. ret = a + (b << shift);
  355. return ret; /* shift >= 0*/
  356. }
  357. #undef silk_ADD_LSHIFT32
  358. static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32(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_LSHIFT_uint
  365. static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
  366. opus_uint32 ret;
  367. ops_count += 1;
  368. ret = a + (b << shift);
  369. return ret; /* shift >= 0*/
  370. }
  371. #undef silk_ADD_RSHIFT
  372. static OPUS_INLINE opus_int32 silk_ADD_RSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
  373. opus_int32 ret;
  374. ops_count += 1;
  375. ret = a + (b >> shift);
  376. return ret; /* shift > 0*/
  377. }
  378. #undef silk_ADD_RSHIFT32
  379. static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32(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_RSHIFT_uint
  386. static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
  387. opus_uint32 ret;
  388. ops_count += 1;
  389. ret = a + (b >> shift);
  390. return ret; /* shift > 0*/
  391. }
  392. #undef silk_SUB_LSHIFT32
  393. static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
  394. opus_int32 ret;
  395. ops_count += 1;
  396. ret = a - (b << shift);
  397. return ret; /* shift >= 0*/
  398. }
  399. #undef silk_SUB_RSHIFT32
  400. static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32(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_RSHIFT_ROUND
  407. static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift){
  408. opus_int32 ret;
  409. ops_count += 3;
  410. ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
  411. return ret;
  412. }
  413. #undef silk_RSHIFT_ROUND64
  414. static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift){
  415. opus_int64 ret;
  416. ops_count += 6;
  417. ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
  418. return ret;
  419. }
  420. #undef silk_abs_int64
  421. static OPUS_INLINE opus_int64 silk_abs_int64(opus_int64 a){
  422. ops_count += 1;
  423. return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN*/
  424. }
  425. #undef silk_abs_int32
  426. static OPUS_INLINE opus_int32 silk_abs_int32(opus_int32 a){
  427. ops_count += 1;
  428. return silk_abs(a);
  429. }
  430. #undef silk_min
  431. static silk_min(a, b){
  432. ops_count += 1;
  433. return (((a) < (b)) ? (a) : (b));
  434. }
  435. #undef silk_max
  436. static silk_max(a, b){
  437. ops_count += 1;
  438. return (((a) > (b)) ? (a) : (b));
  439. }
  440. #undef silk_sign
  441. static silk_sign(a){
  442. ops_count += 1;
  443. return ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 ));
  444. }
  445. #undef silk_ADD16
  446. static OPUS_INLINE opus_int16 silk_ADD16(opus_int16 a, opus_int16 b){
  447. opus_int16 ret;
  448. ops_count += 1;
  449. ret = a + b;
  450. return ret;
  451. }
  452. #undef silk_ADD32
  453. static OPUS_INLINE opus_int32 silk_ADD32(opus_int32 a, opus_int32 b){
  454. opus_int32 ret;
  455. ops_count += 1;
  456. ret = a + b;
  457. return ret;
  458. }
  459. #undef silk_ADD64
  460. static OPUS_INLINE opus_int64 silk_ADD64(opus_int64 a, opus_int64 b){
  461. opus_int64 ret;
  462. ops_count += 2;
  463. ret = a + b;
  464. return ret;
  465. }
  466. #undef silk_SUB16
  467. static OPUS_INLINE opus_int16 silk_SUB16(opus_int16 a, opus_int16 b){
  468. opus_int16 ret;
  469. ops_count += 1;
  470. ret = a - b;
  471. return ret;
  472. }
  473. #undef silk_SUB32
  474. static OPUS_INLINE opus_int32 silk_SUB32(opus_int32 a, opus_int32 b){
  475. opus_int32 ret;
  476. ops_count += 1;
  477. ret = a - b;
  478. return ret;
  479. }
  480. #undef silk_SUB64
  481. static OPUS_INLINE opus_int64 silk_SUB64(opus_int64 a, opus_int64 b){
  482. opus_int64 ret;
  483. ops_count += 2;
  484. ret = a - b;
  485. return ret;
  486. }
  487. #undef silk_ADD_SAT16
  488. static OPUS_INLINE opus_int16 silk_ADD_SAT16( opus_int16 a16, opus_int16 b16 ) {
  489. opus_int16 res;
  490. /* Nb will be counted in AKP_add32 and silk_SAT16*/
  491. res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) );
  492. return res;
  493. }
  494. #undef silk_ADD_SAT32
  495. static OPUS_INLINE opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32){
  496. opus_int32 res;
  497. ops_count += 1;
  498. res = ((((a32) + (b32)) & 0x80000000) == 0 ? \
  499. ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \
  500. ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) );
  501. return res;
  502. }
  503. #undef silk_ADD_SAT64
  504. static OPUS_INLINE opus_int64 silk_ADD_SAT64( opus_int64 a64, opus_int64 b64 ) {
  505. opus_int64 res;
  506. ops_count += 1;
  507. res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \
  508. ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \
  509. ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) );
  510. return res;
  511. }
  512. #undef silk_SUB_SAT16
  513. static OPUS_INLINE opus_int16 silk_SUB_SAT16( opus_int16 a16, opus_int16 b16 ) {
  514. opus_int16 res;
  515. silk_assert(0);
  516. /* Nb will be counted in sub-macros*/
  517. res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) );
  518. return res;
  519. }
  520. #undef silk_SUB_SAT32
  521. static OPUS_INLINE opus_int32 silk_SUB_SAT32( opus_int32 a32, opus_int32 b32 ) {
  522. opus_int32 res;
  523. ops_count += 1;
  524. res = ((((a32)-(b32)) & 0x80000000) == 0 ? \
  525. (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \
  526. ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) );
  527. return res;
  528. }
  529. #undef silk_SUB_SAT64
  530. static OPUS_INLINE opus_int64 silk_SUB_SAT64( opus_int64 a64, opus_int64 b64 ) {
  531. opus_int64 res;
  532. ops_count += 1;
  533. res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \
  534. (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \
  535. ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) );
  536. return res;
  537. }
  538. #undef silk_SMULWW
  539. static OPUS_INLINE opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32){
  540. opus_int32 ret;
  541. /* Nb will be counted in sub-macros*/
  542. ret = silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16));
  543. return ret;
  544. }
  545. #undef silk_SMLAWW
  546. static OPUS_INLINE opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_int32 c32){
  547. opus_int32 ret;
  548. /* Nb will be counted in sub-macros*/
  549. ret = silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16));
  550. return ret;
  551. }
  552. #undef silk_min_int
  553. static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b)
  554. {
  555. ops_count += 1;
  556. return (((a) < (b)) ? (a) : (b));
  557. }
  558. #undef silk_min_16
  559. static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b)
  560. {
  561. ops_count += 1;
  562. return (((a) < (b)) ? (a) : (b));
  563. }
  564. #undef silk_min_32
  565. static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b)
  566. {
  567. ops_count += 1;
  568. return (((a) < (b)) ? (a) : (b));
  569. }
  570. #undef silk_min_64
  571. static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b)
  572. {
  573. ops_count += 1;
  574. return (((a) < (b)) ? (a) : (b));
  575. }
  576. /* silk_min() versions with typecast in the function call */
  577. #undef silk_max_int
  578. static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b)
  579. {
  580. ops_count += 1;
  581. return (((a) > (b)) ? (a) : (b));
  582. }
  583. #undef silk_max_16
  584. static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b)
  585. {
  586. ops_count += 1;
  587. return (((a) > (b)) ? (a) : (b));
  588. }
  589. #undef silk_max_32
  590. static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b)
  591. {
  592. ops_count += 1;
  593. return (((a) > (b)) ? (a) : (b));
  594. }
  595. #undef silk_max_64
  596. static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b)
  597. {
  598. ops_count += 1;
  599. return (((a) > (b)) ? (a) : (b));
  600. }
  601. #undef silk_LIMIT_int
  602. static OPUS_INLINE opus_int silk_LIMIT_int(opus_int a, opus_int limit1, opus_int limit2)
  603. {
  604. opus_int ret;
  605. ops_count += 6;
  606. ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
  607. : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
  608. return(ret);
  609. }
  610. #undef silk_LIMIT_16
  611. static OPUS_INLINE opus_int16 silk_LIMIT_16(opus_int16 a, opus_int16 limit1, opus_int16 limit2)
  612. {
  613. opus_int16 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_32
  620. static OPUS_INLINE opus_int32 silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2)
  621. {
  622. opus_int32 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. #else
  629. #define varDefine
  630. #define silk_SaveCount()
  631. #endif
  632. #endif