BASIC_OP.C
上传用户:meifeng08
上传日期:2013-06-18
资源大小:5304k
文件大小:102k
源码类别:

语音压缩

开发平台:

C/C++

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