basicop2.c 106 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145
  1. /*___________________________________________________________________________
  2. | |
  3. | Basic arithmetic operators. |
  4. | |
  5. | $Id $
  6. |___________________________________________________________________________|
  7. */
  8. /*___________________________________________________________________________
  9. | |
  10. | Include-Files |
  11. |___________________________________________________________________________|
  12. */
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include "typedef.h"
  16. #include "basic_op.h"
  17. #if (WMOPS)
  18. #include "count.h"
  19. extern BASIC_OP multiCounter[MAXCOUNTERS];
  20. extern int currCounter;
  21. #endif
  22. /*___________________________________________________________________________
  23. | |
  24. | Local Functions |
  25. |___________________________________________________________________________|
  26. */
  27. static Word16 saturate (Word32 L_var1);
  28. /*___________________________________________________________________________
  29. | |
  30. | Constants and Globals |
  31. |___________________________________________________________________________|
  32. */
  33. Flag Overflow = 0;
  34. Flag Carry = 0;
  35. /*___________________________________________________________________________
  36. | |
  37. | Functions |
  38. |___________________________________________________________________________|
  39. */
  40. /*___________________________________________________________________________
  41. | |
  42. | Function Name : saturate |
  43. | |
  44. | Purpose : |
  45. | |
  46. | Limit the 32 bit input to the range of a 16 bit word. |
  47. | |
  48. | Inputs : |
  49. | |
  50. | L_var1 |
  51. | 32 bit long signed integer (Word32) whose value falls in the |
  52. | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
  53. | |
  54. | Outputs : |
  55. | |
  56. | none |
  57. | |
  58. | Return Value : |
  59. | |
  60. | var_out |
  61. | 16 bit short signed integer (Word16) whose value falls in the |
  62. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  63. |___________________________________________________________________________|
  64. */
  65. static Word16
  66. saturate (Word32 L_var1)
  67. {
  68. Word16 var_out;
  69. if (L_var1 > 0X00007fffL)
  70. {
  71. Overflow = 1;
  72. var_out = MAX_16;
  73. }
  74. else if (L_var1 < (Word32) 0xffff8000L)
  75. {
  76. Overflow = 1;
  77. var_out = MIN_16;
  78. }
  79. else
  80. {
  81. var_out = extract_l_ex (L_var1);
  82. #if (WMOPS)
  83. multiCounter[currCounter].extract_l_ex--;
  84. #endif
  85. }
  86. return (var_out);
  87. }
  88. /*___________________________________________________________________________
  89. | |
  90. | Function Name : add |
  91. | |
  92. | Purpose : |
  93. | |
  94. | Performs the addition (var1+var2) with overflow control and saturation;|
  95. | the 16 bit result is set at +32767 when overflow occurs or at -32768 |
  96. | when underflow occurs. |
  97. | |
  98. | Complexity weight : 1 |
  99. | |
  100. | Inputs : |
  101. | |
  102. | var1 |
  103. | 16 bit short signed integer (Word16) whose value falls in the |
  104. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  105. | |
  106. | var2 |
  107. | 16 bit short signed integer (Word16) whose value falls in the |
  108. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  109. | |
  110. | Outputs : |
  111. | |
  112. | none |
  113. | |
  114. | Return Value : |
  115. | |
  116. | var_out |
  117. | 16 bit short signed integer (Word16) whose value falls in the |
  118. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  119. |___________________________________________________________________________|
  120. */
  121. Word16 add_ex (Word16 var1, Word16 var2)
  122. {
  123. Word16 var_out;
  124. Word32 L_sum;
  125. L_sum = (Word32) var1 + var2;
  126. var_out = saturate (L_sum);
  127. #if (WMOPS)
  128. multiCounter[currCounter].add_ex++;
  129. #endif
  130. return (var_out);
  131. }
  132. /*___________________________________________________________________________
  133. | |
  134. | Function Name : sub_ex |
  135. | |
  136. | Purpose : |
  137. | |
  138. | Performs the subtraction (var1+var2) with overflow control and satu- |
  139. | ration; the 16 bit result is set at +32767 when overflow occurs or at |
  140. | -32768 when underflow occurs. |
  141. | |
  142. | Complexity weight : 1 |
  143. | |
  144. | Inputs : |
  145. | |
  146. | var1 |
  147. | 16 bit short signed integer (Word16) whose value falls in the |
  148. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  149. | |
  150. | var2 |
  151. | 16 bit short signed integer (Word16) whose value falls in the |
  152. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  153. | |
  154. | Outputs : |
  155. | |
  156. | none |
  157. | |
  158. | Return Value : |
  159. | |
  160. | var_out |
  161. | 16 bit short signed integer (Word16) whose value falls in the |
  162. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  163. |___________________________________________________________________________|
  164. */
  165. Word16 sub_ex (Word16 var1, Word16 var2)
  166. {
  167. Word16 var_out;
  168. Word32 L_diff;
  169. L_diff = (Word32) var1 - var2;
  170. var_out = saturate (L_diff);
  171. #if (WMOPS)
  172. multiCounter[currCounter].sub_ex++;
  173. #endif
  174. return (var_out);
  175. }
  176. /*___________________________________________________________________________
  177. | |
  178. | Function Name : abs_s_ex |
  179. | |
  180. | Purpose : |
  181. | |
  182. | Absolute value of var1; abs_s_ex(-32768) = 32767. |
  183. | |
  184. | Complexity weight : 1 |
  185. | |
  186. | Inputs : |
  187. | |
  188. | var1 |
  189. | 16 bit short signed integer (Word16) whose value falls in the |
  190. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  191. | |
  192. | Outputs : |
  193. | |
  194. | none |
  195. | |
  196. | Return Value : |
  197. | |
  198. | var_out |
  199. | 16 bit short signed integer (Word16) whose value falls in the |
  200. | range : 0x0000 0000 <= var_out <= 0x0000 7fff. |
  201. |___________________________________________________________________________|
  202. */
  203. Word16 abs_s_ex (Word16 var1)
  204. {
  205. Word16 var_out;
  206. if (var1 == (Word16) 0X8000)
  207. {
  208. var_out = MAX_16;
  209. }
  210. else
  211. {
  212. if (var1 < 0)
  213. {
  214. var_out = -var1;
  215. }
  216. else
  217. {
  218. var_out = var1;
  219. }
  220. }
  221. #if (WMOPS)
  222. multiCounter[currCounter].abs_s_ex++;
  223. #endif
  224. return (var_out);
  225. }
  226. /*___________________________________________________________________________
  227. | |
  228. | Function Name : shl_ex |
  229. | |
  230. | Purpose : |
  231. | |
  232. | Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill|
  233. | the var2 LSB of the result. If var2 is negative, arithmetically shift |
  234. | var1 right by -var2 with sign extension. Saturate the result in case of |
  235. | underflows or overflows. |
  236. | |
  237. | Complexity weight : 1 |
  238. | |
  239. | Inputs : |
  240. | |
  241. | var1 |
  242. | 16 bit short signed integer (Word16) whose value falls in the |
  243. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  244. | |
  245. | var2 |
  246. | 16 bit short signed integer (Word16) whose value falls in the |
  247. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  248. | |
  249. | Outputs : |
  250. | |
  251. | none |
  252. | |
  253. | Return Value : |
  254. | |
  255. | var_out |
  256. | 16 bit short signed integer (Word16) whose value falls in the |
  257. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  258. |___________________________________________________________________________|
  259. */
  260. Word16 shl_ex (Word16 var1, Word16 var2)
  261. {
  262. Word16 var_out;
  263. Word32 result;
  264. if (var2 < 0)
  265. {
  266. if (var2 < -16)
  267. var2 = -16;
  268. var_out = shr_ex (var1, -var2);
  269. #if (WMOPS)
  270. multiCounter[currCounter].shr_ex--;
  271. #endif
  272. }
  273. else
  274. {
  275. result = (Word32) var1 *((Word32) 1 << var2);
  276. if ((var2 > 15 && var1 != 0) || (result != (Word32) ((Word16) result)))
  277. {
  278. Overflow = 1;
  279. var_out = (var1 > 0) ? MAX_16 : MIN_16;
  280. }
  281. else
  282. {
  283. var_out = extract_l_ex (result);
  284. #if (WMOPS)
  285. multiCounter[currCounter].extract_l_ex--;
  286. #endif
  287. }
  288. }
  289. #if (WMOPS)
  290. multiCounter[currCounter].shl_ex++;
  291. #endif
  292. return (var_out);
  293. }
  294. /*___________________________________________________________________________
  295. | |
  296. | Function Name : shr_ex |
  297. | |
  298. | Purpose : |
  299. | |
  300. | Arithmetically shift the 16 bit input var1 right var2 positions with |
  301. | sign extension. If var2 is negative, arithmetically shift var1 left by |
  302. | -var2 with sign extension. Saturate the result in case of underflows or |
  303. | overflows. |
  304. | |
  305. | Complexity weight : 1 |
  306. | |
  307. | Inputs : |
  308. | |
  309. | var1 |
  310. | 16 bit short signed integer (Word16) whose value falls in the |
  311. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  312. | |
  313. | var2 |
  314. | 16 bit short signed integer (Word16) whose value falls in the |
  315. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  316. | |
  317. | Outputs : |
  318. | |
  319. | none |
  320. | |
  321. | Return Value : |
  322. | |
  323. | var_out |
  324. | 16 bit short signed integer (Word16) whose value falls in the |
  325. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  326. |___________________________________________________________________________|
  327. */
  328. Word16 shr_ex (Word16 var1, Word16 var2)
  329. {
  330. Word16 var_out;
  331. if (var2 < 0)
  332. {
  333. if (var2 < -16)
  334. var2 = -16;
  335. var_out = shl_ex (var1, -var2);
  336. #if (WMOPS)
  337. multiCounter[currCounter].shl_ex--;
  338. #endif
  339. }
  340. else
  341. {
  342. if (var2 >= 15)
  343. {
  344. var_out = (var1 < 0) ? -1 : 0;
  345. }
  346. else
  347. {
  348. if (var1 < 0)
  349. {
  350. var_out = ~((~var1) >> var2);
  351. }
  352. else
  353. {
  354. var_out = var1 >> var2;
  355. }
  356. }
  357. }
  358. #if (WMOPS)
  359. multiCounter[currCounter].shr_ex++;
  360. #endif
  361. return (var_out);
  362. }
  363. /*___________________________________________________________________________
  364. | |
  365. | Function Name : mult_ex |
  366. | |
  367. | Purpose : |
  368. | |
  369. | Performs the multiplication of var1 by var2 and gives a 16 bit result |
  370. | which is scaled i.e.: |
  371. | mult_ex(var1,var2) = extract_l_ex(L_shr_ex((var1 times var2),15)) and |
  372. | mult_ex(-32768,-32768) = 32767. |
  373. | |
  374. | Complexity weight : 1 |
  375. | |
  376. | Inputs : |
  377. | |
  378. | var1 |
  379. | 16 bit short signed integer (Word16) whose value falls in the |
  380. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  381. | |
  382. | var2 |
  383. | 16 bit short signed integer (Word16) whose value falls in the |
  384. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  385. | |
  386. | Outputs : |
  387. | |
  388. | none |
  389. | |
  390. | Return Value : |
  391. | |
  392. | var_out |
  393. | 16 bit short signed integer (Word16) whose value falls in the |
  394. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  395. |___________________________________________________________________________|
  396. */
  397. Word16 mult_ex (Word16 var1, Word16 var2)
  398. {
  399. Word16 var_out;
  400. Word32 L_product;
  401. L_product = (Word32) var1 *(Word32) var2;
  402. L_product = (L_product & (Word32) 0xffff8000L) >> 15;
  403. if (L_product & (Word32) 0x00010000L)
  404. L_product = L_product | (Word32) 0xffff0000L;
  405. var_out = saturate (L_product);
  406. #if (WMOPS)
  407. multiCounter[currCounter].mult_ex++;
  408. #endif
  409. return (var_out);
  410. }
  411. /*___________________________________________________________________________
  412. | |
  413. | Function Name : L_mult_ex |
  414. | |
  415. | Purpose : |
  416. | |
  417. | L_mult_ex is the 32 bit result of the multiplication of var1 times var2 |
  418. | with one shift left i.e.: |
  419. | L_mult_ex(var1,var2) = L_shl_ex((var1 times var2),1) and |
  420. | L_mult_ex(-32768,-32768) = 2147483647. |
  421. | |
  422. | Complexity weight : 1 |
  423. | |
  424. | Inputs : |
  425. | |
  426. | var1 |
  427. | 16 bit short signed integer (Word16) whose value falls in the |
  428. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  429. | |
  430. | var2 |
  431. | 16 bit short signed integer (Word16) whose value falls in the |
  432. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  433. | |
  434. | Outputs : |
  435. | |
  436. | none |
  437. | |
  438. | Return Value : |
  439. | |
  440. | L_var_out |
  441. | 32 bit long signed integer (Word32) whose value falls in the |
  442. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  443. |___________________________________________________________________________|
  444. */
  445. Word32 L_mult_ex (Word16 var1, Word16 var2)
  446. {
  447. Word32 L_var_out;
  448. L_var_out = (Word32) var1 *(Word32) var2;
  449. if (L_var_out != (Word32) 0x40000000L)
  450. {
  451. L_var_out *= 2;
  452. }
  453. else
  454. {
  455. Overflow = 1;
  456. L_var_out = MAX_32;
  457. }
  458. #if (WMOPS)
  459. multiCounter[currCounter].L_mult_ex++;
  460. #endif
  461. return (L_var_out);
  462. }
  463. /*___________________________________________________________________________
  464. | |
  465. | Function Name : negate_ex |
  466. | |
  467. | Purpose : |
  468. | |
  469. | Negate var1 with saturation, saturate in the case where input is -32768:|
  470. | negate_ex(var1) = sub_ex(0,var1). |
  471. | |
  472. | Complexity weight : 1 |
  473. | |
  474. | Inputs : |
  475. | |
  476. | var1 |
  477. | 16 bit short signed integer (Word16) whose value falls in the |
  478. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  479. | |
  480. | Outputs : |
  481. | |
  482. | none |
  483. | |
  484. | Return Value : |
  485. | |
  486. | var_out |
  487. | 16 bit short signed integer (Word16) whose value falls in the |
  488. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  489. |___________________________________________________________________________|
  490. */
  491. Word16 negate_ex (Word16 var1)
  492. {
  493. Word16 var_out;
  494. var_out = (var1 == MIN_16) ? MAX_16 : -var1;
  495. #if (WMOPS)
  496. multiCounter[currCounter].negate_ex++;
  497. #endif
  498. return (var_out);
  499. }
  500. /*___________________________________________________________________________
  501. | |
  502. | Function Name : extract_h_ex |
  503. | |
  504. | Purpose : |
  505. | |
  506. | Return the 16 MSB of L_var1. |
  507. | |
  508. | Complexity weight : 1 |
  509. | |
  510. | Inputs : |
  511. | |
  512. | L_var1 |
  513. | 32 bit long signed integer (Word32 ) whose value falls in the |
  514. | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
  515. | |
  516. | Outputs : |
  517. | |
  518. | none |
  519. | |
  520. | Return Value : |
  521. | |
  522. | var_out |
  523. | 16 bit short signed integer (Word16) whose value falls in the |
  524. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  525. |___________________________________________________________________________|
  526. */
  527. Word16 extract_h_ex (Word32 L_var1)
  528. {
  529. Word16 var_out;
  530. var_out = (Word16) (L_var1 >> 16);
  531. #if (WMOPS)
  532. multiCounter[currCounter].extract_h_ex++;
  533. #endif
  534. return (var_out);
  535. }
  536. /*___________________________________________________________________________
  537. | |
  538. | Function Name : extract_l_ex |
  539. | |
  540. | Purpose : |
  541. | |
  542. | Return the 16 LSB of L_var1. |
  543. | |
  544. | Complexity weight : 1 |
  545. | |
  546. | Inputs : |
  547. | |
  548. | L_var1 |
  549. | 32 bit long signed integer (Word32 ) whose value falls in the |
  550. | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
  551. | |
  552. | Outputs : |
  553. | |
  554. | none |
  555. | |
  556. | Return Value : |
  557. | |
  558. | var_out |
  559. | 16 bit short signed integer (Word16) whose value falls in the |
  560. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  561. |___________________________________________________________________________|
  562. */
  563. Word16 extract_l_ex (Word32 L_var1)
  564. {
  565. Word16 var_out;
  566. var_out = (Word16) L_var1;
  567. #if (WMOPS)
  568. multiCounter[currCounter].extract_l_ex++;
  569. #endif
  570. return (var_out);
  571. }
  572. /*___________________________________________________________________________
  573. | |
  574. | Function Name : round |
  575. | |
  576. | Purpose : |
  577. | |
  578. | Round the lower 16 bits of the 32 bit input number into the MS 16 bits |
  579. | with saturation. Shift the resulting bits right by 16 and return the 16 |
  580. | bit number: |
  581. | round(L_var1) = extract_h_ex(L_add_ex(L_var1,32768)) |
  582. | |
  583. | Complexity weight : 1 |
  584. | |
  585. | Inputs : |
  586. | |
  587. | L_var1 |
  588. | 32 bit long signed integer (Word32 ) whose value falls in the |
  589. | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
  590. | |
  591. | Outputs : |
  592. | |
  593. | none |
  594. | |
  595. | Return Value : |
  596. | |
  597. | var_out |
  598. | 16 bit short signed integer (Word16) whose value falls in the |
  599. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  600. |___________________________________________________________________________|
  601. */
  602. Word16 round_ex (Word32 L_var1)
  603. {
  604. Word16 var_out;
  605. Word32 L_rounded;
  606. L_rounded = L_add_ex (L_var1, (Word32) 0x00008000L);
  607. #if (WMOPS)
  608. multiCounter[currCounter].L_add_ex--;
  609. #endif
  610. var_out = extract_h_ex (L_rounded);
  611. #if (WMOPS)
  612. multiCounter[currCounter].extract_h_ex--;
  613. multiCounter[currCounter].round++;
  614. #endif
  615. return (var_out);
  616. }
  617. /*___________________________________________________________________________
  618. | |
  619. | Function Name : L_mac_ex |
  620. | |
  621. | Purpose : |
  622. | |
  623. | Multiply var1 by var2 and shift the result left by 1. Add the 32 bit |
  624. | result to L_var3 with saturation, return a 32 bit result: |
  625. | L_mac_ex(L_var3,var1,var2) = L_add_ex(L_var3,L_mult_ex(var1,var2)). |
  626. | |
  627. | Complexity weight : 1 |
  628. | |
  629. | Inputs : |
  630. | |
  631. | L_var3 32 bit long signed integer (Word32) whose value falls in the |
  632. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  633. | |
  634. | var1 |
  635. | 16 bit short signed integer (Word16) whose value falls in the |
  636. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  637. | |
  638. | var2 |
  639. | 16 bit short signed integer (Word16) whose value falls in the |
  640. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  641. | |
  642. | Outputs : |
  643. | |
  644. | none |
  645. | |
  646. | Return Value : |
  647. | |
  648. | L_var_out |
  649. | 32 bit long signed integer (Word32) whose value falls in the |
  650. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  651. |___________________________________________________________________________|
  652. */
  653. Word32 L_mac_ex (Word32 L_var3, Word16 var1, Word16 var2)
  654. {
  655. Word32 L_var_out;
  656. Word32 L_product;
  657. L_product = L_mult_ex (var1, var2);
  658. #if (WMOPS)
  659. multiCounter[currCounter].L_mult_ex--;
  660. #endif
  661. L_var_out = L_add_ex (L_var3, L_product);
  662. #if (WMOPS)
  663. multiCounter[currCounter].L_add_ex--;
  664. multiCounter[currCounter].L_mac_ex++;
  665. #endif
  666. return (L_var_out);
  667. }
  668. /*___________________________________________________________________________
  669. | |
  670. | Function Name : L_msu_ex |
  671. | |
  672. | Purpose : |
  673. | |
  674. | Multiply var1 by var2 and shift the result left by 1. Subtract the 32 |
  675. | bit result to L_var3 with saturation, return a 32 bit result: |
  676. | L_msu_ex(L_var3,var1,var2) = L_sub_ex(L_var3,L_mult_ex(var1,var2)). |
  677. | |
  678. | Complexity weight : 1 |
  679. | |
  680. | Inputs : |
  681. | |
  682. | L_var3 32 bit long signed integer (Word32) whose value falls in the |
  683. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  684. | |
  685. | var1 |
  686. | 16 bit short signed integer (Word16) whose value falls in the |
  687. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  688. | |
  689. | var2 |
  690. | 16 bit short signed integer (Word16) whose value falls in the |
  691. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  692. | |
  693. | Outputs : |
  694. | |
  695. | none |
  696. | |
  697. | Return Value : |
  698. | |
  699. | L_var_out |
  700. | 32 bit long signed integer (Word32) whose value falls in the |
  701. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  702. |___________________________________________________________________________|
  703. */
  704. Word32 L_msu_ex (Word32 L_var3, Word16 var1, Word16 var2)
  705. {
  706. Word32 L_var_out;
  707. Word32 L_product;
  708. L_product = L_mult_ex (var1, var2);
  709. #if (WMOPS)
  710. multiCounter[currCounter].L_mult_ex--;
  711. #endif
  712. L_var_out = L_sub_ex (L_var3, L_product);
  713. #if (WMOPS)
  714. multiCounter[currCounter].L_sub_ex--;
  715. multiCounter[currCounter].L_msu_ex++;
  716. #endif
  717. return (L_var_out);
  718. }
  719. /*___________________________________________________________________________
  720. | |
  721. | Function Name : L_macNs |
  722. | |
  723. | Purpose : |
  724. | |
  725. | Multiply var1 by var2 and shift the result left by 1. Add the 32 bit |
  726. | result to L_var3 without saturation, return a 32 bit result. Generate |
  727. | carry and overflow values : |
  728. | L_macNs(L_var3,var1,var2) = L_add_c(L_var3,L_mult_ex(var1,var2)). |
  729. | |
  730. | Complexity weight : 1 |
  731. | |
  732. | Inputs : |
  733. | |
  734. | L_var3 32 bit long signed integer (Word32) whose value falls in the |
  735. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  736. | |
  737. | var1 |
  738. | 16 bit short signed integer (Word16) whose value falls in the |
  739. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  740. | |
  741. | var2 |
  742. | 16 bit short signed integer (Word16) whose value falls in the |
  743. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  744. | |
  745. | Outputs : |
  746. | |
  747. | none |
  748. | |
  749. | Return Value : |
  750. | |
  751. | L_var_out |
  752. | 32 bit long signed integer (Word32) whose value falls in the |
  753. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  754. | |
  755. | Caution : |
  756. | |
  757. | In some cases the Carry flag has to be cleared or set before using |
  758. | operators which take into account its value. |
  759. |___________________________________________________________________________|
  760. */
  761. Word32 L_macNs (Word32 L_var3, Word16 var1, Word16 var2)
  762. {
  763. Word32 L_var_out;
  764. L_var_out = L_mult_ex (var1, var2);
  765. #if (WMOPS)
  766. multiCounter[currCounter].L_mult_ex--;
  767. #endif
  768. L_var_out = L_add_c (L_var3, L_var_out);
  769. #if (WMOPS)
  770. multiCounter[currCounter].L_add_c--;
  771. multiCounter[currCounter].L_macNs++;
  772. #endif
  773. return (L_var_out);
  774. }
  775. /*___________________________________________________________________________
  776. | |
  777. | Function Name : L_msuNs |
  778. | |
  779. | Purpose : |
  780. | |
  781. | Multiply var1 by var2 and shift the result left by 1. Subtract the 32 |
  782. | bit result from L_var3 without saturation, return a 32 bit result. Ge- |
  783. | nerate carry and overflow values : |
  784. | L_msuNs(L_var3,var1,var2) = L_sub_c(L_var3,L_mult_ex(var1,var2)). |
  785. | |
  786. | Complexity weight : 1 |
  787. | |
  788. | Inputs : |
  789. | |
  790. | L_var3 32 bit long signed integer (Word32) whose value falls in the |
  791. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  792. | |
  793. | var1 |
  794. | 16 bit short signed integer (Word16) whose value falls in the |
  795. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  796. | |
  797. | var2 |
  798. | 16 bit short signed integer (Word16) whose value falls in the |
  799. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  800. | |
  801. | Outputs : |
  802. | |
  803. | none |
  804. | |
  805. | Return Value : |
  806. | |
  807. | L_var_out |
  808. | 32 bit long signed integer (Word32) whose value falls in the |
  809. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  810. | |
  811. | Caution : |
  812. | |
  813. | In some cases the Carry flag has to be cleared or set before using |
  814. | operators which take into account its value. |
  815. |___________________________________________________________________________|
  816. */
  817. Word32 L_msuNs (Word32 L_var3, Word16 var1, Word16 var2)
  818. {
  819. Word32 L_var_out;
  820. L_var_out = L_mult_ex (var1, var2);
  821. #if (WMOPS)
  822. multiCounter[currCounter].L_mult_ex--;
  823. #endif
  824. L_var_out = L_sub_c (L_var3, L_var_out);
  825. #if (WMOPS)
  826. multiCounter[currCounter].L_sub_c--;
  827. multiCounter[currCounter].L_msuNs++;
  828. #endif
  829. return (L_var_out);
  830. }
  831. /*___________________________________________________________________________
  832. | |
  833. | Function Name : L_add_ex |
  834. | |
  835. | Purpose : |
  836. | |
  837. | 32 bits addition of the two 32 bits variables (L_var1+L_var2) with |
  838. | overflow control and saturation; the result is set at +2147483647 when |
  839. | overflow occurs or at -2147483648 when underflow occurs. |
  840. | |
  841. | Complexity weight : 2 |
  842. | |
  843. | Inputs : |
  844. | |
  845. | L_var1 32 bit long signed integer (Word32) whose value falls in the |
  846. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  847. | |
  848. | L_var2 32 bit long signed integer (Word32) whose value falls in the |
  849. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  850. | |
  851. | Outputs : |
  852. | |
  853. | none |
  854. | |
  855. | Return Value : |
  856. | |
  857. | L_var_out |
  858. | 32 bit long signed integer (Word32) whose value falls in the |
  859. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  860. |___________________________________________________________________________|
  861. */
  862. Word32 L_add_ex (Word32 L_var1, Word32 L_var2)
  863. {
  864. Word32 L_var_out;
  865. L_var_out = L_var1 + L_var2;
  866. if (((L_var1 ^ L_var2) & MIN_32) == 0)
  867. {
  868. if ((L_var_out ^ L_var1) & MIN_32)
  869. {
  870. L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32;
  871. Overflow = 1;
  872. }
  873. }
  874. #if (WMOPS)
  875. multiCounter[currCounter].L_add_ex++;
  876. #endif
  877. return (L_var_out);
  878. }
  879. /*___________________________________________________________________________
  880. | |
  881. | Function Name : L_sub_ex |
  882. | |
  883. | Purpose : |
  884. | |
  885. | 32 bits subtraction of the two 32 bits variables (L_var1-L_var2) with |
  886. | overflow control and saturation; the result is set at +2147483647 when |
  887. | overflow occurs or at -2147483648 when underflow occurs. |
  888. | |
  889. | Complexity weight : 2 |
  890. | |
  891. | Inputs : |
  892. | |
  893. | L_var1 32 bit long signed integer (Word32) whose value falls in the |
  894. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  895. | |
  896. | L_var2 32 bit long signed integer (Word32) whose value falls in the |
  897. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  898. | |
  899. | Outputs : |
  900. | |
  901. | none |
  902. | |
  903. | Return Value : |
  904. | |
  905. | L_var_out |
  906. | 32 bit long signed integer (Word32) whose value falls in the |
  907. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  908. |___________________________________________________________________________|
  909. */
  910. Word32 L_sub_ex (Word32 L_var1, Word32 L_var2)
  911. {
  912. Word32 L_var_out;
  913. L_var_out = L_var1 - L_var2;
  914. if (((L_var1 ^ L_var2) & MIN_32) != 0)
  915. {
  916. if ((L_var_out ^ L_var1) & MIN_32)
  917. {
  918. L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32;
  919. Overflow = 1;
  920. }
  921. }
  922. #if (WMOPS)
  923. multiCounter[currCounter].L_sub_ex++;
  924. #endif
  925. return (L_var_out);
  926. }
  927. /*___________________________________________________________________________
  928. | |
  929. | Function Name : L_add_c |
  930. | |
  931. | Purpose : |
  932. | |
  933. | Performs 32 bits addition of the two 32 bits variables (L_var1+L_var2+C)|
  934. | with carry. No saturation. Generate carry and Overflow values. The car- |
  935. | ry and overflow values are binary variables which can be tested and as- |
  936. | signed values. |
  937. | |
  938. | Complexity weight : 2 |
  939. | |
  940. | Inputs : |
  941. | |
  942. | L_var1 32 bit long signed integer (Word32) whose value falls in the |
  943. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  944. | |
  945. | L_var2 32 bit long signed integer (Word32) whose value falls in the |
  946. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  947. | |
  948. | Outputs : |
  949. | |
  950. | none |
  951. | |
  952. | Return Value : |
  953. | |
  954. | L_var_out |
  955. | 32 bit long signed integer (Word32) whose value falls in the |
  956. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  957. | |
  958. | Caution : |
  959. | |
  960. | In some cases the Carry flag has to be cleared or set before using |
  961. | operators which take into account its value. |
  962. |___________________________________________________________________________|
  963. */
  964. Word32 L_add_c (Word32 L_var1, Word32 L_var2)
  965. {
  966. Word32 L_var_out;
  967. Word32 L_test;
  968. Flag carry_int = 0;
  969. L_var_out = L_var1 + L_var2 + Carry;
  970. L_test = L_var1 + L_var2;
  971. if ((L_var1 > 0) && (L_var2 > 0) && (L_test < 0))
  972. {
  973. Overflow = 1;
  974. carry_int = 0;
  975. }
  976. else
  977. {
  978. if ((L_var1 < 0) && (L_var2 < 0))
  979. {
  980. if (L_test >= 0)
  981. {
  982. Overflow = 1;
  983. carry_int = 1;
  984. }
  985. else
  986. {
  987. Overflow = 0;
  988. carry_int = 1;
  989. }
  990. }
  991. else
  992. {
  993. if (((L_var1 ^ L_var2) < 0) && (L_test >= 0))
  994. {
  995. Overflow = 0;
  996. carry_int = 1;
  997. }
  998. else
  999. {
  1000. Overflow = 0;
  1001. carry_int = 0;
  1002. }
  1003. }
  1004. }
  1005. if (Carry)
  1006. {
  1007. if (L_test == MAX_32)
  1008. {
  1009. Overflow = 1;
  1010. Carry = carry_int;
  1011. }
  1012. else
  1013. {
  1014. if (L_test == (Word32) 0xFFFFFFFFL)
  1015. {
  1016. Carry = 1;
  1017. }
  1018. else
  1019. {
  1020. Carry = carry_int;
  1021. }
  1022. }
  1023. }
  1024. else
  1025. {
  1026. Carry = carry_int;
  1027. }
  1028. #if (WMOPS)
  1029. multiCounter[currCounter].L_add_c++;
  1030. #endif
  1031. return (L_var_out);
  1032. }
  1033. /*___________________________________________________________________________
  1034. | |
  1035. | Function Name : L_sub_c |
  1036. | |
  1037. | Purpose : |
  1038. | |
  1039. | Performs 32 bits subtraction of the two 32 bits variables with carry |
  1040. | (borrow) : L_var1-L_var2-C. No saturation. Generate carry and Overflow |
  1041. | values. The carry and overflow values are binary variables which can |
  1042. | be tested and assigned values. |
  1043. | |
  1044. | Complexity weight : 2 |
  1045. | |
  1046. | Inputs : |
  1047. | |
  1048. | L_var1 32 bit long signed integer (Word32) whose value falls in the |
  1049. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  1050. | |
  1051. | L_var2 32 bit long signed integer (Word32) whose value falls in the |
  1052. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  1053. | |
  1054. | Outputs : |
  1055. | |
  1056. | none |
  1057. | |
  1058. | Return Value : |
  1059. | |
  1060. | L_var_out |
  1061. | 32 bit long signed integer (Word32) whose value falls in the |
  1062. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  1063. | |
  1064. | Caution : |
  1065. | |
  1066. | In some cases the Carry flag has to be cleared or set before using |
  1067. | operators which take into account its value. |
  1068. |___________________________________________________________________________|
  1069. */
  1070. Word32 L_sub_c (Word32 L_var1, Word32 L_var2)
  1071. {
  1072. Word32 L_var_out;
  1073. Word32 L_test;
  1074. Flag carry_int = 0;
  1075. if (Carry)
  1076. {
  1077. Carry = 0;
  1078. if (L_var2 != MIN_32)
  1079. {
  1080. L_var_out = L_add_c (L_var1, -L_var2);
  1081. #if (WMOPS)
  1082. multiCounter[currCounter].L_add_c--;
  1083. #endif
  1084. }
  1085. else
  1086. {
  1087. L_var_out = L_var1 - L_var2;
  1088. if (L_var1 > 0L)
  1089. {
  1090. Overflow = 1;
  1091. Carry = 0;
  1092. }
  1093. }
  1094. }
  1095. else
  1096. {
  1097. L_var_out = L_var1 - L_var2 - (Word32) 0X00000001L;
  1098. L_test = L_var1 - L_var2;
  1099. if ((L_test < 0) && (L_var1 > 0) && (L_var2 < 0))
  1100. {
  1101. Overflow = 1;
  1102. carry_int = 0;
  1103. }
  1104. else if ((L_test > 0) && (L_var1 < 0) && (L_var2 > 0))
  1105. {
  1106. Overflow = 1;
  1107. carry_int = 1;
  1108. }
  1109. else if ((L_test > 0) && ((L_var1 ^ L_var2) > 0))
  1110. {
  1111. Overflow = 0;
  1112. carry_int = 1;
  1113. }
  1114. if (L_test == MIN_32)
  1115. {
  1116. Overflow = 1;
  1117. Carry = carry_int;
  1118. }
  1119. else
  1120. {
  1121. Carry = carry_int;
  1122. }
  1123. }
  1124. #if (WMOPS)
  1125. multiCounter[currCounter].L_sub_c++;
  1126. #endif
  1127. return (L_var_out);
  1128. }
  1129. /*___________________________________________________________________________
  1130. | |
  1131. | Function Name : L_negate_ex |
  1132. | |
  1133. | Purpose : |
  1134. | |
  1135. | Negate the 32 bit variable L_var1 with saturation; saturate in the case |
  1136. | where input is -2147483648 (0x8000 0000). |
  1137. | |
  1138. | Complexity weight : 2 |
  1139. | |
  1140. | Inputs : |
  1141. | |
  1142. | L_var1 32 bit long signed integer (Word32) whose value falls in the |
  1143. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  1144. | |
  1145. | Outputs : |
  1146. | |
  1147. | none |
  1148. | |
  1149. | Return Value : |
  1150. | |
  1151. | L_var_out |
  1152. | 32 bit long signed integer (Word32) whose value falls in the |
  1153. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  1154. |___________________________________________________________________________|
  1155. */
  1156. Word32 L_negate_ex (Word32 L_var1)
  1157. {
  1158. Word32 L_var_out;
  1159. L_var_out = (L_var1 == MIN_32) ? MAX_32 : -L_var1;
  1160. #if (WMOPS)
  1161. multiCounter[currCounter].L_negate_ex++;
  1162. #endif
  1163. return (L_var_out);
  1164. }
  1165. /*___________________________________________________________________________
  1166. | |
  1167. | Function Name : mult_r_ex |
  1168. | |
  1169. | Purpose : |
  1170. | |
  1171. | Same as mult_ex with rounding, i.e.: |
  1172. | mult_r_ex(var1,var2) = extract_l_ex(L_shr_ex(((var1 * var2) + 16384),15)) and |
  1173. | mult_r_ex(-32768,-32768) = 32767. |
  1174. | |
  1175. | Complexity weight : 2 |
  1176. | |
  1177. | Inputs : |
  1178. | |
  1179. | var1 |
  1180. | 16 bit short signed integer (Word16) whose value falls in the |
  1181. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1182. | |
  1183. | var2 |
  1184. | 16 bit short signed integer (Word16) whose value falls in the |
  1185. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1186. | |
  1187. | Outputs : |
  1188. | |
  1189. | none |
  1190. | |
  1191. | Return Value : |
  1192. | |
  1193. | var_out |
  1194. | 16 bit short signed integer (Word16) whose value falls in the |
  1195. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  1196. |___________________________________________________________________________|
  1197. */
  1198. Word16 mult_r_ex (Word16 var1, Word16 var2)
  1199. {
  1200. Word16 var_out;
  1201. Word32 L_product_arr;
  1202. L_product_arr = (Word32) var1 *(Word32) var2; /* product */
  1203. L_product_arr += (Word32) 0x00004000L; /* round */
  1204. L_product_arr &= (Word32) 0xffff8000L;
  1205. L_product_arr >>= 15; /* shift */
  1206. if (L_product_arr & (Word32) 0x00010000L) /* sign extend when necessary */
  1207. {
  1208. L_product_arr |= (Word32) 0xffff0000L;
  1209. }
  1210. var_out = saturate (L_product_arr);
  1211. #if (WMOPS)
  1212. multiCounter[currCounter].mult_r_ex++;
  1213. #endif
  1214. return (var_out);
  1215. }
  1216. /*___________________________________________________________________________
  1217. | |
  1218. | Function Name : L_shl_ex |
  1219. | |
  1220. | Purpose : |
  1221. | |
  1222. | Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero |
  1223. | fill the var2 LSB of the result. If var2 is negative, arithmetically |
  1224. | shift L_var1 right by -var2 with sign extension. Saturate the result in |
  1225. | case of underflows or overflows. |
  1226. | |
  1227. | Complexity weight : 2 |
  1228. | |
  1229. | Inputs : |
  1230. | |
  1231. | L_var1 32 bit long signed integer (Word32) whose value falls in the |
  1232. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  1233. | |
  1234. | var2 |
  1235. | 16 bit short signed integer (Word16) whose value falls in the |
  1236. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1237. | |
  1238. | Outputs : |
  1239. | |
  1240. | none |
  1241. | |
  1242. | Return Value : |
  1243. | |
  1244. | L_var_out |
  1245. | 32 bit long signed integer (Word32) whose value falls in the |
  1246. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  1247. |___________________________________________________________________________|
  1248. */
  1249. Word32 L_shl_ex (Word32 L_var1, Word16 var2)
  1250. {
  1251. Word32 L_var_out;
  1252. if (var2 <= 0)
  1253. {
  1254. if (var2 < -32)
  1255. var2 = -32;
  1256. L_var_out = L_shr_ex (L_var1, -var2);
  1257. #if (WMOPS)
  1258. multiCounter[currCounter].L_shr_ex--;
  1259. #endif
  1260. }
  1261. else
  1262. {
  1263. for (; var2 > 0; var2--)
  1264. {
  1265. if (L_var1 > (Word32) 0X3fffffffL)
  1266. {
  1267. Overflow = 1;
  1268. L_var_out = MAX_32;
  1269. break;
  1270. }
  1271. else
  1272. {
  1273. if (L_var1 < (Word32) 0xc0000000L)
  1274. {
  1275. Overflow = 1;
  1276. L_var_out = MIN_32;
  1277. break;
  1278. }
  1279. }
  1280. L_var1 *= 2;
  1281. L_var_out = L_var1;
  1282. }
  1283. }
  1284. #if (WMOPS)
  1285. multiCounter[currCounter].L_shl_ex++;
  1286. #endif
  1287. return (L_var_out);
  1288. }
  1289. /*___________________________________________________________________________
  1290. | |
  1291. | Function Name : L_shr_ex |
  1292. | |
  1293. | Purpose : |
  1294. | |
  1295. | Arithmetically shift the 32 bit input L_var1 right var2 positions with |
  1296. | sign extension. If var2 is negative, arithmetically shift L_var1 left |
  1297. | by -var2 and zero fill the -var2 LSB of the result. Saturate the result |
  1298. | in case of underflows or overflows. |
  1299. | |
  1300. | Complexity weight : 2 |
  1301. | |
  1302. | Inputs : |
  1303. | |
  1304. | L_var1 32 bit long signed integer (Word32) whose value falls in the |
  1305. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  1306. | |
  1307. | var2 |
  1308. | 16 bit short signed integer (Word16) whose value falls in the |
  1309. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1310. | |
  1311. | Outputs : |
  1312. | |
  1313. | none |
  1314. | |
  1315. | Return Value : |
  1316. | |
  1317. | L_var_out |
  1318. | 32 bit long signed integer (Word32) whose value falls in the |
  1319. | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
  1320. |___________________________________________________________________________|
  1321. */
  1322. Word32 L_shr_ex (Word32 L_var1, Word16 var2)
  1323. {
  1324. Word32 L_var_out;
  1325. if (var2 < 0)
  1326. {
  1327. if (var2 < -32)
  1328. var2 = -32;
  1329. L_var_out = L_shl_ex (L_var1, -var2);
  1330. #if (WMOPS)
  1331. multiCounter[currCounter].L_shl_ex--;
  1332. #endif
  1333. }
  1334. else
  1335. {
  1336. if (var2 >= 31)
  1337. {
  1338. L_var_out = (L_var1 < 0L) ? -1 : 0;
  1339. }
  1340. else
  1341. {
  1342. if (L_var1 < 0)
  1343. {
  1344. L_var_out = ~((~L_var1) >> var2);
  1345. }
  1346. else
  1347. {
  1348. L_var_out = L_var1 >> var2;
  1349. }
  1350. }
  1351. }
  1352. #if (WMOPS)
  1353. multiCounter[currCounter].L_shr_ex++;
  1354. #endif
  1355. return (L_var_out);
  1356. }
  1357. /*___________________________________________________________________________
  1358. | |
  1359. | Function Name : shr_r |
  1360. | |
  1361. | Purpose : |
  1362. | |
  1363. | Same as shr_ex(var1,var2) but with rounding. Saturate the result in case of|
  1364. | underflows or overflows : |
  1365. | - If var2 is greater than zero : |
  1366. | if (sub_ex(shl_ex(shr_ex(var1,var2),1),shr_ex(var1,sub_ex(var2,1)))) |
  1367. | is equal to zero |
  1368. | then |
  1369. | shr_r(var1,var2) = shr_ex(var1,var2) |
  1370. | else |
  1371. | shr_r(var1,var2) = add(shr_ex(var1,var2),1) |
  1372. | - If var2 is less than or equal to zero : |
  1373. | shr_r(var1,var2) = shr_ex(var1,var2). |
  1374. | |
  1375. | Complexity weight : 2 |
  1376. | |
  1377. | Inputs : |
  1378. | |
  1379. | var1 |
  1380. | 16 bit short signed integer (Word16) whose value falls in the |
  1381. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1382. | |
  1383. | var2 |
  1384. | 16 bit short signed integer (Word16) whose value falls in the |
  1385. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1386. | |
  1387. | Outputs : |
  1388. | |
  1389. | none |
  1390. | |
  1391. | Return Value : |
  1392. | |
  1393. | var_out |
  1394. | 16 bit short signed integer (Word16) whose value falls in the |
  1395. | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
  1396. |___________________________________________________________________________|
  1397. */
  1398. Word16 shr_r_ex (Word16 var1, Word16 var2)
  1399. {
  1400. Word16 var_out;
  1401. if (var2 > 15)
  1402. {
  1403. var_out = 0;
  1404. }
  1405. else
  1406. {
  1407. var_out = shr_ex (var1, var2);
  1408. #if (WMOPS)
  1409. multiCounter[currCounter].shr_ex--;
  1410. #endif
  1411. if (var2 > 0)
  1412. {
  1413. if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)
  1414. {
  1415. var_out++;
  1416. }
  1417. }
  1418. }
  1419. #if (WMOPS)
  1420. multiCounter[currCounter].shr_r++;
  1421. #endif
  1422. return (var_out);
  1423. }
  1424. /*___________________________________________________________________________
  1425. | |
  1426. | Function Name : mac_r_ex |
  1427. | |
  1428. | Purpose : |
  1429. | |
  1430. | Multiply var1 by var2 and shift the result left by 1. Add the 32 bit |
  1431. | result to L_var3 with saturation. Round the LS 16 bits of the result |
  1432. | into the MS 16 bits with saturation and shift the result right by 16. |
  1433. | Return a 16 bit result. |
  1434. | mac_r_ex(L_var3,var1,var2) = round(L_mac_ex(L_var3,var1,var2)) |
  1435. | |
  1436. | Complexity weight : 2 |
  1437. | |
  1438. | Inputs : |
  1439. | |
  1440. | L_var3 32 bit long signed integer (Word32) whose value falls in the |
  1441. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  1442. | |
  1443. | var1 |
  1444. | 16 bit short signed integer (Word16) whose value falls in the |
  1445. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1446. | |
  1447. | var2 |
  1448. | 16 bit short signed integer (Word16) whose value falls in the |
  1449. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1450. | |
  1451. | Outputs : |
  1452. | |
  1453. | none |
  1454. | |
  1455. | Return Value : |
  1456. | |
  1457. | var_out |
  1458. | 16 bit short signed integer (Word16) whose value falls in the |
  1459. | range : 0x0000 8000 <= L_var_out <= 0x0000 7fff. |
  1460. |___________________________________________________________________________|
  1461. */
  1462. Word16 mac_r_ex (Word32 L_var3, Word16 var1, Word16 var2)
  1463. {
  1464. Word16 var_out;
  1465. L_var3 = L_mac_ex (L_var3, var1, var2);
  1466. #if (WMOPS)
  1467. multiCounter[currCounter].L_mac_ex--;
  1468. #endif
  1469. L_var3 = L_add_ex (L_var3, (Word32) 0x00008000L);
  1470. #if (WMOPS)
  1471. multiCounter[currCounter].L_add_ex--;
  1472. #endif
  1473. var_out = extract_h_ex (L_var3);
  1474. #if (WMOPS)
  1475. multiCounter[currCounter].extract_h_ex--;
  1476. multiCounter[currCounter].mac_r_ex++;
  1477. #endif
  1478. return (var_out);
  1479. }
  1480. /*___________________________________________________________________________
  1481. | |
  1482. | Function Name : msu_r_ex |
  1483. | |
  1484. | Purpose : |
  1485. | |
  1486. | Multiply var1 by var2 and shift the result left by 1. Subtract the 32 |
  1487. | bit result to L_var3 with saturation. Round the LS 16 bits of the res- |
  1488. | ult into the MS 16 bits with saturation and shift the result right by |
  1489. | 16. Return a 16 bit result. |
  1490. | msu_r_ex(L_var3,var1,var2) = round(L_msu_ex(L_var3,var1,var2)) |
  1491. | |
  1492. | Complexity weight : 2 |
  1493. | |
  1494. | Inputs : |
  1495. | |
  1496. | L_var3 32 bit long signed integer (Word32) whose value falls in the |
  1497. | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
  1498. | |
  1499. | var1 |
  1500. | 16 bit short signed integer (Word16) whose value falls in the |
  1501. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1502. | |
  1503. | var2 |
  1504. | 16 bit short signed integer (Word16) whose value falls in the |
  1505. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1506. | |
  1507. | Outputs : |
  1508. | |
  1509. | none |
  1510. | |
  1511. | Return Value : |
  1512. | |
  1513. | var_out |
  1514. | 16 bit short signed integer (Word16) whose value falls in the |
  1515. | range : 0x0000 8000 <= L_var_out <= 0x0000 7fff. |
  1516. |___________________________________________________________________________|
  1517. */
  1518. Word16 msu_r_ex (Word32 L_var3, Word16 var1, Word16 var2)
  1519. {
  1520. Word16 var_out;
  1521. L_var3 = L_msu_ex (L_var3, var1, var2);
  1522. #if (WMOPS)
  1523. multiCounter[currCounter].L_msu_ex--;
  1524. #endif
  1525. L_var3 = L_add_ex (L_var3, (Word32) 0x00008000L);
  1526. #if (WMOPS)
  1527. multiCounter[currCounter].L_add_ex--;
  1528. #endif
  1529. var_out = extract_h_ex (L_var3);
  1530. #if (WMOPS)
  1531. multiCounter[currCounter].extract_h_ex--;
  1532. multiCounter[currCounter].msu_r_ex++;
  1533. #endif
  1534. return (var_out);
  1535. }
  1536. /*___________________________________________________________________________
  1537. | |
  1538. | Function Name : L_deposit_h_ex |
  1539. | |
  1540. | Purpose : |
  1541. | |
  1542. | Deposit the 16 bit var1 into the 16 MS bits of the 32 bit output. The |
  1543. | 16 LS bits of the output are zeroed. |
  1544. | |
  1545. | Complexity weight : 2 |
  1546. | |
  1547. | Inputs : |
  1548. | |
  1549. | var1 |
  1550. | 16 bit short signed integer (Word16) whose value falls in the |
  1551. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1552. | |
  1553. | Outputs : |
  1554. | |
  1555. | none |
  1556. | |
  1557. | Return Value : |
  1558. | |
  1559. | L_var_out |
  1560. | 32 bit long signed integer (Word32) whose value falls in the |
  1561. | range : 0x8000 0000 <= var_out <= 0x7fff 0000. |
  1562. |___________________________________________________________________________|
  1563. */
  1564. Word32 L_deposit_h_ex (Word16 var1)
  1565. {
  1566. Word32 L_var_out;
  1567. L_var_out = (Word32) var1 << 16;
  1568. #if (WMOPS)
  1569. multiCounter[currCounter].L_deposit_h_ex++;
  1570. #endif
  1571. return (L_var_out);
  1572. }
  1573. /*___________________________________________________________________________
  1574. | |
  1575. | Function Name : L_deposit_l_ex |
  1576. | |
  1577. | Purpose : |
  1578. | |
  1579. | Deposit the 16 bit var1 into the 16 LS bits of the 32 bit output. The |
  1580. | 16 MS bits of the output are sign extended. |
  1581. | |
  1582. | Complexity weight : 2 |
  1583. | |
  1584. | Inputs : |
  1585. | |
  1586. | var1 |
  1587. | 16 bit short signed integer (Word16) whose value falls in the |
  1588. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1589. | |
  1590. | Outputs : |
  1591. | |
  1592. | none |
  1593. | |
  1594. | Return Value : |
  1595. | |
  1596. | L_var_out |
  1597. | 32 bit long signed integer (Word32) whose value falls in the |
  1598. | range : 0xFFFF 8000 <= var_out <= 0x0000 7fff. |
  1599. |___________________________________________________________________________|
  1600. */
  1601. Word32 L_deposit_l_ex (Word16 var1)
  1602. {
  1603. Word32 L_var_out;
  1604. L_var_out = (Word32) var1;
  1605. #if (WMOPS)
  1606. multiCounter[currCounter].L_deposit_l_ex++;
  1607. #endif
  1608. return (L_var_out);
  1609. }
  1610. /*___________________________________________________________________________
  1611. | |
  1612. | Function Name : L_shr_r |
  1613. | |
  1614. | Purpose : |
  1615. | |
  1616. | Same as L_shr_ex(L_var1,var2) but with rounding. Saturate the result in |
  1617. | case of underflows or overflows : |
  1618. | - If var2 is greater than zero : |
  1619. | if (L_sub_ex(L_shl_ex(L_shr_ex(L_var1,var2),1),L_shr_ex(L_var1,sub_ex(var2,1))))|
  1620. | is equal to zero |
  1621. | then |
  1622. | L_shr_r(L_var1,var2) = L_shr_ex(L_var1,var2) |
  1623. | else |
  1624. | L_shr_r(L_var1,var2) = L_add_ex(L_shr_ex(L_var1,var2),1) |
  1625. | - If var2 is less than or equal to zero : |
  1626. | L_shr_r(L_var1,var2) = L_shr_ex(L_var1,var2). |
  1627. | |
  1628. | Complexity weight : 3 |
  1629. | |
  1630. | Inputs : |
  1631. | |
  1632. | L_var1 |
  1633. | 32 bit long signed integer (Word32) whose value falls in the |
  1634. | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
  1635. | |
  1636. | var2 |
  1637. | 16 bit short signed integer (Word16) whose value falls in the |
  1638. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1639. | |
  1640. | Outputs : |
  1641. | |
  1642. | none |
  1643. | |
  1644. | Return Value : |
  1645. | |
  1646. | L_var_out |
  1647. | 32 bit long signed integer (Word32) whose value falls in the |
  1648. | range : 0x8000 0000 <= var_out <= 0x7fff ffff. |
  1649. |___________________________________________________________________________|
  1650. */
  1651. Word32 L_shr_r_ex (Word32 L_var1, Word16 var2)
  1652. {
  1653. Word32 L_var_out;
  1654. if (var2 > 31)
  1655. {
  1656. L_var_out = 0;
  1657. }
  1658. else
  1659. {
  1660. L_var_out = L_shr_ex (L_var1, var2);
  1661. #if (WMOPS)
  1662. multiCounter[currCounter].L_shr_ex--;
  1663. #endif
  1664. if (var2 > 0)
  1665. {
  1666. if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)
  1667. {
  1668. L_var_out++;
  1669. }
  1670. }
  1671. }
  1672. #if (WMOPS)
  1673. multiCounter[currCounter].L_shr_r++;
  1674. #endif
  1675. return (L_var_out);
  1676. }
  1677. /*___________________________________________________________________________
  1678. | |
  1679. | Function Name : L_abs_ex |
  1680. | |
  1681. | Purpose : |
  1682. | |
  1683. | Absolute value of L_var1; Saturate in case where the input is |
  1684. | -214783648 |
  1685. | |
  1686. | Complexity weight : 3 |
  1687. | |
  1688. | Inputs : |
  1689. | |
  1690. | L_var1 |
  1691. | 32 bit long signed integer (Word32) whose value falls in the |
  1692. | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
  1693. | |
  1694. | Outputs : |
  1695. | |
  1696. | none |
  1697. | |
  1698. | Return Value : |
  1699. | |
  1700. | L_var_out |
  1701. | 32 bit long signed integer (Word32) whose value falls in the |
  1702. | range : 0x0000 0000 <= var_out <= 0x7fff ffff. |
  1703. |___________________________________________________________________________|
  1704. */
  1705. Word32 L_abs_ex (Word32 L_var1)
  1706. {
  1707. Word32 L_var_out;
  1708. if (L_var1 == MIN_32)
  1709. {
  1710. L_var_out = MAX_32;
  1711. }
  1712. else
  1713. {
  1714. if (L_var1 < 0)
  1715. {
  1716. L_var_out = -L_var1;
  1717. }
  1718. else
  1719. {
  1720. L_var_out = L_var1;
  1721. }
  1722. }
  1723. #if (WMOPS)
  1724. multiCounter[currCounter].L_abs_ex++;
  1725. #endif
  1726. return (L_var_out);
  1727. }
  1728. /*___________________________________________________________________________
  1729. | |
  1730. | Function Name : L_sat |
  1731. | |
  1732. | Purpose : |
  1733. | |
  1734. | 32 bit L_var1 is set to 2147483647 if an overflow occured or to |
  1735. | -2147483648 if an underflow occured on the most recent L_add_c, |
  1736. | L_sub_c, L_macNs or L_msuNs operations. The carry and overflow values |
  1737. | are binary values which can be tested and assigned values. |
  1738. | |
  1739. | Complexity weight : 4 |
  1740. | |
  1741. | Inputs : |
  1742. | |
  1743. | L_var1 |
  1744. | 32 bit long signed integer (Word32) whose value falls in the |
  1745. | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
  1746. | |
  1747. | Outputs : |
  1748. | |
  1749. | none |
  1750. | |
  1751. | Return Value : |
  1752. | |
  1753. | L_var_out |
  1754. | 32 bit long signed integer (Word32) whose value falls in the |
  1755. | range : 0x8000 0000 <= var_out <= 0x7fff ffff. |
  1756. |___________________________________________________________________________|
  1757. */
  1758. Word32 L_sat (Word32 L_var1)
  1759. {
  1760. Word32 L_var_out;
  1761. L_var_out = L_var1;
  1762. if (Overflow)
  1763. {
  1764. if (Carry)
  1765. {
  1766. L_var_out = MIN_32;
  1767. }
  1768. else
  1769. {
  1770. L_var_out = MAX_32;
  1771. }
  1772. Carry = 0;
  1773. Overflow = 0;
  1774. }
  1775. #if (WMOPS)
  1776. multiCounter[currCounter].L_sat++;
  1777. #endif
  1778. return (L_var_out);
  1779. }
  1780. /*___________________________________________________________________________
  1781. | |
  1782. | Function Name : norm_s_ex |
  1783. | |
  1784. | Purpose : |
  1785. | |
  1786. | Produces the number of left shift needed to normalize the 16 bit varia- |
  1787. | ble var1 for positive values on the interval with minimum of 16384 and |
  1788. | maximum of 32767, and for negative values on the interval with minimum |
  1789. | of -32768 and maximum of -16384; in order to normalize the result, the |
  1790. | following operation must be done : |
  1791. | norm_var1 = shl_ex(var1,norm_s_ex(var1)). |
  1792. | |
  1793. | Complexity weight : 15 |
  1794. | |
  1795. | Inputs : |
  1796. | |
  1797. | var1 |
  1798. | 16 bit short signed integer (Word16) whose value falls in the |
  1799. | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
  1800. | |
  1801. | Outputs : |
  1802. | |
  1803. | none |
  1804. | |
  1805. | Return Value : |
  1806. | |
  1807. | var_out |
  1808. | 16 bit short signed integer (Word16) whose value falls in the |
  1809. | range : 0x0000 0000 <= var_out <= 0x0000 000f. |
  1810. |___________________________________________________________________________|
  1811. */
  1812. Word16 norm_s_ex (Word16 var1)
  1813. {
  1814. Word16 var_out;
  1815. if (var1 == 0)
  1816. {
  1817. var_out = 0;
  1818. }
  1819. else
  1820. {
  1821. if (var1 == (Word16) 0xffff)
  1822. {
  1823. var_out = 15;
  1824. }
  1825. else
  1826. {
  1827. if (var1 < 0)
  1828. {
  1829. var1 = ~var1;
  1830. }
  1831. for (var_out = 0; var1 < 0x4000; var_out++)
  1832. {
  1833. var1 <<= 1;
  1834. }
  1835. }
  1836. }
  1837. #if (WMOPS)
  1838. multiCounter[currCounter].norm_s_ex++;
  1839. #endif
  1840. return (var_out);
  1841. }
  1842. /*___________________________________________________________________________
  1843. | |
  1844. | Function Name : div_s |
  1845. | |
  1846. | Purpose : |
  1847. | |
  1848. | Produces a result which is the fractional integer division of var1 by |
  1849. | var2; var1 and var2 must be positive and var2 must be greater or equal |
  1850. | to var1; the result is positive (leading bit equal to 0) and truncated |
  1851. | to 16 bits. |
  1852. | If var1 = var2 then div(var1,var2) = 32767. |
  1853. | |
  1854. | Complexity weight : 18 |
  1855. | |
  1856. | Inputs : |
  1857. | |
  1858. | var1 |
  1859. | 16 bit short signed integer (Word16) whose value falls in the |
  1860. | range : 0x0000 0000 <= var1 <= var2 and var2 != 0. |
  1861. | |
  1862. | var2 |
  1863. | 16 bit short signed integer (Word16) whose value falls in the |
  1864. | range : var1 <= var2 <= 0x0000 7fff and var2 != 0. |
  1865. | |
  1866. | Outputs : |
  1867. | |
  1868. | none |
  1869. | |
  1870. | Return Value : |
  1871. | |
  1872. | var_out |
  1873. | 16 bit short signed integer (Word16) whose value falls in the |
  1874. | range : 0x0000 0000 <= var_out <= 0x0000 7fff. |
  1875. | It's a Q15 value (point between b15 and b14). |
  1876. |___________________________________________________________________________|
  1877. */
  1878. Word16 div_s (Word16 var1, Word16 var2)
  1879. {
  1880. Word16 var_out = 0;
  1881. Word16 iteration;
  1882. Word32 L_num;
  1883. Word32 L_denom;
  1884. if ((var1 > var2) || (var1 < 0) || (var2 < 0))
  1885. {
  1886. wprintf ("Division Error var1=%d var2=%d\n", var1, var2);
  1887. #ifndef NO_EXIT_ABORT_CALL
  1888. abort(); /* exit (0); */
  1889. #else
  1890. return 0;
  1891. #endif
  1892. }
  1893. if (var2 == 0)
  1894. {
  1895. wprintf ("Division by 0, Fatal error \n");
  1896. #ifndef NO_EXIT_ABORT_CALL
  1897. abort(); /* exit (0); */
  1898. #else
  1899. return 0;
  1900. #endif
  1901. }
  1902. if (var1 == 0)
  1903. {
  1904. var_out = 0;
  1905. }
  1906. else
  1907. {
  1908. if (var1 == var2)
  1909. {
  1910. var_out = MAX_16;
  1911. }
  1912. else
  1913. {
  1914. L_num = L_deposit_l_ex (var1);
  1915. #if (WMOPS)
  1916. multiCounter[currCounter].L_deposit_l_ex--;
  1917. #endif
  1918. L_denom = L_deposit_l_ex (var2);
  1919. #if (WMOPS)
  1920. multiCounter[currCounter].L_deposit_l_ex--;
  1921. #endif
  1922. for (iteration = 0; iteration < 15; iteration++)
  1923. {
  1924. var_out <<= 1;
  1925. L_num <<= 1;
  1926. if (L_num >= L_denom)
  1927. {
  1928. L_num = L_sub_ex (L_num, L_denom);
  1929. #if (WMOPS)
  1930. multiCounter[currCounter].L_sub_ex--;
  1931. #endif
  1932. var_out = add_ex (var_out, 1);
  1933. #if (WMOPS)
  1934. multiCounter[currCounter].add_ex--;
  1935. #endif
  1936. }
  1937. }
  1938. }
  1939. }
  1940. #if (WMOPS)
  1941. multiCounter[currCounter].div_s++;
  1942. #endif
  1943. return (var_out);
  1944. }
  1945. /*___________________________________________________________________________
  1946. | |
  1947. | Function Name : norm_l_ex |
  1948. | |
  1949. | Purpose : |
  1950. | |
  1951. | Produces the number of left shifts needed to normalize the 32 bit varia-|
  1952. | ble L_var1 for positive values on the interval with minimum of |
  1953. | 1073741824 and maximum of 2147483647, and for negative values on the in-|
  1954. | terval with minimum of -2147483648 and maximum of -1073741824; in order |
  1955. | to normalize the result, the following operation must be done : |
  1956. | norm_L_var1 = L_shl_ex(L_var1,norm_l_ex(L_var1)). |
  1957. | |
  1958. | Complexity weight : 30 |
  1959. | |
  1960. | Inputs : |
  1961. | |
  1962. | L_var1 |
  1963. | 32 bit long signed integer (Word32) whose value falls in the |
  1964. | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
  1965. | |
  1966. | Outputs : |
  1967. | |
  1968. | none |
  1969. | |
  1970. | Return Value : |
  1971. | |
  1972. | var_out |
  1973. | 16 bit short signed integer (Word16) whose value falls in the |
  1974. | range : 0x0000 0000 <= var_out <= 0x0000 001f. |
  1975. |___________________________________________________________________________|
  1976. */
  1977. Word16 norm_l_ex (Word32 L_var1)
  1978. {
  1979. Word16 var_out;
  1980. if (L_var1 == 0)
  1981. {
  1982. var_out = 0;
  1983. }
  1984. else
  1985. {
  1986. if (L_var1 == (Word32) 0xffffffffL)
  1987. {
  1988. var_out = 31;
  1989. }
  1990. else
  1991. {
  1992. if (L_var1 < 0)
  1993. {
  1994. L_var1 = ~L_var1;
  1995. }
  1996. for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)
  1997. {
  1998. L_var1 <<= 1;
  1999. }
  2000. }
  2001. }
  2002. #if (WMOPS)
  2003. multiCounter[currCounter].norm_l_ex++;
  2004. #endif
  2005. return (var_out);
  2006. }