LCOV - code coverage report
Current view: top level - lib_com - basop32.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 262 436 60.1 %
Date: 2025-05-23 08:37:30 Functions: 41 60 68.3 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : /*                                                      v.2.3 - 30.Nov.2009
      34             :   =============================================================================
      35             : 
      36             :                           U    U   GGG    SSSS  TTTTT
      37             :                           U    U  G       S       T
      38             :                           U    U  G  GG   SSSS    T
      39             :                           U    U  G   G       S   T
      40             :                            UUU     GG     SSS     T
      41             : 
      42             :                    ========================================
      43             :                     ITU-T - USER'S GROUP ON SOFTWARE TOOLS
      44             :                    ========================================
      45             : 
      46             :        =============================================================
      47             :        COPYRIGHT NOTE: This source code, and all of its derivations,
      48             :        is subject to the "ITU-T General Public License". Please have
      49             :        it  read  in    the  distribution  disk,   or  in  the  ITU-T
      50             :        Recommendation G.191 on "SOFTWARE TOOLS FOR SPEECH AND  AUDIO
      51             :        CODING STANDARDS".
      52             :        =============================================================
      53             : 
      54             : MODULE:         BASOP32, BASIC OPERATORS
      55             : 
      56             : ORIGINAL BY:
      57             :                 Incorporated from anonymous contributions for
      58             :                 ETSI Standards as well as G.723.1, G.729, and G.722.1
      59             : 
      60             : DESCRIPTION:
      61             :         This file contains the definition of 16- and 32-bit basic
      62             :         operators to be used in the implementation of signal
      63             :         processing algorithms. The basic operators try to resemble
      64             :         assembly language instructions that are commonly found in
      65             :         digital signal processor (DSP) CPUs, thus allowing algorithm
      66             :         C-code implementations more directly mapeable to DSP assembly
      67             :         code.
      68             : 
      69             :         *********************************************************
      70             :          NOTE: so far, this module does not have a demo program!
      71             :         *********************************************************
      72             : 
      73             : FUNCTIONS:
      74             :   Defined in basop32.h. Self-documentation within each function.
      75             : 
      76             : HISTORY:
      77             :   26.Jan.00    v1.0     Incorporated to the STL from updated G.723.1/G.729
      78             :                         basic operator library (based on basicop2.c) and
      79             :                         G.723.1's basop.c [L_mls(), div_l(), i_mult()]
      80             : 
      81             :   05.Jul.00    v1.1     Added 32-bit shiftless accumulation basic
      82             :                         operators (L_msu0, L_mac0, L_mult0). Improved
      83             :                         documentation for i_mult().
      84             : 
      85             :    03 Nov 04   v2.0     Incorporation of new 32-bit / 40-bit / control
      86             :                         operators for the ITU-T Standard Tool Library as
      87             :                         described in Geneva, 20-30 January 2004 WP 3/16 Q10/16
      88             :                         TD 11 document and subsequent discussions on the
      89             :                         wp3audio@yahoogroups.com email reflector.
      90             :                         norm_s()      weight reduced from 15 to 1.
      91             :                         norm_l()      weight reduced from 30 to 1.
      92             :                         L_abs()       weight reduced from  2 to 1.
      93             :                         L_add()       weight reduced from  2 to 1.
      94             :                         L_negate()    weight reduced from  2 to 1.
      95             :                         L_shl()       weight reduced from  2 to 1.
      96             :                         L_shr()       weight reduced from  2 to 1.
      97             :                         L_sub()       weight reduced from  2 to 1.
      98             :                         mac_r()       weight reduced from  2 to 1.
      99             :                         msu_r()       weight reduced from  2 to 1.
     100             :                         mult_r()      weight reduced from  2 to 1.
     101             :                         L_deposit_h() weight reduced from  2 to 1.
     102             :                         L_deposit_l() weight reduced from  2 to 1.
     103             :                         L_mls() weight of 5.
     104             :                         div_l() weight of 32.
     105             :                         i_mult() weight of 3.
     106             : 
     107             :    30 Nov 09   v2.3     round() function is now round_fx().
     108             :                         saturate() is not referencable from outside application
     109             :   =============================================================================
     110             : */
     111             : 
     112             : 
     113             : /*___________________________________________________________________________
     114             :  |                                                                           |
     115             :  | Basic arithmetic operators.                                               |
     116             :  |                                                                           |
     117             :  |                                                                           |
     118             :  |                                                                           |
     119             :  |       saturate()                                                          |
     120             :  |       add()                                                               |
     121             :  |       sub()                                                               |
     122             :  |       abs_s()                                                             |
     123             :  |       divide_s()                                                          |
     124             :  |       extract_h()                                                         |
     125             :  |       extract_l()                                                         |
     126             :  |       L_abs()                                                             |
     127             :  |       L_add()                                                             |
     128             :  |       L_deposit_h()                                                       |
     129             :  |       L_deposit_l()                                                       |
     130             :  |       L_mac()                                                             |
     131             :  |       L_msu()                                                             |
     132             :  |       L_mult()                                                            |
     133             :  |       L_negate()                                                          |
     134             :  |       L_shl()                                                             |
     135             :  |       L_shr()                                                             |
     136             :  |       L_sub()                                                             |
     137             :  |       mac_r()                                                             |
     138             :  |       msu_r()                                                             |
     139             :  |       mult()                                                              |
     140             :  |       mult_r()                                                            |
     141             :  |       negate()                                                            |
     142             :  |       norm_l()                                                            |
     143             :  |       norm_s()                                                            |
     144             :  |       round_fx()                                                          |
     145             :  |       shl()                                                               |
     146             :  |       shr()                                                               |
     147             :  |___________________________________________________________________________|
     148             : */
     149             : 
     150             : 
     151             : /*___________________________________________________________________________
     152             :  |                                                                           |
     153             :  |   Include-Files                                                           |
     154             :  |___________________________________________________________________________|
     155             : */
     156             : #ifndef _CRT_SECURE_NO_WARNINGS
     157             : #define _CRT_SECURE_NO_WARNINGS
     158             : #endif
     159             : 
     160             : #include <stdio.h>
     161             : #include <stdlib.h>
     162             : #include "stl.h"
     163             : #ifdef BASOP_NOGLOB
     164             : #include <assert.h>
     165             : #endif /* BASOP_NOGLOB */
     166             : 
     167             : #define WMC_TOOL_SKIP
     168             : 
     169             : #ifdef _MSC_VER
     170             : #pragma warning( disable : 4310 )
     171             : #endif
     172             : 
     173             : /*___________________________________________________________________________
     174             :  |                                                                           |
     175             :  |   Local Functions                                                         |
     176             :  |___________________________________________________________________________|
     177             : */
     178             : #ifdef BASOP_NOGLOB
     179             : static Word16 saturate_o( Word32 L_var1, Flag *Overflow );
     180             : #endif /* BASOP_NOGLOB */
     181             : static Word16 saturate( Word32 L_var1 );
     182             : 
     183             : 
     184             : /*___________________________________________________________________________
     185             :  |                                                                           |
     186             :  |   Constants and Globals                                                   |
     187             :  |___________________________________________________________________________|
     188             : */
     189             : #ifndef BASOP_NOGLOB
     190             : Flag Overflow = 0;
     191             : Flag Carry = 0;
     192             : 
     193             : #else  /* BASOP_NOGLOB */
     194             : /*
     195             : Flag BASOP_Overflow = 0;
     196             : Flag BASOP_Carry = 0;
     197             : */
     198             : #endif /* BASOP_NOGLOB */
     199             : 
     200             : /*___________________________________________________________________________
     201             :  |                                                                           |
     202             :  |   Functions                                                               |
     203             :  |___________________________________________________________________________|
     204             : */
     205             : 
     206             : #define PRINT_STACK_ID_ALL "*"
     207             : 
     208             : 
     209             : /*___________________________________________________________________________
     210             :  |                                                                           |
     211             :  |   Function Name : saturate                                                |
     212             :  |                                                                           |
     213             :  |   Purpose :                                                               |
     214             :  |                                                                           |
     215             :  |    Limit the 32 bit input to the range of a 16 bit word. Must NOT be      |
     216             :  |    referenced from outside applications.                                  |
     217             :  |                                                                           |
     218             :  |   Inputs :                                                                |
     219             :  |                                                                           |
     220             :  |    L_var1                                                                 |
     221             :  |             32 bit long signed integer (Word32) whose value falls in the  |
     222             :  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
     223             :  |                                                                           |
     224             :  |   Outputs :                                                               |
     225             :  |                                                                           |
     226             :  |    none                                                                   |
     227             :  |                                                                           |
     228             :  |   Return Value :                                                          |
     229             :  |                                                                           |
     230             :  |    var_out                                                                |
     231             :  |             16 bit short signed integer (Word16) whose value falls in the |
     232             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     233             :  |___________________________________________________________________________|
     234             : */
     235             : #ifndef BASOP_NOGLOB
     236             : static Word16 saturate( Word32 L_var1 )
     237             : #else  /* BASOP_NOGLOB */
     238           0 : static Word16 saturate_o( Word32 L_var1, Flag *Overflow )
     239             : #endif /* BASOP_NOGLOB */
     240             : {
     241             :     Word16 var_out;
     242             : 
     243           0 :     if ( L_var1 > 0X00007fffL )
     244             :     {
     245             : #ifndef BASOP_NOGLOB
     246             :         Overflow = 1;
     247             : #else  /* BASOP_NOGLOB */
     248           0 :         *Overflow = 1;
     249             : #endif /* BASOP_NOGLOB */
     250           0 :         var_out = MAX_16;
     251             :     }
     252           0 :     else if ( L_var1 < (Word32) 0xffff8000L )
     253             :     {
     254             : #ifndef BASOP_NOGLOB
     255             :         Overflow = 1;
     256             : #else  /* BASOP_NOGLOB */
     257           0 :         *Overflow = 1;
     258             : #endif /* BASOP_NOGLOB */
     259           0 :         var_out = MIN_16;
     260             :     }
     261             :     else
     262             :     {
     263           0 :         var_out = extract_l( L_var1 );
     264             : #ifdef WMOPS
     265             :         multiCounter[currCounter].extract_l--;
     266             : #endif
     267             :     }
     268             : 
     269             :     BASOP_CHECK();
     270             : 
     271           0 :     return ( var_out );
     272             : }
     273             : 
     274             : #ifdef BASOP_NOGLOB
     275   575834953 : static Word16 saturate( Word32 L_var1 )
     276             : {
     277             :     Word16 var_out;
     278             : 
     279   575834953 :     if ( L_var1 > 0X00007fffL )
     280             :     {
     281           0 :         assert( 0 );
     282             :         var_out = MAX_16;
     283             :     }
     284   575834953 :     else if ( L_var1 < (Word32) 0xffff8000L )
     285             :     {
     286           0 :         assert( 0 );
     287             :         var_out = MIN_16;
     288             :     }
     289             :     else
     290             :     {
     291   575834953 :         var_out = extract_l( L_var1 );
     292             : #ifdef WMOPS
     293             :         multiCounter[currCounter].extract_l--;
     294             : #endif
     295             :     }
     296             : 
     297             :     BASOP_CHECK();
     298             : 
     299   575834953 :     return ( var_out );
     300             : }
     301             : #endif /* BASOP_NOGLOB */
     302             : 
     303             : /*___________________________________________________________________________
     304             :  |                                                                           |
     305             :  |   Function Name : add                                                     |
     306             :  |                                                                           |
     307             :  |   Purpose :                                                               |
     308             :  |                                                                           |
     309             :  |    Performs the addition (var1+var2) with overflow control and saturation;|
     310             :  |    the 16 bit result is set at +32767 when overflow occurs or at -32768   |
     311             :  |    when underflow occurs.                                                 |
     312             :  |                                                                           |
     313             :  |   Complexity weight : 1                                                   |
     314             :  |                                                                           |
     315             :  |   Inputs :                                                                |
     316             :  |                                                                           |
     317             :  |    var1                                                                   |
     318             :  |             16 bit short signed integer (Word16) whose value falls in the |
     319             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     320             :  |                                                                           |
     321             :  |    var2                                                                   |
     322             :  |             16 bit short signed integer (Word16) whose value falls in the |
     323             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     324             :  |                                                                           |
     325             :  |   Outputs :                                                               |
     326             :  |                                                                           |
     327             :  |    none                                                                   |
     328             :  |                                                                           |
     329             :  |   Return Value :                                                          |
     330             :  |                                                                           |
     331             :  |    var_out                                                                |
     332             :  |             16 bit short signed integer (Word16) whose value falls in the |
     333             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     334             :  |___________________________________________________________________________|
     335             : */
     336             : #ifdef BASOP_NOGLOB
     337           0 : Word16 add_o( Word16 var1, Word16 var2, Flag *Overflow )
     338             : {
     339             :     Word16 var_out;
     340             :     Word32 L_sum;
     341             : 
     342           0 :     L_sum = (Word32) var1 + var2;
     343           0 :     var_out = saturate_o( L_sum, Overflow );
     344             : 
     345             : #ifdef WMOPS
     346             :     multiCounter[currCounter].add++;
     347             : #endif
     348           0 :     return ( var_out );
     349             : }
     350             : 
     351             : #endif /* BASOP_NOGLOB */
     352   144167364 : Word16 add( Word16 var1, Word16 var2 )
     353             : {
     354             :     Word16 var_out;
     355             :     Word32 L_sum;
     356             : 
     357   144167364 :     L_sum = (Word32) var1 + var2;
     358   144167364 :     var_out = saturate( L_sum );
     359             : 
     360             : #ifdef WMOPS
     361             :     multiCounter[currCounter].add++;
     362             : #endif
     363   144167364 :     return ( var_out );
     364             : }
     365             : 
     366             : 
     367             : /*___________________________________________________________________________
     368             :  |                                                                           |
     369             :  |   Function Name : sub                                                     |
     370             :  |                                                                           |
     371             :  |   Purpose :                                                               |
     372             :  |                                                                           |
     373             :  |    Performs the subtraction (var1+var2) with overflow control and satu-   |
     374             :  |    ration; the 16 bit result is set at +32767 when overflow occurs or at  |
     375             :  |    -32768 when underflow occurs.                                          |
     376             :  |                                                                           |
     377             :  |   Complexity weight : 1                                                   |
     378             :  |                                                                           |
     379             :  |   Inputs :                                                                |
     380             :  |                                                                           |
     381             :  |    var1                                                                   |
     382             :  |             16 bit short signed integer (Word16) whose value falls in the |
     383             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     384             :  |                                                                           |
     385             :  |    var2                                                                   |
     386             :  |             16 bit short signed integer (Word16) whose value falls in the |
     387             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     388             :  |                                                                           |
     389             :  |   Outputs :                                                               |
     390             :  |                                                                           |
     391             :  |    none                                                                   |
     392             :  |                                                                           |
     393             :  |   Return Value :                                                          |
     394             :  |                                                                           |
     395             :  |    var_out                                                                |
     396             :  |             16 bit short signed integer (Word16) whose value falls in the |
     397             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     398             :  |___________________________________________________________________________|
     399             : */
     400             : #ifdef BASOP_NOGLOB
     401           0 : Word16 sub_o( Word16 var1, Word16 var2, Flag *Overflow )
     402             : {
     403             :     Word16 var_out;
     404             :     Word32 L_diff;
     405             : 
     406           0 :     L_diff = (Word32) var1 - var2;
     407           0 :     var_out = saturate_o( L_diff, Overflow );
     408             : 
     409             : #ifdef WMOPS
     410             :     multiCounter[currCounter].sub++;
     411             : #endif
     412           0 :     return ( var_out );
     413             : }
     414             : 
     415             : #endif /* BASOP_NOGLOB */
     416   192579775 : Word16 sub( Word16 var1, Word16 var2 )
     417             : {
     418             :     Word16 var_out;
     419             :     Word32 L_diff;
     420             : 
     421   192579775 :     L_diff = (Word32) var1 - var2;
     422   192579775 :     var_out = saturate( L_diff );
     423             : 
     424             : #ifdef WMOPS
     425             :     multiCounter[currCounter].sub++;
     426             : #endif
     427   192579775 :     return ( var_out );
     428             : }
     429             : 
     430             : 
     431             : /*___________________________________________________________________________
     432             :  |                                                                           |
     433             :  |   Function Name : abs_s                                                   |
     434             :  |                                                                           |
     435             :  |   Purpose :                                                               |
     436             :  |                                                                           |
     437             :  |    Absolute value of var1; abs_s(-32768) = 32767.                         |
     438             :  |                                                                           |
     439             :  |   Complexity weight : 1                                                   |
     440             :  |                                                                           |
     441             :  |   Inputs :                                                                |
     442             :  |                                                                           |
     443             :  |    var1                                                                   |
     444             :  |             16 bit short signed integer (Word16) whose value falls in the |
     445             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     446             :  |                                                                           |
     447             :  |   Outputs :                                                               |
     448             :  |                                                                           |
     449             :  |    none                                                                   |
     450             :  |                                                                           |
     451             :  |   Return Value :                                                          |
     452             :  |                                                                           |
     453             :  |    var_out                                                                |
     454             :  |             16 bit short signed integer (Word16) whose value falls in the |
     455             :  |             range : 0x0000 0000 <= var_out <= 0x0000 7fff.                |
     456             :  |___________________________________________________________________________|
     457             : */
     458    15831285 : Word16 abs_s( Word16 var1 )
     459             : {
     460             :     Word16 var_out;
     461             : 
     462    15831285 :     if ( var1 == (Word16) MIN_16 )
     463             :     {
     464         393 :         var_out = MAX_16;
     465             :     }
     466             :     else
     467             :     {
     468    15830892 :         if ( var1 < 0 )
     469             :         {
     470       52685 :             var_out = -var1;
     471             :         }
     472             :         else
     473             :         {
     474    15778207 :             var_out = var1;
     475             :         }
     476             :     }
     477             : 
     478             : #ifdef WMOPS
     479             :     multiCounter[currCounter].abs_s++;
     480             : #endif
     481             :     BASOP_CHECK();
     482             : 
     483             : 
     484    15831285 :     return ( var_out );
     485             : }
     486             : 
     487             : 
     488             : /*___________________________________________________________________________
     489             :  |                                                                           |
     490             :  |   Function Name : shl                                                     |
     491             :  |                                                                           |
     492             :  |   Purpose :                                                               |
     493             :  |                                                                           |
     494             :  |   Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill|
     495             :  |   the var2 LSB of the result. If var2 is negative, arithmetically shift   |
     496             :  |   var1 right by -var2 with sign extension. Saturate the result in case of |
     497             :  |   underflows or overflows.                                                |
     498             :  |                                                                           |
     499             :  |   Complexity weight : 1                                                   |
     500             :  |                                                                           |
     501             :  |   Inputs :                                                                |
     502             :  |                                                                           |
     503             :  |    var1                                                                   |
     504             :  |             16 bit short signed integer (Word16) whose value falls in the |
     505             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     506             :  |                                                                           |
     507             :  |    var2                                                                   |
     508             :  |             16 bit short signed integer (Word16) whose value falls in the |
     509             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     510             :  |                                                                           |
     511             :  |   Outputs :                                                               |
     512             :  |                                                                           |
     513             :  |    none                                                                   |
     514             :  |                                                                           |
     515             :  |   Return Value :                                                          |
     516             :  |                                                                           |
     517             :  |    var_out                                                                |
     518             :  |             16 bit short signed integer (Word16) whose value falls in the |
     519             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     520             :  |___________________________________________________________________________|
     521             : */
     522             : #ifndef BASOP_NOGLOB
     523             : Word16 shl( Word16 var1, Word16 var2 )
     524             : #else  /* BASOP_NOGLOB */
     525      883948 : Word16 shl_o( Word16 var1, Word16 var2, Flag *Overflow )
     526             : #endif /* BASOP_NOGLOB */
     527             : {
     528             :     Word16 var_out;
     529             :     Word32 result;
     530             : 
     531      883948 :     if ( var2 < 0 )
     532             :     {
     533      720009 :         if ( var2 < -16 )
     534           4 :             var2 = -16;
     535      720009 :         var2 = -var2;
     536      720009 :         var_out = shr( var1, var2 );
     537             : 
     538             : #ifdef WMOPS
     539             :         multiCounter[currCounter].shr--;
     540             : #endif
     541             :     }
     542             :     else
     543             :     {
     544      163939 :         result = (Word32) var1 * ( (Word32) 1 << var2 );
     545             : 
     546      163939 :         if ( ( var2 > 15 && var1 != 0 ) || ( result != (Word32) ( (Word16) result ) ) )
     547             :         {
     548             : #ifndef BASOP_NOGLOB
     549             :             Overflow = 1;
     550             : #else  /* BASOP_NOGLOB */
     551        1253 :             *Overflow = 1;
     552             : #endif /* BASOP_NOGLOB */
     553        1253 :             var_out = ( var1 > 0 ) ? MAX_16 : MIN_16;
     554             :         }
     555             :         else
     556             :         {
     557      162686 :             var_out = extract_l( result );
     558             : 
     559             : #ifdef WMOPS
     560             :             multiCounter[currCounter].extract_l--;
     561             : #endif
     562             :         }
     563             :     }
     564             : 
     565             : #ifdef WMOPS
     566             :     multiCounter[currCounter].shl++;
     567             : #endif
     568             : 
     569             :     BASOP_CHECK();
     570             : 
     571             : 
     572      883948 :     return ( var_out );
     573             : }
     574             : 
     575             : #ifdef BASOP_NOGLOB
     576    81160590 : Word16 shl( Word16 var1, Word16 var2 )
     577             : {
     578             :     Word16 var_out;
     579             :     Word32 result;
     580             : 
     581    81160590 :     if ( var2 < 0 )
     582             :     {
     583      805150 :         if ( var2 < -16 )
     584           0 :             var2 = -16;
     585      805150 :         var2 = -var2;
     586      805150 :         var_out = shr( var1, var2 );
     587             : 
     588             : #ifdef WMOPS
     589             :         multiCounter[currCounter].shr--;
     590             : #endif
     591             :     }
     592             :     else
     593             :     {
     594    80355440 :         result = (Word32) var1 * ( (Word32) 1 << var2 );
     595             : 
     596    80355440 :         if ( ( var2 > 15 && var1 != 0 ) || ( result != (Word32) ( (Word16) result ) ) )
     597             :         {
     598           0 :             assert( 0 );
     599             :             var_out = ( var1 > 0 ) ? MAX_16 : MIN_16;
     600             :         }
     601             :         else
     602             :         {
     603    80355440 :             var_out = extract_l( result );
     604             : 
     605             : #ifdef WMOPS
     606             :             multiCounter[currCounter].extract_l--;
     607             : #endif
     608             :         }
     609             :     }
     610             : 
     611             : #ifdef WMOPS
     612             :     multiCounter[currCounter].shl++;
     613             : #endif
     614             :     BASOP_CHECK();
     615             : 
     616             : 
     617    81160590 :     return ( var_out );
     618             : }
     619             : #endif /* BASOP_NOGLOB */
     620             : 
     621             : /*___________________________________________________________________________
     622             :  |                                                                           |
     623             :  |   Function Name : shr                                                     |
     624             :  |                                                                           |
     625             :  |   Purpose :                                                               |
     626             :  |                                                                           |
     627             :  |   Arithmetically shift the 16 bit input var1 right var2 positions with    |
     628             :  |   sign extension. If var2 is negative, arithmetically shift var1 left by  |
     629             :  |   -var2 with sign extension. Saturate the result in case of underflows or |
     630             :  |   overflows.                                                              |
     631             :  |                                                                           |
     632             :  |   Complexity weight : 1                                                   |
     633             :  |                                                                           |
     634             :  |   Inputs :                                                                |
     635             :  |                                                                           |
     636             :  |    var1                                                                   |
     637             :  |             16 bit short signed integer (Word16) whose value falls in the |
     638             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     639             :  |                                                                           |
     640             :  |    var2                                                                   |
     641             :  |             16 bit short signed integer (Word16) whose value falls in the |
     642             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     643             :  |                                                                           |
     644             :  |   Outputs :                                                               |
     645             :  |                                                                           |
     646             :  |    none                                                                   |
     647             :  |                                                                           |
     648             :  |   Return Value :                                                          |
     649             :  |                                                                           |
     650             :  |    var_out                                                                |
     651             :  |             16 bit short signed integer (Word16) whose value falls in the |
     652             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     653             :  |___________________________________________________________________________|
     654             : */
     655   303799645 : Word16 shr( Word16 var1, Word16 var2 )
     656             : {
     657             :     Word16 var_out;
     658             : 
     659   303799645 :     if ( var2 < 0 )
     660             :     {
     661             : #ifdef BASOP_NOGLOB
     662           0 :         assert( 0 );
     663             : #endif /* BASOP_NOGLOB */
     664             :         if ( var2 < -16 )
     665             :             var2 = -16;
     666             :         var2 = -var2;
     667             :         var_out = shl( var1, var2 );
     668             : 
     669             : #ifdef WMOPS
     670             :         multiCounter[currCounter].shl--;
     671             : #endif
     672             :     }
     673             :     else
     674             :     {
     675   303799645 :         if ( var2 >= 15 )
     676             :         {
     677       11619 :             var_out = ( var1 < 0 ) ? -1 : 0;
     678             :         }
     679             :         else
     680             :         {
     681   303788026 :             if ( var1 < 0 )
     682             :             {
     683    42602860 :                 var_out = ~( ( ~var1 ) >> var2 );
     684             :             }
     685             :             else
     686             :             {
     687   261185166 :                 var_out = var1 >> var2;
     688             :             }
     689             :         }
     690             :     }
     691             : 
     692             : #ifdef WMOPS
     693             :     multiCounter[currCounter].shr++;
     694             : #endif
     695             : 
     696             :     BASOP_CHECK();
     697             : 
     698             : 
     699   303799645 :     return ( var_out );
     700             : }
     701             : 
     702             : 
     703             : /*___________________________________________________________________________
     704             :  |                                                                           |
     705             :  |   Function Name : mult                                                    |
     706             :  |                                                                           |
     707             :  |   Purpose :                                                               |
     708             :  |                                                                           |
     709             :  |    Performs the multiplication of var1 by var2 and gives a 16 bit result  |
     710             :  |    which is scaled i.e.:                                                  |
     711             :  |             mult(var1,var2) = extract_l(L_shr((var1 times var2),15)) and  |
     712             :  |             mult(-32768,-32768) = 32767.                                  |
     713             :  |                                                                           |
     714             :  |   Complexity weight : 1                                                   |
     715             :  |                                                                           |
     716             :  |   Inputs :                                                                |
     717             :  |                                                                           |
     718             :  |    var1                                                                   |
     719             :  |             16 bit short signed integer (Word16) whose value falls in the |
     720             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     721             :  |                                                                           |
     722             :  |    var2                                                                   |
     723             :  |             16 bit short signed integer (Word16) whose value falls in the |
     724             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     725             :  |                                                                           |
     726             :  |   Outputs :                                                               |
     727             :  |                                                                           |
     728             :  |    none                                                                   |
     729             :  |                                                                           |
     730             :  |   Return Value :                                                          |
     731             :  |                                                                           |
     732             :  |    var_out                                                                |
     733             :  |             16 bit short signed integer (Word16) whose value falls in the |
     734             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     735             :  |___________________________________________________________________________|
     736             : */
     737             : #ifdef BASOP_NOGLOB
     738           0 : Word16 mult_o( Word16 var1, Word16 var2, Flag *Overflow )
     739             : {
     740             :     Word16 var_out;
     741             :     Word32 L_product;
     742             : 
     743           0 :     L_product = (Word32) var1 * (Word32) var2;
     744             : 
     745           0 :     L_product = ( L_product & (Word32) 0xffff8000L ) >> 15;
     746             : 
     747           0 :     if ( L_product & (Word32) 0x00010000L )
     748           0 :         L_product = L_product | (Word32) 0xffff0000L;
     749             : 
     750           0 :     var_out = saturate_o( L_product, Overflow );
     751             : 
     752             : #ifdef WMOPS
     753             :     multiCounter[currCounter].mult++;
     754             : #endif
     755             : 
     756           0 :     return ( var_out );
     757             : }
     758             : 
     759             : #endif /* BASOP_NOGLOB */
     760   171230673 : Word16 mult( Word16 var1, Word16 var2 )
     761             : {
     762             :     Word16 var_out;
     763             :     Word32 L_product;
     764             : 
     765   171230673 :     L_product = (Word32) var1 * (Word32) var2;
     766             : 
     767   171230673 :     L_product = ( L_product & (Word32) 0xffff8000L ) >> 15;
     768             : 
     769   171230673 :     if ( L_product & (Word32) 0x00010000L )
     770    42602848 :         L_product = L_product | (Word32) 0xffff0000L;
     771             : 
     772   171230673 :     var_out = saturate( L_product );
     773             : 
     774             : #ifdef WMOPS
     775             :     multiCounter[currCounter].mult++;
     776             : #endif
     777   171230673 :     return ( var_out );
     778             : }
     779             : 
     780             : 
     781             : /*___________________________________________________________________________
     782             :  |                                                                           |
     783             :  |   Function Name : L_mult                                                  |
     784             :  |                                                                           |
     785             :  |   Purpose :                                                               |
     786             :  |                                                                           |
     787             :  |   L_mult is the 32 bit result of the multiplication of var1 times var2    |
     788             :  |   with one shift left i.e.:                                               |
     789             :  |        L_mult(var1,var2) = L_shl((var1 times var2),1) and                 |
     790             :  |        L_mult(-32768,-32768) = 2147483647.                                |
     791             :  |                                                                           |
     792             :  |   Complexity weight : 1                                                   |
     793             :  |                                                                           |
     794             :  |   Inputs :                                                                |
     795             :  |                                                                           |
     796             :  |    var1                                                                   |
     797             :  |             16 bit short signed integer (Word16) whose value falls in the |
     798             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     799             :  |                                                                           |
     800             :  |    var2                                                                   |
     801             :  |             16 bit short signed integer (Word16) whose value falls in the |
     802             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     803             :  |                                                                           |
     804             :  |   Outputs :                                                               |
     805             :  |                                                                           |
     806             :  |    none                                                                   |
     807             :  |                                                                           |
     808             :  |   Return Value :                                                          |
     809             :  |                                                                           |
     810             :  |    L_var_out                                                              |
     811             :  |             32 bit long signed integer (Word32) whose value falls in the  |
     812             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
     813             :  |___________________________________________________________________________|
     814             : */
     815             : #ifndef BASOP_NOGLOB
     816             : Word32 L_mult( Word16 var1, Word16 var2 )
     817             : #else  /* BASOP_NOGLOB */
     818       88665 : Word32 L_mult_o( Word16 var1, Word16 var2, Flag *Overflow )
     819             : #endif /* BASOP_NOGLOB */
     820             : {
     821             :     Word32 L_var_out;
     822             : 
     823       88665 :     L_var_out = (Word32) var1 * (Word32) var2;
     824             : 
     825       88665 :     if ( L_var_out != (Word32) 0x40000000L )
     826             :     {
     827       88665 :         L_var_out *= 2;
     828             :     }
     829             :     else
     830             :     {
     831             : #ifndef BASOP_NOGLOB
     832             :         Overflow = 1;
     833             : #else  /* BASOP_NOGLOB */
     834           0 :         *Overflow = 1;
     835             : #endif /* BASOP_NOGLOB */
     836           0 :         L_var_out = MAX_32;
     837             :     }
     838             : 
     839             : #ifdef WMOPS
     840             :     multiCounter[currCounter].L_mult++;
     841             : #endif
     842             : 
     843             :     BASOP_CHECK();
     844             : 
     845       88665 :     return ( L_var_out );
     846             : }
     847             : 
     848             : #ifdef BASOP_NOGLOB
     849   134570831 : Word32 L_mult( Word16 var1, Word16 var2 )
     850             : {
     851             :     Word32 L_var_out;
     852             : 
     853   134570831 :     L_var_out = (Word32) var1 * (Word32) var2;
     854             : 
     855   134570831 :     if ( L_var_out != (Word32) 0x40000000L )
     856             :     {
     857   134570831 :         L_var_out *= 2;
     858             :     }
     859             :     else
     860             :     {
     861           0 :         assert( 0 );
     862             :         L_var_out = MAX_32;
     863             :     }
     864             : 
     865             : #ifdef WMOPS
     866             :     multiCounter[currCounter].L_mult++;
     867             : #endif
     868             : 
     869             :     BASOP_CHECK();
     870             : 
     871   134570831 :     return ( L_var_out );
     872             : }
     873             : #endif /* BASOP_NOGLOB */
     874             : 
     875             : /*___________________________________________________________________________
     876             :  |                                                                           |
     877             :  |   Function Name : negate                                                  |
     878             :  |                                                                           |
     879             :  |   Purpose :                                                               |
     880             :  |                                                                           |
     881             :  |   Negate var1 with saturation, saturate in the case where input is -32768:|
     882             :  |                negate(var1) = sub(0,var1).                                |
     883             :  |                                                                           |
     884             :  |   Complexity weight : 1                                                   |
     885             :  |                                                                           |
     886             :  |   Inputs :                                                                |
     887             :  |                                                                           |
     888             :  |    var1                                                                   |
     889             :  |             16 bit short signed integer (Word16) whose value falls in the |
     890             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     891             :  |                                                                           |
     892             :  |   Outputs :                                                               |
     893             :  |                                                                           |
     894             :  |    none                                                                   |
     895             :  |                                                                           |
     896             :  |   Return Value :                                                          |
     897             :  |                                                                           |
     898             :  |    var_out                                                                |
     899             :  |             16 bit short signed integer (Word16) whose value falls in the |
     900             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     901             :  |___________________________________________________________________________|
     902             : */
     903    90089843 : Word16 negate( Word16 var1 )
     904             : {
     905             :     Word16 var_out;
     906             : 
     907    90089843 :     var_out = ( var1 == MIN_16 ) ? MAX_16 : -var1;
     908             : 
     909             : 
     910             : #ifdef WMOPS
     911             :     multiCounter[currCounter].negate++;
     912             : #endif
     913             : 
     914             :     BASOP_CHECK();
     915             : 
     916             : 
     917    90089843 :     return ( var_out );
     918             : }
     919             : 
     920             : 
     921             : /*___________________________________________________________________________
     922             :  |                                                                           |
     923             :  |   Function Name : extract_h                                               |
     924             :  |                                                                           |
     925             :  |   Purpose :                                                               |
     926             :  |                                                                           |
     927             :  |   Return the 16 MSB of L_var1.                                            |
     928             :  |                                                                           |
     929             :  |   Complexity weight : 1                                                   |
     930             :  |                                                                           |
     931             :  |   Inputs :                                                                |
     932             :  |                                                                           |
     933             :  |    L_var1                                                                 |
     934             :  |             32 bit long signed integer (Word32 ) whose value falls in the |
     935             :  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
     936             :  |                                                                           |
     937             :  |   Outputs :                                                               |
     938             :  |                                                                           |
     939             :  |    none                                                                   |
     940             :  |                                                                           |
     941             :  |   Return Value :                                                          |
     942             :  |                                                                           |
     943             :  |    var_out                                                                |
     944             :  |             16 bit short signed integer (Word16) whose value falls in the |
     945             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     946             :  |___________________________________________________________________________|
     947             : */
     948   520638993 : Word16 extract_h( Word32 L_var1 )
     949             : {
     950             :     Word16 var_out;
     951             : 
     952   520638993 :     var_out = (Word16) ( L_var1 >> 16 );
     953             : 
     954             : #ifdef WMOPS
     955             :     multiCounter[currCounter].extract_h++;
     956             : #endif
     957             : 
     958             :     BASOP_CHECK();
     959             : 
     960             : 
     961   520638993 :     return ( var_out );
     962             : }
     963             : 
     964             : 
     965             : /*___________________________________________________________________________
     966             :  |                                                                           |
     967             :  |   Function Name : extract_l                                               |
     968             :  |                                                                           |
     969             :  |   Purpose :                                                               |
     970             :  |                                                                           |
     971             :  |   Return the 16 LSB of L_var1.                                            |
     972             :  |                                                                           |
     973             :  |   Complexity weight : 1                                                   |
     974             :  |                                                                           |
     975             :  |   Inputs :                                                                |
     976             :  |                                                                           |
     977             :  |    L_var1                                                                 |
     978             :  |             32 bit long signed integer (Word32 ) whose value falls in the |
     979             :  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
     980             :  |                                                                           |
     981             :  |   Outputs :                                                               |
     982             :  |                                                                           |
     983             :  |    none                                                                   |
     984             :  |                                                                           |
     985             :  |   Return Value :                                                          |
     986             :  |                                                                           |
     987             :  |    var_out                                                                |
     988             :  |             16 bit short signed integer (Word16) whose value falls in the |
     989             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     990             :  |___________________________________________________________________________|
     991             : */
     992   945733535 : Word16 extract_l( Word32 L_var1 )
     993             : {
     994             :     Word16 var_out;
     995             : 
     996   945733535 :     var_out = (Word16) L_var1;
     997             : 
     998             : #ifdef WMOPS
     999             :     multiCounter[currCounter].extract_l++;
    1000             : #endif
    1001             : 
    1002             :     BASOP_CHECK();
    1003             : 
    1004             : 
    1005   945733535 :     return ( var_out );
    1006             : }
    1007             : 
    1008             : 
    1009             : /*___________________________________________________________________________
    1010             :  |                                                                           |
    1011             :  |   Function Name : round_fx                                                |
    1012             :  |                                                                           |
    1013             :  |   Purpose :                                                               |
    1014             :  |                                                                           |
    1015             :  |   Round the lower 16 bits of the 32 bit input number into the MS 16 bits  |
    1016             :  |   with saturation. Shift the resulting bits right by 16 and return the 16 |
    1017             :  |   bit number:                                                             |
    1018             :  |               round_fx(L_var1) = extract_h(L_add(L_var1,32768))           |
    1019             :  |                                                                           |
    1020             :  |   Complexity weight : 1                                                   |
    1021             :  |                                                                           |
    1022             :  |   Inputs :                                                                |
    1023             :  |                                                                           |
    1024             :  |    L_var1                                                                 |
    1025             :  |             32 bit long signed integer (Word32 ) whose value falls in the |
    1026             :  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
    1027             :  |                                                                           |
    1028             :  |   Outputs :                                                               |
    1029             :  |                                                                           |
    1030             :  |    none                                                                   |
    1031             :  |                                                                           |
    1032             :  |   Return Value :                                                          |
    1033             :  |                                                                           |
    1034             :  |    var_out                                                                |
    1035             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1036             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
    1037             :  |___________________________________________________________________________|
    1038             : */
    1039             : #ifdef BASOP_NOGLOB
    1040    29718270 : Word16 round_fx_o( Word32 L_var1, Flag *Overflow )
    1041             : {
    1042             :     Word16 var_out;
    1043             :     Word32 L_rounded;
    1044             : 
    1045             :     BASOP_SATURATE_WARNING_OFF
    1046    29718270 :     L_rounded = L_add_o( L_var1, (Word32) 0x00008000L, Overflow );
    1047             :     BASOP_SATURATE_WARNING_ON
    1048    29718270 :     var_out = extract_h( L_rounded );
    1049             : 
    1050             : #ifdef WMOPS
    1051             :     multiCounter[currCounter].L_add--;
    1052             :     multiCounter[currCounter].extract_h--;
    1053             :     multiCounter[currCounter].round++;
    1054             : #endif
    1055             : 
    1056             :     BASOP_CHECK();
    1057             : 
    1058    29718270 :     return ( var_out );
    1059             : }
    1060             : 
    1061             : #endif /* BASOP_NOGLOB */
    1062   133879050 : Word16 round_fx( Word32 L_var1 )
    1063             : {
    1064             :     Word16 var_out;
    1065             :     Word32 L_rounded;
    1066             : 
    1067             :     BASOP_SATURATE_WARNING_OFF
    1068   133879050 :     L_rounded = L_add( L_var1, (Word32) 0x00008000L );
    1069             :     BASOP_SATURATE_WARNING_ON
    1070   133879050 :     var_out = extract_h( L_rounded );
    1071             : 
    1072             : #ifdef WMOPS
    1073             :     multiCounter[currCounter].L_add--;
    1074             :     multiCounter[currCounter].extract_h--;
    1075             :     multiCounter[currCounter].round++;
    1076             : #endif
    1077             :     BASOP_CHECK();
    1078             : 
    1079   133879050 :     return ( var_out );
    1080             : }
    1081             : 
    1082             : 
    1083             : /*___________________________________________________________________________
    1084             :  |                                                                           |
    1085             :  |   Function Name : L_mac                                                   |
    1086             :  |                                                                           |
    1087             :  |   Purpose :                                                               |
    1088             :  |                                                                           |
    1089             :  |   Multiply var1 by var2 and shift the result left by 1. Add the 32 bit    |
    1090             :  |   result to L_var3 with saturation, return a 32 bit result:               |
    1091             :  |        L_mac(L_var3,var1,var2) = L_add(L_var3,L_mult(var1,var2)).         |
    1092             :  |                                                                           |
    1093             :  |   Complexity weight : 1                                                   |
    1094             :  |                                                                           |
    1095             :  |   Inputs :                                                                |
    1096             :  |                                                                           |
    1097             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    1098             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1099             :  |                                                                           |
    1100             :  |    var1                                                                   |
    1101             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1102             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1103             :  |                                                                           |
    1104             :  |    var2                                                                   |
    1105             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1106             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1107             :  |                                                                           |
    1108             :  |   Outputs :                                                               |
    1109             :  |                                                                           |
    1110             :  |    none                                                                   |
    1111             :  |                                                                           |
    1112             :  |   Return Value :                                                          |
    1113             :  |                                                                           |
    1114             :  |    L_var_out                                                              |
    1115             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1116             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1117             :  |___________________________________________________________________________|
    1118             : */
    1119             : #ifdef BASOP_NOGLOB
    1120       88665 : Word32 L_mac_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    1121             : {
    1122             :     Word32 L_var_out;
    1123             :     Word32 L_product;
    1124             : 
    1125       88665 :     L_product = L_mult_o( var1, var2, Overflow );
    1126       88665 :     L_var_out = L_add_o( L_var3, L_product, Overflow );
    1127             : 
    1128             : #ifdef WMOPS
    1129             :     multiCounter[currCounter].L_mult--;
    1130             :     multiCounter[currCounter].L_add--;
    1131             :     multiCounter[currCounter].L_mac++;
    1132             : #endif
    1133             : 
    1134       88665 :     return ( L_var_out );
    1135             : }
    1136             : 
    1137             : #endif /* BASOP_NOGLOB */
    1138    61569296 : Word32 L_mac( Word32 L_var3, Word16 var1, Word16 var2 )
    1139             : {
    1140             :     Word32 L_var_out;
    1141             :     Word32 L_product;
    1142             : 
    1143    61569296 :     L_product = L_mult( var1, var2 );
    1144    61569296 :     L_var_out = L_add( L_var3, L_product );
    1145             : 
    1146             : #ifdef WMOPS
    1147             :     multiCounter[currCounter].L_mult--;
    1148             :     multiCounter[currCounter].L_add--;
    1149             :     multiCounter[currCounter].L_mac++;
    1150             : #endif
    1151             :     BASOP_CHECK();
    1152             : 
    1153    61569296 :     return ( L_var_out );
    1154             : }
    1155             : 
    1156             : 
    1157             : /*___________________________________________________________________________
    1158             :  |                                                                           |
    1159             :  |   Function Name : L_msu                                                   |
    1160             :  |                                                                           |
    1161             :  |   Purpose :                                                               |
    1162             :  |                                                                           |
    1163             :  |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   |
    1164             :  |   bit result from L_var3 with saturation, return a 32 bit result:         |
    1165             :  |        L_msu(L_var3,var1,var2) = L_sub(L_var3,L_mult(var1,var2)).         |
    1166             :  |                                                                           |
    1167             :  |   Complexity weight : 1                                                   |
    1168             :  |                                                                           |
    1169             :  |   Inputs :                                                                |
    1170             :  |                                                                           |
    1171             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    1172             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1173             :  |                                                                           |
    1174             :  |    var1                                                                   |
    1175             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1176             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1177             :  |                                                                           |
    1178             :  |    var2                                                                   |
    1179             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1180             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1181             :  |                                                                           |
    1182             :  |   Outputs :                                                               |
    1183             :  |                                                                           |
    1184             :  |    none                                                                   |
    1185             :  |                                                                           |
    1186             :  |   Return Value :                                                          |
    1187             :  |                                                                           |
    1188             :  |    L_var_out                                                              |
    1189             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1190             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1191             :  |___________________________________________________________________________|
    1192             : */
    1193             : #ifdef BASOP_NOGLOB
    1194           0 : Word32 L_msu_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    1195             : {
    1196             :     Word32 L_var_out;
    1197             :     Word32 L_product;
    1198             : 
    1199           0 :     L_product = L_mult_o( var1, var2, Overflow );
    1200           0 :     L_var_out = L_sub_o( L_var3, L_product, Overflow );
    1201             : 
    1202             : #ifdef WMOPS
    1203             :     multiCounter[currCounter].L_mult--;
    1204             :     multiCounter[currCounter].L_sub--;
    1205             :     multiCounter[currCounter].L_msu++;
    1206             : #endif
    1207             : 
    1208           0 :     return ( L_var_out );
    1209             : }
    1210             : 
    1211             : #endif /* BASOP_NOGLOB */
    1212    33234546 : Word32 L_msu( Word32 L_var3, Word16 var1, Word16 var2 )
    1213             : {
    1214             :     Word32 L_var_out;
    1215             :     Word32 L_product;
    1216             : 
    1217    33234546 :     L_product = L_mult( var1, var2 );
    1218    33234546 :     L_var_out = L_sub( L_var3, L_product );
    1219             : 
    1220             : #ifdef WMOPS
    1221             :     multiCounter[currCounter].L_mult--;
    1222             :     multiCounter[currCounter].L_sub--;
    1223             :     multiCounter[currCounter].L_msu++;
    1224             : #endif
    1225             :     BASOP_CHECK();
    1226             : 
    1227    33234546 :     return ( L_var_out );
    1228             : }
    1229             : 
    1230             : 
    1231             : /*___________________________________________________________________________
    1232             :  |                                                                           |
    1233             :  |   Function Name : L_macNs                                                 |
    1234             :  |                                                                           |
    1235             :  |   Purpose :                                                               |
    1236             :  |                                                                           |
    1237             :  |   Multiply var1 by var2 and shift the result left by 1. Add the 32 bit    |
    1238             :  |   result to L_var3 without saturation, return a 32 bit result. Generate   |
    1239             :  |   carry and overflow values :                                             |
    1240             :  |        L_macNs(L_var3,var1,var2) = L_add_c(L_var3,L_mult(var1,var2)).     |
    1241             :  |                                                                           |
    1242             :  |   Complexity weight : 1                                                   |
    1243             :  |                                                                           |
    1244             :  |   Inputs :                                                                |
    1245             :  |                                                                           |
    1246             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    1247             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1248             :  |                                                                           |
    1249             :  |    var1                                                                   |
    1250             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1251             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1252             :  |                                                                           |
    1253             :  |    var2                                                                   |
    1254             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1255             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1256             :  |                                                                           |
    1257             :  |   Outputs :                                                               |
    1258             :  |                                                                           |
    1259             :  |    none                                                                   |
    1260             :  |                                                                           |
    1261             :  |   Return Value :                                                          |
    1262             :  |                                                                           |
    1263             :  |    L_var_out                                                              |
    1264             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1265             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1266             :  |                                                                           |
    1267             :  |   Caution :                                                               |
    1268             :  |                                                                           |
    1269             : #ifndef BASOP_NOGLOB
    1270             :  |    In some cases the Carry flag has to be cleared or set before using     |
    1271             : #else
    1272             :  |    In some cases the BASOP_Carry flag has to be cleared or set before using     |
    1273             : #endif
    1274             :  |    operators which take into account its value.                           |
    1275             :  |___________________________________________________________________________|
    1276             : */
    1277             : #ifndef BASOP_NOGLOB
    1278             : Word32 L_macNs( Word32 L_var3, Word16 var1, Word16 var2 )
    1279             : #else  /* BASOP_NOGLOB */
    1280           0 : Word32 DEPR_L_macNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry )
    1281             : #endif /* BASOP_NOGLOB */
    1282             : {
    1283             :     Word32 L_var_out;
    1284             : 
    1285           0 :     L_var_out = L_mult( var1, var2 );
    1286             : #ifndef BASOP_NOGLOB
    1287             :     L_var_out = L_add_c( L_var3, L_var_out );
    1288             : #else  /* BASOP_NOGLOB */
    1289           0 :     L_var_out = DEPR_L_add_c( L_var3, L_var_out, Carry );
    1290             : #endif /* BASOP_NOGLOB */
    1291             : 
    1292             : #ifdef WMOPS
    1293             :     multiCounter[currCounter].L_mult--;
    1294             :     multiCounter[currCounter].L_add_c--;
    1295             :     multiCounter[currCounter].L_macNs++;
    1296             : #endif
    1297             : 
    1298             :     /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
    1299             : 
    1300             : 
    1301           0 :     return ( L_var_out );
    1302             : }
    1303             : 
    1304             : 
    1305             : /*___________________________________________________________________________
    1306             :  |                                                                           |
    1307             :  |   Function Name : L_msuNs                                                 |
    1308             :  |                                                                           |
    1309             :  |   Purpose :                                                               |
    1310             :  |                                                                           |
    1311             :  |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   |
    1312             :  |   bit result from L_var3 without saturation, return a 32 bit result. Ge-  |
    1313             :  |   nerate carry and overflow values :                                      |
    1314             :  |        L_msuNs(L_var3,var1,var2) = L_sub_c(L_var3,L_mult(var1,var2)).     |
    1315             :  |                                                                           |
    1316             :  |   Complexity weight : 1                                                   |
    1317             :  |                                                                           |
    1318             :  |   Inputs :                                                                |
    1319             :  |                                                                           |
    1320             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    1321             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1322             :  |                                                                           |
    1323             :  |    var1                                                                   |
    1324             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1325             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1326             :  |                                                                           |
    1327             :  |    var2                                                                   |
    1328             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1329             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1330             :  |                                                                           |
    1331             :  |   Outputs :                                                               |
    1332             :  |                                                                           |
    1333             :  |    none                                                                   |
    1334             :  |                                                                           |
    1335             :  |   Return Value :                                                          |
    1336             :  |                                                                           |
    1337             :  |    L_var_out                                                              |
    1338             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1339             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1340             :  |                                                                           |
    1341             :  |   Caution :                                                               |
    1342             :  |                                                                           |
    1343             : #ifndef BASOP_NOGLOB
    1344             :  |    In some cases the Carry flag has to be cleared or set before using     |
    1345             : #else
    1346             :  |    In some cases the BASOP_Carry flag has to be cleared or set before using     |
    1347             : #endif
    1348             :  |    operators which take into account its value.                           |
    1349             :  |___________________________________________________________________________|
    1350             : */
    1351             : #ifndef BASOP_NOGLOB
    1352             : Word32 L_msuNs( Word32 L_var3, Word16 var1, Word16 var2 )
    1353             : #else  /* BASOP_NOGLOB */
    1354           0 : Word32 DEPR_L_msuNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry )
    1355             : #endif /* BASOP_NOGLOB */
    1356             : {
    1357             :     Word32 L_var_out;
    1358             : 
    1359           0 :     L_var_out = L_mult( var1, var2 );
    1360             : #ifndef BASOP_NOGLOB
    1361             :     L_var_out = L_sub_c( L_var3, L_var_out );
    1362             : #else  /* BASOP_NOGLOB */
    1363           0 :     L_var_out = DEPR_L_sub_c( L_var3, L_var_out, Carry );
    1364             : #endif /* BASOP_NOGLOB */
    1365             : 
    1366             : #ifdef WMOPS
    1367             :     multiCounter[currCounter].L_mult--;
    1368             :     multiCounter[currCounter].L_sub_c--;
    1369             :     multiCounter[currCounter].L_msuNs++;
    1370             : #endif
    1371             : 
    1372             :     /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
    1373             : 
    1374           0 :     return ( L_var_out );
    1375             : }
    1376             : 
    1377             : 
    1378             : /*___________________________________________________________________________
    1379             :  |                                                                           |
    1380             :  |   Function Name : L_add                                                   |
    1381             :  |                                                                           |
    1382             :  |   Purpose :                                                               |
    1383             :  |                                                                           |
    1384             :  |   32 bits addition of the two 32 bits variables (L_var1+L_var2) with      |
    1385             :  |   overflow control and saturation; the result is set at +2147483647 when  |
    1386             :  |   overflow occurs or at -2147483648 when underflow occurs.                |
    1387             :  |                                                                           |
    1388             :  |   Complexity weight : 1                                                   |
    1389             :  |                                                                           |
    1390             :  |   Inputs :                                                                |
    1391             :  |                                                                           |
    1392             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    1393             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1394             :  |                                                                           |
    1395             :  |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |
    1396             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1397             :  |                                                                           |
    1398             :  |   Outputs :                                                               |
    1399             :  |                                                                           |
    1400             :  |    none                                                                   |
    1401             :  |                                                                           |
    1402             :  |   Return Value :                                                          |
    1403             :  |                                                                           |
    1404             :  |    L_var_out                                                              |
    1405             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1406             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1407             :  |___________________________________________________________________________|
    1408             : */
    1409             : #ifndef BASOP_NOGLOB
    1410             : Word32 L_add( Word32 L_var1, Word32 L_var2 )
    1411             : #else  /* BASOP_NOGLOB */
    1412    29875350 : Word32 L_add_o( Word32 L_var1, Word32 L_var2, Flag *Overflow )
    1413             : #endif /* BASOP_NOGLOB */
    1414             : {
    1415             :     Word32 L_var_out;
    1416             : 
    1417    29875350 :     L_var_out = L_var1 + L_var2;
    1418             : 
    1419    29875350 :     if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) == 0 )
    1420             :     {
    1421    29875350 :         if ( ( L_var_out ^ L_var1 ) & MIN_32 )
    1422             :         {
    1423         668 :             L_var_out = ( L_var1 < 0 ) ? MIN_32 : MAX_32;
    1424             : #ifndef BASOP_NOGLOB
    1425             :             Overflow = 1;
    1426             : #else  /* BASOP_NOGLOB */
    1427         668 :             *Overflow = 1;
    1428             : #endif /* BASOP_NOGLOB */
    1429             :         }
    1430             :     }
    1431             : 
    1432             : #ifdef WMOPS
    1433             :     multiCounter[currCounter].L_add++;
    1434             : #endif
    1435             : 
    1436             :     BASOP_CHECK();
    1437             : 
    1438             : 
    1439    29875350 :     return ( L_var_out );
    1440             : }
    1441             : 
    1442             : #ifdef BASOP_NOGLOB
    1443   576604265 : Word32 L_add( Word32 L_var1, Word32 L_var2 )
    1444             : {
    1445             :     Word32 L_var_out;
    1446             : 
    1447   576604265 :     L_var_out = L_var1 + L_var2;
    1448             : 
    1449   576604265 :     if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) == 0 )
    1450             :     {
    1451   469368675 :         if ( ( L_var_out ^ L_var1 ) & MIN_32 )
    1452             :         {
    1453           0 :             L_var_out = ( L_var1 < 0 ) ? MIN_32 : MAX_32;
    1454           0 :             assert( 0 );
    1455             :         }
    1456             :     }
    1457             : 
    1458             : #ifdef WMOPS
    1459             :     multiCounter[currCounter].L_add++;
    1460             : #endif
    1461   576604265 :     return ( L_var_out );
    1462             : }
    1463             : #endif /* BASOP_NOGLOB */
    1464             : 
    1465             : /*___________________________________________________________________________
    1466             :  |                                                                           |
    1467             :  |   Function Name : L_sub                                                   |
    1468             :  |                                                                           |
    1469             :  |   Purpose :                                                               |
    1470             :  |                                                                           |
    1471             :  |   32 bits subtraction of the two 32 bits variables (L_var1-L_var2) with   |
    1472             :  |   overflow control and saturation; the result is set at +2147483647 when  |
    1473             :  |   overflow occurs or at -2147483648 when underflow occurs.                |
    1474             :  |                                                                           |
    1475             :  |   Complexity weight : 1                                                   |
    1476             :  |                                                                           |
    1477             :  |   Inputs :                                                                |
    1478             :  |                                                                           |
    1479             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    1480             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1481             :  |                                                                           |
    1482             :  |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |
    1483             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1484             :  |                                                                           |
    1485             :  |   Outputs :                                                               |
    1486             :  |                                                                           |
    1487             :  |    none                                                                   |
    1488             :  |                                                                           |
    1489             :  |   Return Value :                                                          |
    1490             :  |                                                                           |
    1491             :  |    L_var_out                                                              |
    1492             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1493             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1494             :  |___________________________________________________________________________|
    1495             : */
    1496             : #ifndef BASOP_NOGLOB
    1497             : Word32 L_sub( Word32 L_var1, Word32 L_var2 )
    1498             : #else  /* BASOP_NOGLOB */
    1499           0 : Word32 L_sub_o( Word32 L_var1, Word32 L_var2, Flag *Overflow )
    1500             : #endif /* BASOP_NOGLOB */
    1501             : {
    1502             :     Word32 L_var_out;
    1503             : 
    1504           0 :     L_var_out = L_var1 - L_var2;
    1505             : 
    1506           0 :     if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) != 0 )
    1507             :     {
    1508           0 :         if ( ( L_var_out ^ L_var1 ) & MIN_32 )
    1509             :         {
    1510           0 :             L_var_out = ( L_var1 < 0L ) ? MIN_32 : MAX_32;
    1511             : #ifndef BASOP_NOGLOB
    1512             :             Overflow = 1;
    1513             : #else  /* BASOP_NOGLOB */
    1514           0 :             *Overflow = 1;
    1515             : #endif /* BASOP_NOGLOB */
    1516             :         }
    1517             :     }
    1518             : 
    1519             : #ifdef WMOPS
    1520             :     multiCounter[currCounter].L_sub++;
    1521             : #endif
    1522             : 
    1523             :     BASOP_CHECK();
    1524             : 
    1525           0 :     return ( L_var_out );
    1526             : }
    1527             : 
    1528             : #ifdef BASOP_NOGLOB
    1529   150500414 : Word32 L_sub( Word32 L_var1, Word32 L_var2 )
    1530             : {
    1531             :     Word32 L_var_out;
    1532             : 
    1533   150500414 :     L_var_out = L_var1 - L_var2;
    1534             : 
    1535   150500414 :     if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) != 0 )
    1536             :     {
    1537    34151017 :         if ( ( L_var_out ^ L_var1 ) & MIN_32 )
    1538             :         {
    1539           0 :             L_var_out = ( L_var1 < 0L ) ? MIN_32 : MAX_32;
    1540           0 :             assert( 0 );
    1541             :         }
    1542             :     }
    1543             : 
    1544             : #ifdef WMOPS
    1545             :     multiCounter[currCounter].L_sub++;
    1546             : #endif
    1547             :     BASOP_CHECK();
    1548             : 
    1549   150500414 :     return ( L_var_out );
    1550             : }
    1551             : #endif /* BASOP_NOGLOB */
    1552             : 
    1553             : /*___________________________________________________________________________
    1554             :  |                                                                           |
    1555             :  |   Function Name : L_add_c                                                 |
    1556             :  |                                                                           |
    1557             :  |   Purpose :                                                               |
    1558             :  |                                                                           |
    1559             :  |   Performs 32 bits addition of the two 32 bits variables (L_var1+L_var2+C)|
    1560             : #ifndef BASOP_NOGLOB
    1561             :  |   with carry. No saturation. Generate carry and Overflow values. The car- |
    1562             : #else
    1563             :  |   with carry. No saturation. Generate carry and BASOP_Overflow values. The car- |
    1564             : #endif
    1565             :  |   ry and overflow values are binary variables which can be tested and as- |
    1566             :  |   signed values.                                                          |
    1567             :  |                                                                           |
    1568             :  |   Complexity weight : 2                                                   |
    1569             :  |                                                                           |
    1570             :  |   Inputs :                                                                |
    1571             :  |                                                                           |
    1572             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    1573             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1574             :  |                                                                           |
    1575             :  |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |
    1576             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1577             :  |                                                                           |
    1578             :  |   Outputs :                                                               |
    1579             :  |                                                                           |
    1580             :  |    none                                                                   |
    1581             :  |                                                                           |
    1582             :  |   Return Value :                                                          |
    1583             :  |                                                                           |
    1584             :  |    L_var_out                                                              |
    1585             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1586             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1587             :  |                                                                           |
    1588             :  |   Caution :                                                               |
    1589             :  |                                                                           |
    1590             : #ifndef BASOP_NOGLOB
    1591             :  |    In some cases the Carry flag has to be cleared or set before using     |
    1592             : #else
    1593             :  |    In some cases the BASOP_Carry flag has to be cleared or set before using     |
    1594             : #endif
    1595             :  |    operators which take into account its value.                           |
    1596             :  |___________________________________________________________________________|
    1597             : */
    1598             : #ifndef BASOP_NOGLOB
    1599             : Word32 L_add_c( Word32 L_var1, Word32 L_var2 )
    1600             : #else  /* BASOP_NOGLOB */
    1601           0 : Word32 DEPR_L_add_c( Word32 L_var1, Word32 L_var2, Flag *Carry )
    1602             : #endif /* BASOP_NOGLOB */
    1603             : {
    1604             :     Word32 L_var_out;
    1605             :     Word32 L_test;
    1606           0 :     Flag carry_int = 0;
    1607             : 
    1608             : #ifndef BASOP_NOGLOB
    1609             :     L_var_out = L_var1 + L_var2 + Carry;
    1610             : #else  /* BASOP_NOGLOB */
    1611           0 :     L_var_out = L_var1 + L_var2 + *Carry;
    1612             : #endif /* BASOP_NOGLOB */
    1613             : 
    1614           0 :     L_test = L_var1 + L_var2;
    1615             : 
    1616           0 :     if ( ( L_var1 > 0 ) && ( L_var2 > 0 ) && ( L_test < 0 ) )
    1617             :     {
    1618             : #ifndef BASOP_NOGLOB
    1619             :         Overflow = 1;
    1620             : #endif /* ! BASOP_NOGLOB */
    1621           0 :         carry_int = 0;
    1622             :     }
    1623             :     else
    1624             :     {
    1625           0 :         if ( ( L_var1 < 0 ) && ( L_var2 < 0 ) )
    1626             :         {
    1627           0 :             if ( L_test >= 0 )
    1628             :             {
    1629             : #ifndef BASOP_NOGLOB
    1630             :                 Overflow = 1;
    1631             : #endif /* ! BASOP_NOGLOB */
    1632           0 :                 carry_int = 1;
    1633             :             }
    1634             :             else
    1635             :             {
    1636             : #ifndef BASOP_NOGLOB
    1637             :                 Overflow = 0;
    1638             : #endif /* ! BASOP_NOGLOB */
    1639           0 :                 carry_int = 1;
    1640             :             }
    1641             :         }
    1642             :         else
    1643             :         {
    1644           0 :             if ( ( ( L_var1 ^ L_var2 ) < 0 ) && ( L_test >= 0 ) )
    1645             :             {
    1646             : #ifndef BASOP_NOGLOB
    1647             :                 Overflow = 0;
    1648             : #endif /* ! BASOP_NOGLOB */
    1649           0 :                 carry_int = 1;
    1650             :             }
    1651             :             else
    1652             :             {
    1653             : #ifndef BASOP_NOGLOB
    1654             :                 Overflow = 0;
    1655             : #endif /* ! BASOP_NOGLOB */
    1656           0 :                 carry_int = 0;
    1657             :             }
    1658             :         }
    1659             :     }
    1660             : 
    1661             : #ifndef BASOP_NOGLOB
    1662             :     if ( Carry )
    1663             : #else  /* BASOP_NOGLOB */
    1664           0 :     if ( *Carry )
    1665             : #endif /* BASOP_NOGLOB */
    1666             :     {
    1667           0 :         if ( L_test == MAX_32 )
    1668             :         {
    1669             : #ifndef BASOP_NOGLOB
    1670             :             Overflow = 1;
    1671             :             Carry = carry_int;
    1672             : #else  /* BASOP_NOGLOB */
    1673           0 :             *Carry = carry_int;
    1674             : #endif /* BASOP_NOGLOB */
    1675             :         }
    1676             :         else
    1677             :         {
    1678           0 :             if ( L_test == (Word32) 0xFFFFFFFFL )
    1679             :             {
    1680             : #ifndef BASOP_NOGLOB
    1681             :                 Carry = 1;
    1682             : #else  /* BASOP_NOGLOB */
    1683           0 :                 *Carry = 1;
    1684             : #endif /* BASOP_NOGLOB */
    1685             :             }
    1686             :             else
    1687             :             {
    1688             : #ifndef BASOP_NOGLOB
    1689             :                 Carry = carry_int;
    1690             : #else  /* BASOP_NOGLOB */
    1691           0 :                 *Carry = carry_int;
    1692             : #endif /* BASOP_NOGLOB */
    1693             :             }
    1694             :         }
    1695             :     }
    1696             :     else
    1697             :     {
    1698             : #ifndef BASOP_NOGLOB
    1699             :         Carry = carry_int;
    1700             : #else  /* BASOP_NOGLOB */
    1701           0 :         *Carry = carry_int;
    1702             : #endif /* BASOP_NOGLOB */
    1703             :     }
    1704             : 
    1705             : #ifdef WMOPS
    1706             :     multiCounter[currCounter].L_add_c++;
    1707             : #endif
    1708             : 
    1709             :     /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
    1710             : 
    1711             : 
    1712           0 :     return ( L_var_out );
    1713             : }
    1714             : 
    1715             : 
    1716             : /*___________________________________________________________________________
    1717             :  |                                                                           |
    1718             :  |   Function Name : L_sub_c                                                 |
    1719             :  |                                                                           |
    1720             :  |   Purpose :                                                               |
    1721             :  |                                                                           |
    1722             :  |   Performs 32 bits subtraction of the two 32 bits variables with carry    |
    1723             : #ifndef BASOP_NOGLOB
    1724             :  |   (borrow) : L_var1-L_var2-C. No saturation. Generate carry and Overflow  |
    1725             : #else
    1726             :  |   (borrow) : L_var1-L_var2-C. No saturation. Generate carry and BASOP_Overflow  |
    1727             : #endif
    1728             :  |   values. The carry and overflow values are binary variables which can    |
    1729             :  |   be tested and assigned values.                                          |
    1730             :  |                                                                           |
    1731             :  |   Complexity weight : 2                                                   |
    1732             :  |                                                                           |
    1733             :  |   Inputs :                                                                |
    1734             :  |                                                                           |
    1735             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    1736             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1737             :  |                                                                           |
    1738             :  |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |
    1739             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1740             :  |                                                                           |
    1741             :  |   Outputs :                                                               |
    1742             :  |                                                                           |
    1743             :  |    none                                                                   |
    1744             :  |                                                                           |
    1745             :  |   Return Value :                                                          |
    1746             :  |                                                                           |
    1747             :  |    L_var_out                                                              |
    1748             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1749             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1750             :  |                                                                           |
    1751             :  |   Caution :                                                               |
    1752             :  |                                                                           |
    1753             : #ifndef BASOP_NOGLOB
    1754             :  |    In some cases the Carry flag has to be cleared or set before using     |
    1755             : #else
    1756             :  |    In some cases the BASOP_Carry flag has to be cleared or set before using     |
    1757             : #endif
    1758             :  |    operators which take into account its value.                           |
    1759             :  |___________________________________________________________________________|
    1760             : */
    1761             : #ifndef BASOP_NOGLOB
    1762             : Word32 L_sub_c( Word32 L_var1, Word32 L_var2 )
    1763             : #else  /* BASOP_NOGLOB */
    1764           0 : Word32 DEPR_L_sub_c( Word32 L_var1, Word32 L_var2, Flag *Carry )
    1765             : #endif /* BASOP_NOGLOB */
    1766             : {
    1767             :     Word32 L_var_out;
    1768             :     Word32 L_test;
    1769           0 :     Flag carry_int = 0;
    1770             : 
    1771             : #ifndef BASOP_NOGLOB
    1772             :     if ( Carry )
    1773             : #else  /* BASOP_NOGLOB */
    1774           0 :     if ( *Carry )
    1775             : #endif /* BASOP_NOGLOB */
    1776             :     {
    1777             : #ifndef BASOP_NOGLOB
    1778             :         Carry = 0;
    1779             : #else  /* BASOP_NOGLOB */
    1780           0 :         *Carry = 0;
    1781             : #endif /* BASOP_NOGLOB */
    1782           0 :         if ( L_var2 != MIN_32 )
    1783             :         {
    1784             : #ifndef BASOP_NOGLOB
    1785             :             L_var_out = L_add_c( L_var1, -L_var2 );
    1786             : #else  /* BASOP_NOGLOB */
    1787           0 :             L_var_out = DEPR_L_add_c( L_var1, -L_var2, Carry );
    1788             : #endif /* BASOP_NOGLOB */
    1789             : #ifdef WMOPS
    1790             :             multiCounter[currCounter].L_add_c--;
    1791             : #endif
    1792             :         }
    1793             :         else
    1794             :         {
    1795           0 :             L_var_out = L_var1 - L_var2;
    1796           0 :             if ( L_var1 > 0L )
    1797             :             {
    1798             : #ifndef BASOP_NOGLOB
    1799             :                 Overflow = 1;
    1800             :                 Carry = 0;
    1801             : #else  /* BASOP_NOGLOB */
    1802           0 :                 *Carry = 0;
    1803             : #endif /* BASOP_NOGLOB */
    1804             :             }
    1805             :         }
    1806             :     }
    1807             :     else
    1808             :     {
    1809           0 :         L_var_out = L_var1 - L_var2 - (Word32) 0X00000001L;
    1810           0 :         L_test = L_var1 - L_var2;
    1811             : 
    1812           0 :         if ( ( L_test < 0 ) && ( L_var1 > 0 ) && ( L_var2 < 0 ) )
    1813             :         {
    1814             : #ifndef BASOP_NOGLOB
    1815             :             Overflow = 1;
    1816             : #endif /* ! BASOP_NOGLOB */
    1817           0 :             carry_int = 0;
    1818             :         }
    1819           0 :         else if ( ( L_test > 0 ) && ( L_var1 < 0 ) && ( L_var2 > 0 ) )
    1820             :         {
    1821             : #ifndef BASOP_NOGLOB
    1822             :             Overflow = 1;
    1823             : #endif /* ! BASOP_NOGLOB */
    1824           0 :             carry_int = 1;
    1825             :         }
    1826           0 :         else if ( ( L_test > 0 ) && ( ( L_var1 ^ L_var2 ) > 0 ) )
    1827             :         {
    1828             : #ifndef BASOP_NOGLOB
    1829             :             Overflow = 0;
    1830             : #endif /* ! BASOP_NOGLOB */
    1831           0 :             carry_int = 1;
    1832             :         }
    1833           0 :         if ( L_test == MIN_32 )
    1834             :         {
    1835             : #ifndef BASOP_NOGLOB
    1836             :             Overflow = 1;
    1837             :             Carry = carry_int;
    1838             : #else  /* BASOP_NOGLOB */
    1839           0 :             *Carry = carry_int;
    1840             : #endif /* BASOP_NOGLOB */
    1841             :         }
    1842             :         else
    1843             :         {
    1844             : #ifndef BASOP_NOGLOB
    1845             :             Carry = carry_int;
    1846             : #else  /* BASOP_NOGLOB */
    1847           0 :             *Carry = carry_int;
    1848             : #endif /* BASOP_NOGLOB */
    1849             :         }
    1850             :     }
    1851             : 
    1852             : #ifdef WMOPS
    1853             :     multiCounter[currCounter].L_sub_c++;
    1854             : #endif
    1855             : 
    1856             :     /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
    1857             : 
    1858             : 
    1859           0 :     return ( L_var_out );
    1860             : }
    1861             : 
    1862             : 
    1863             : /*___________________________________________________________________________
    1864             :  |                                                                           |
    1865             :  |   Function Name : L_negate                                                |
    1866             :  |                                                                           |
    1867             :  |   Purpose :                                                               |
    1868             :  |                                                                           |
    1869             :  |   Negate the 32 bit variable L_var1 with saturation; saturate in the case |
    1870             :  |   where input is -2147483648 (0x8000 0000).                               |
    1871             :  |                                                                           |
    1872             :  |   Complexity weight : 1                                                   |
    1873             :  |                                                                           |
    1874             :  |   Inputs :                                                                |
    1875             :  |                                                                           |
    1876             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    1877             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1878             :  |                                                                           |
    1879             :  |   Outputs :                                                               |
    1880             :  |                                                                           |
    1881             :  |    none                                                                   |
    1882             :  |                                                                           |
    1883             :  |   Return Value :                                                          |
    1884             :  |                                                                           |
    1885             :  |    L_var_out                                                              |
    1886             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1887             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1888             :  |___________________________________________________________________________|
    1889             : */
    1890    45074607 : Word32 L_negate( Word32 L_var1 )
    1891             : {
    1892             :     Word32 L_var_out;
    1893             : 
    1894    45074607 :     L_var_out = ( L_var1 == MIN_32 ) ? MAX_32 : -L_var1;
    1895             : 
    1896             : 
    1897             : #ifdef WMOPS
    1898             :     multiCounter[currCounter].L_negate++;
    1899             : #endif
    1900             : 
    1901             :     BASOP_CHECK();
    1902             : 
    1903    45074607 :     return ( L_var_out );
    1904             : }
    1905             : 
    1906             : 
    1907             : /*___________________________________________________________________________
    1908             :  |                                                                           |
    1909             :  |   Function Name : mult_r                                                  |
    1910             :  |                                                                           |
    1911             :  |   Purpose :                                                               |
    1912             :  |                                                                           |
    1913             :  |   Same as mult with rounding, i.e.:                                       |
    1914             :  |     mult_r(var1,var2) = extract_l(L_shr(((var1 * var2) + 16384),15)) and  |
    1915             :  |     mult_r(-32768,-32768) = 32767.                                        |
    1916             :  |                                                                           |
    1917             :  |   Complexity weight : 1                                                   |
    1918             :  |                                                                           |
    1919             :  |   Inputs :                                                                |
    1920             :  |                                                                           |
    1921             :  |    var1                                                                   |
    1922             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1923             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1924             :  |                                                                           |
    1925             :  |    var2                                                                   |
    1926             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1927             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1928             :  |                                                                           |
    1929             :  |   Outputs :                                                               |
    1930             :  |                                                                           |
    1931             :  |    none                                                                   |
    1932             :  |                                                                           |
    1933             :  |   Return Value :                                                          |
    1934             :  |                                                                           |
    1935             :  |    var_out                                                                |
    1936             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1937             :  |             range : 0x8000 <= var_out <= 0x7fff.                          |
    1938             :  |___________________________________________________________________________|
    1939             : */
    1940             : #ifdef BASOP_NOGLOB
    1941           0 : Word16 mult_ro( Word16 var1, Word16 var2, Flag *Overflow )
    1942             : {
    1943             :     Word16 var_out;
    1944             :     Word32 L_product_arr;
    1945             : 
    1946           0 :     L_product_arr = (Word32) var1 * (Word32) var2; /* product */
    1947           0 :     L_product_arr += (Word32) 0x00004000L;         /* round */
    1948           0 :     L_product_arr &= (Word32) 0xffff8000L;
    1949           0 :     L_product_arr >>= 15; /* shift */
    1950             : 
    1951           0 :     if ( L_product_arr & (Word32) 0x00010000L ) /* sign extend when necessary */
    1952             :     {
    1953           0 :         L_product_arr |= (Word32) 0xffff0000L;
    1954             :     }
    1955           0 :     var_out = saturate_o( L_product_arr, Overflow );
    1956             : 
    1957             : #ifdef WMOPS
    1958             :     multiCounter[currCounter].mult_r++;
    1959             : #endif
    1960             : 
    1961           0 :     return ( var_out );
    1962             : }
    1963             : 
    1964             : #endif /* BASOP_NOGLOB */
    1965    67857141 : Word16 mult_r( Word16 var1, Word16 var2 )
    1966             : {
    1967             :     Word16 var_out;
    1968             :     Word32 L_product_arr;
    1969             : 
    1970    67857141 :     L_product_arr = (Word32) var1 * (Word32) var2; /* product */
    1971    67857141 :     L_product_arr += (Word32) 0x00004000L;         /* round */
    1972    67857141 :     L_product_arr &= (Word32) 0xffff8000L;
    1973    67857141 :     L_product_arr >>= 15; /* shift */
    1974             : 
    1975    67857141 :     if ( L_product_arr & (Word32) 0x00010000L ) /* sign extend when necessary */
    1976             :     {
    1977     1900321 :         L_product_arr |= (Word32) 0xffff0000L;
    1978             :     }
    1979    67857141 :     var_out = saturate( L_product_arr );
    1980             : 
    1981             : #ifdef WMOPS
    1982             :     multiCounter[currCounter].mult_r++;
    1983             : #endif
    1984    67857141 :     return ( var_out );
    1985             : }
    1986             : 
    1987             : 
    1988             : /*___________________________________________________________________________
    1989             :  |                                                                           |
    1990             :  |   Function Name : L_shl                                                   |
    1991             :  |                                                                           |
    1992             :  |   Purpose :                                                               |
    1993             :  |                                                                           |
    1994             :  |   Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero  |
    1995             :  |   fill the var2 LSB of the result. If var2 is negative, arithmetically    |
    1996             :  |   shift L_var1 right by -var2 with sign extension. Saturate the result in |
    1997             :  |   case of underflows or overflows.                                        |
    1998             :  |                                                                           |
    1999             :  |   Complexity weight : 1                                                   |
    2000             :  |                                                                           |
    2001             :  |   Inputs :                                                                |
    2002             :  |                                                                           |
    2003             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    2004             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    2005             :  |                                                                           |
    2006             :  |    var2                                                                   |
    2007             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2008             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2009             :  |                                                                           |
    2010             :  |   Outputs :                                                               |
    2011             :  |                                                                           |
    2012             :  |    none                                                                   |
    2013             :  |                                                                           |
    2014             :  |   Return Value :                                                          |
    2015             :  |                                                                           |
    2016             :  |    L_var_out                                                              |
    2017             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2018             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    2019             :  |___________________________________________________________________________|
    2020             : */
    2021             : #ifndef BASOP_NOGLOB
    2022             : Word32 L_shl( Word32 L_var1, Word16 var2 )
    2023             : #else  /* BASOP_NOGLOB */
    2024      108915 : Word32 L_shl_o( Word32 L_var1, Word16 var2, Flag *Overflow )
    2025             : #endif /* BASOP_NOGLOB */
    2026             : {
    2027             : 
    2028      108915 :     Word32 L_var_out = 0L;
    2029             : 
    2030      108915 :     if ( var2 <= 0 )
    2031             :     {
    2032       20247 :         if ( var2 < -32 )
    2033           0 :             var2 = -32;
    2034       20247 :         var2 = -var2;
    2035       20247 :         L_var_out = L_shr( L_var1, var2 );
    2036             : #ifdef WMOPS
    2037             :         multiCounter[currCounter].L_shr--;
    2038             : #endif
    2039             :     }
    2040             :     else
    2041             :     {
    2042      786425 :         for ( ; var2 > 0; var2-- )
    2043             :         {
    2044      733956 :             if ( L_var1 > (Word32) 0X3fffffffL )
    2045             :             {
    2046             : #ifndef BASOP_NOGLOB
    2047             :                 Overflow = 1;
    2048             : #else  /* BASOP_NOGLOB */
    2049       36199 :                 *Overflow = 1;
    2050             : #endif /* BASOP_NOGLOB */
    2051       36199 :                 L_var_out = MAX_32;
    2052       36199 :                 break;
    2053             :             }
    2054             :             else
    2055             :             {
    2056      697757 :                 if ( L_var1 < (Word32) 0xc0000000L )
    2057             :                 {
    2058             : #ifndef BASOP_NOGLOB
    2059             :                     Overflow = 1;
    2060             : #else  /* BASOP_NOGLOB */
    2061           0 :                     *Overflow = 1;
    2062             : #endif /* BASOP_NOGLOB */
    2063           0 :                     L_var_out = MIN_32;
    2064           0 :                     break;
    2065             :                 }
    2066             :             }
    2067      697757 :             L_var1 *= 2;
    2068      697757 :             L_var_out = L_var1;
    2069             :         }
    2070             :     }
    2071             : 
    2072             : #ifdef WMOPS
    2073             :     multiCounter[currCounter].L_shl++;
    2074             : #endif
    2075             : 
    2076             :     BASOP_CHECK();
    2077             : 
    2078             : 
    2079      108915 :     return ( L_var_out );
    2080             : }
    2081             : 
    2082             : #ifdef BASOP_NOGLOB
    2083   253631020 : Word32 L_shl( Word32 L_var1, Word16 var2 )
    2084             : {
    2085             : 
    2086   253631020 :     Word32 L_var_out = 0L;
    2087             : 
    2088   253631020 :     if ( var2 <= 0 )
    2089             :     {
    2090    61384777 :         if ( var2 < -32 )
    2091           0 :             var2 = -32;
    2092    61384777 :         var2 = -var2;
    2093    61384777 :         L_var_out = L_shr( L_var1, var2 );
    2094             : #ifdef WMOPS
    2095             :         multiCounter[currCounter].L_shr--;
    2096             : #endif
    2097             :     }
    2098             :     else
    2099             :     {
    2100  2116979966 :         for ( ; var2 > 0; var2-- )
    2101             :         {
    2102  1924733723 :             if ( L_var1 > (Word32) 0X3fffffffL )
    2103             :             {
    2104           0 :                 assert( 0 );
    2105             :                 L_var_out = MAX_32;
    2106             :                 break;
    2107             :             }
    2108             :             else
    2109             :             {
    2110  1924733723 :                 if ( L_var1 < (Word32) 0xc0000000L )
    2111             :                 {
    2112           0 :                     assert( 0 );
    2113             :                     L_var_out = MIN_32;
    2114             :                     break;
    2115             :                 }
    2116             :             }
    2117  1924733723 :             L_var1 *= 2;
    2118  1924733723 :             L_var_out = L_var1;
    2119             :         }
    2120             :     }
    2121             : 
    2122             : #ifdef WMOPS
    2123             :     multiCounter[currCounter].L_shl++;
    2124             : #endif
    2125             :     BASOP_CHECK();
    2126             : 
    2127             : 
    2128   253631020 :     return ( L_var_out );
    2129             : }
    2130             : #endif /* BASOP_NOGLOB */
    2131             : 
    2132             : /*___________________________________________________________________________
    2133             :  |                                                                           |
    2134             :  |   Function Name : L_shr                                                   |
    2135             :  |                                                                           |
    2136             :  |   Purpose :                                                               |
    2137             :  |                                                                           |
    2138             :  |   Arithmetically shift the 32 bit input L_var1 right var2 positions with  |
    2139             :  |   sign extension. If var2 is negative, arithmetically shift L_var1 left   |
    2140             :  |   by -var2 and zero fill the -var2 LSB of the result. Saturate the result |
    2141             :  |   in case of underflows or overflows.                                     |
    2142             :  |                                                                           |
    2143             :  |   Complexity weight : 1                                                   |
    2144             :  |                                                                           |
    2145             :  |   Inputs :                                                                |
    2146             :  |                                                                           |
    2147             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    2148             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    2149             :  |                                                                           |
    2150             :  |    var2                                                                   |
    2151             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2152             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2153             :  |                                                                           |
    2154             :  |   Outputs :                                                               |
    2155             :  |                                                                           |
    2156             :  |    none                                                                   |
    2157             :  |                                                                           |
    2158             :  |   Return Value :                                                          |
    2159             :  |                                                                           |
    2160             :  |    L_var_out                                                              |
    2161             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2162             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    2163             :  |___________________________________________________________________________|
    2164             : */
    2165             : #ifdef BASOP_NOGLOB
    2166           0 : Word32 L_shr_o( Word32 L_var1, Word16 var2, Flag *Overflow )
    2167             : {
    2168             :     Word32 L_var_out;
    2169             : 
    2170           0 :     if ( var2 < 0 )
    2171             :     {
    2172           0 :         if ( var2 < -32 )
    2173           0 :             var2 = -32;
    2174           0 :         var2 = -var2;
    2175           0 :         L_var_out = L_shl_o( L_var1, var2, Overflow );
    2176             : #ifdef WMOPS
    2177             :         multiCounter[currCounter].L_shl--;
    2178             : #endif
    2179             :     }
    2180             :     else
    2181             :     {
    2182           0 :         if ( var2 >= 31 )
    2183             :         {
    2184           0 :             L_var_out = ( L_var1 < 0L ) ? -1 : 0;
    2185             :         }
    2186             :         else
    2187             :         {
    2188           0 :             if ( L_var1 < 0 )
    2189             :             {
    2190           0 :                 L_var_out = ~( ( ~L_var1 ) >> var2 );
    2191             :             }
    2192             :             else
    2193             :             {
    2194           0 :                 L_var_out = L_var1 >> var2;
    2195             :             }
    2196             :         }
    2197             :     }
    2198             : 
    2199             : #ifdef WMOPS
    2200             :     multiCounter[currCounter].L_shr++;
    2201             : #endif
    2202             : 
    2203             :     BASOP_CHECK();
    2204             : 
    2205             : 
    2206           0 :     return ( L_var_out );
    2207             : }
    2208             : 
    2209             : #endif /* BASOP_NOGLOB */
    2210   163388044 : Word32 L_shr( Word32 L_var1, Word16 var2 )
    2211             : {
    2212             :     Word32 L_var_out;
    2213             : 
    2214   163388044 :     if ( var2 < 0 )
    2215             :     {
    2216      500622 :         if ( var2 < -32 )
    2217           0 :             var2 = -32;
    2218      500622 :         var2 = -var2;
    2219      500622 :         L_var_out = L_shl( L_var1, var2 );
    2220             : #ifdef WMOPS
    2221             :         multiCounter[currCounter].L_shl--;
    2222             : #endif
    2223             :     }
    2224             :     else
    2225             :     {
    2226   162887422 :         if ( var2 >= 31 )
    2227             :         {
    2228           4 :             L_var_out = ( L_var1 < 0L ) ? -1 : 0;
    2229             :         }
    2230             :         else
    2231             :         {
    2232   162887418 :             if ( L_var1 < 0 )
    2233             :             {
    2234    62607390 :                 L_var_out = ~( ( ~L_var1 ) >> var2 );
    2235             :             }
    2236             :             else
    2237             :             {
    2238   100280028 :                 L_var_out = L_var1 >> var2;
    2239             :             }
    2240             :         }
    2241             :     }
    2242             : 
    2243             : #ifdef WMOPS
    2244             :     multiCounter[currCounter].L_shr++;
    2245             : #endif
    2246             :     BASOP_CHECK();
    2247             : 
    2248             : 
    2249   163388044 :     return ( L_var_out );
    2250             : }
    2251             : 
    2252             : 
    2253             : /*___________________________________________________________________________
    2254             :  |                                                                           |
    2255             :  |   Function Name : shr_r                                                   |
    2256             :  |                                                                           |
    2257             :  |   Purpose :                                                               |
    2258             :  |                                                                           |
    2259             :  |   Same as shr(var1,var2) but with rounding. Saturate the result in case of|
    2260             :  |   underflows or overflows :                                               |
    2261             :  |    - If var2 is greater than zero :                                       |
    2262             :  |          if (sub(shl(shr(var1,var2),1),shr(var1,sub(var2,1))))            |
    2263             :  |          is equal to zero                                                 |
    2264             :  |                     then                                                  |
    2265             :  |                     shr_r(var1,var2) = shr(var1,var2)                     |
    2266             :  |                     else                                                  |
    2267             :  |                     shr_r(var1,var2) = add(shr(var1,var2),1)              |
    2268             :  |    - If var2 is less than or equal to zero :                              |
    2269             :  |                     shr_r(var1,var2) = shr(var1,var2).                    |
    2270             :  |                                                                           |
    2271             :  |   Complexity weight : 3                                                   |
    2272             :  |                                                                           |
    2273             :  |   Inputs :                                                                |
    2274             :  |                                                                           |
    2275             :  |    var1                                                                   |
    2276             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2277             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2278             :  |                                                                           |
    2279             :  |    var2                                                                   |
    2280             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2281             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2282             :  |                                                                           |
    2283             :  |   Outputs :                                                               |
    2284             :  |                                                                           |
    2285             :  |    none                                                                   |
    2286             :  |                                                                           |
    2287             :  |   Return Value :                                                          |
    2288             :  |                                                                           |
    2289             :  |    var_out                                                                |
    2290             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2291             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
    2292             :  |___________________________________________________________________________|
    2293             : */
    2294           0 : Word16 shr_r( Word16 var1, Word16 var2 )
    2295             : {
    2296             :     Word16 var_out;
    2297             : 
    2298           0 :     if ( var2 > 15 )
    2299             :     {
    2300           0 :         var_out = 0;
    2301             :     }
    2302             :     else
    2303             :     {
    2304           0 :         var_out = shr( var1, var2 );
    2305             : 
    2306             : #ifdef WMOPS
    2307             :         multiCounter[currCounter].shr--;
    2308             : #endif
    2309           0 :         if ( var2 > 0 )
    2310             :         {
    2311           0 :             if ( ( var1 & ( (Word16) 1 << ( var2 - 1 ) ) ) != 0 )
    2312             :             {
    2313           0 :                 var_out++;
    2314             :             }
    2315             :         }
    2316             :     }
    2317             : 
    2318             : #ifdef WMOPS
    2319             :     multiCounter[currCounter].shr_r++;
    2320             : #endif
    2321             : 
    2322             :     BASOP_CHECK();
    2323             : 
    2324           0 :     return ( var_out );
    2325             : }
    2326             : 
    2327             : 
    2328             : /*___________________________________________________________________________
    2329             :  |                                                                           |
    2330             :  |   Function Name : mac_r                                                   |
    2331             :  |                                                                           |
    2332             :  |   Purpose :                                                               |
    2333             :  |                                                                           |
    2334             :  |   Multiply var1 by var2 and shift the result left by 1. Add the 32 bit    |
    2335             :  |   result to L_var3 with saturation. Round the LS 16 bits of the result    |
    2336             :  |   into the MS 16 bits with saturation and shift the result right by 16.   |
    2337             :  |   Return a 16 bit result.                                                 |
    2338             :  |            mac_r(L_var3,var1,var2) = round_fx(L_mac(L_var3,var1,var2))    |
    2339             :  |                                                                           |
    2340             :  |   Complexity weight : 1                                                   |
    2341             :  |                                                                           |
    2342             :  |   Inputs :                                                                |
    2343             :  |                                                                           |
    2344             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    2345             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    2346             :  |                                                                           |
    2347             :  |    var1                                                                   |
    2348             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2349             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2350             :  |                                                                           |
    2351             :  |    var2                                                                   |
    2352             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2353             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2354             :  |                                                                           |
    2355             :  |   Outputs :                                                               |
    2356             :  |                                                                           |
    2357             :  |    none                                                                   |
    2358             :  |                                                                           |
    2359             :  |   Return Value :                                                          |
    2360             :  |                                                                           |
    2361             :  |    var_out                                                                |
    2362             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2363             :  |             range : 0x0000 8000 <= L_var_out <= 0x0000 7fff.              |
    2364             :  |___________________________________________________________________________|
    2365             : */
    2366             : #ifdef BASOP_NOGLOB
    2367       68415 : Word16 mac_ro( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    2368             : {
    2369             :     Word16 var_out;
    2370             : 
    2371       68415 :     L_var3 = L_mac_o( L_var3, var1, var2, Overflow );
    2372       68415 :     L_var3 = L_add_o( L_var3, (Word32) 0x00008000L, Overflow );
    2373       68415 :     var_out = extract_h( L_var3 );
    2374             : 
    2375             : #ifdef WMOPS
    2376             :     multiCounter[currCounter].L_mac--;
    2377             :     multiCounter[currCounter].L_add--;
    2378             :     multiCounter[currCounter].extract_h--;
    2379             :     multiCounter[currCounter].mac_r++;
    2380             : #endif
    2381             : 
    2382             :     BASOP_CHECK();
    2383             : 
    2384             : 
    2385       68415 :     return ( var_out );
    2386             : }
    2387             : 
    2388             : #endif /* BASOP_NOGLOB */
    2389    59632918 : Word16 mac_r( Word32 L_var3, Word16 var1, Word16 var2 )
    2390             : {
    2391             :     Word16 var_out;
    2392             : 
    2393    59632918 :     L_var3 = L_mac( L_var3, var1, var2 );
    2394    59632918 :     L_var3 = L_add( L_var3, (Word32) 0x00008000L );
    2395    59632918 :     var_out = extract_h( L_var3 );
    2396             : 
    2397             : #ifdef WMOPS
    2398             :     multiCounter[currCounter].L_mac--;
    2399             :     multiCounter[currCounter].L_add--;
    2400             :     multiCounter[currCounter].extract_h--;
    2401             :     multiCounter[currCounter].mac_r++;
    2402             : #endif
    2403             : 
    2404             :     BASOP_CHECK();
    2405             : 
    2406             : 
    2407    59632918 :     return ( var_out );
    2408             : }
    2409             : 
    2410             : 
    2411             : /*___________________________________________________________________________
    2412             :  |                                                                           |
    2413             :  |   Function Name : msu_r                                                   |
    2414             :  |                                                                           |
    2415             :  |   Purpose :                                                               |
    2416             :  |                                                                           |
    2417             :  |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   |
    2418             :  |   bit result from L_var3 with saturation. Round the LS 16 bits of the res-|
    2419             :  |   ult into the MS 16 bits with saturation and shift the result right by   |
    2420             :  |   16. Return a 16 bit result.                                             |
    2421             :  |            msu_r(L_var3,var1,var2) = round_fx(L_msu(L_var3,var1,var2))    |
    2422             :  |                                                                           |
    2423             :  |   Complexity weight : 1                                                   |
    2424             :  |                                                                           |
    2425             :  |   Inputs :                                                                |
    2426             :  |                                                                           |
    2427             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    2428             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    2429             :  |                                                                           |
    2430             :  |    var1                                                                   |
    2431             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2432             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2433             :  |                                                                           |
    2434             :  |    var2                                                                   |
    2435             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2436             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2437             :  |                                                                           |
    2438             :  |   Outputs :                                                               |
    2439             :  |                                                                           |
    2440             :  |    none                                                                   |
    2441             :  |                                                                           |
    2442             :  |   Return Value :                                                          |
    2443             :  |                                                                           |
    2444             :  |    var_out                                                                |
    2445             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2446             :  |             range : 0x0000 8000 <= L_var_out <= 0x0000 7fff.              |
    2447             :  |___________________________________________________________________________|
    2448             : */
    2449             : #ifdef BASOP_NOGLOB
    2450           0 : Word16 msu_ro( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    2451             : {
    2452             :     Word16 var_out;
    2453             : 
    2454           0 :     L_var3 = L_msu_o( L_var3, var1, var2, Overflow );
    2455           0 :     L_var3 = L_add_o( L_var3, (Word32) 0x00008000L, Overflow );
    2456           0 :     var_out = extract_h( L_var3 );
    2457             : 
    2458             : #ifdef WMOPS
    2459             :     multiCounter[currCounter].L_msu--;
    2460             :     multiCounter[currCounter].L_add--;
    2461             :     multiCounter[currCounter].extract_h--;
    2462             :     multiCounter[currCounter].msu_r++;
    2463             : #endif
    2464             :     BASOP_CHECK();
    2465             : 
    2466           0 :     return ( var_out );
    2467             : }
    2468             : 
    2469             : #endif /* BASOP_NOGLOB */
    2470    33071147 : Word16 msu_r( Word32 L_var3, Word16 var1, Word16 var2 )
    2471             : {
    2472             :     Word16 var_out;
    2473             : 
    2474    33071147 :     L_var3 = L_msu( L_var3, var1, var2 );
    2475    33071147 :     L_var3 = L_add( L_var3, (Word32) 0x00008000L );
    2476    33071147 :     var_out = extract_h( L_var3 );
    2477             : 
    2478             : #ifdef WMOPS
    2479             :     multiCounter[currCounter].L_msu--;
    2480             :     multiCounter[currCounter].L_add--;
    2481             :     multiCounter[currCounter].extract_h--;
    2482             :     multiCounter[currCounter].msu_r++;
    2483             : #endif
    2484             :     BASOP_CHECK();
    2485             : 
    2486    33071147 :     return ( var_out );
    2487             : }
    2488             : 
    2489             : 
    2490             : /*___________________________________________________________________________
    2491             :  |                                                                           |
    2492             :  |   Function Name : L_deposit_h                                             |
    2493             :  |                                                                           |
    2494             :  |   Purpose :                                                               |
    2495             :  |                                                                           |
    2496             :  |   Deposit the 16 bit var1 into the 16 MS bits of the 32 bit output. The   |
    2497             :  |   16 LS bits of the output are zeroed.                                    |
    2498             :  |                                                                           |
    2499             :  |   Complexity weight : 1                                                   |
    2500             :  |                                                                           |
    2501             :  |   Inputs :                                                                |
    2502             :  |                                                                           |
    2503             :  |    var1                                                                   |
    2504             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2505             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2506             :  |                                                                           |
    2507             :  |   Outputs :                                                               |
    2508             :  |                                                                           |
    2509             :  |    none                                                                   |
    2510             :  |                                                                           |
    2511             :  |   Return Value :                                                          |
    2512             :  |                                                                           |
    2513             :  |    L_var_out                                                              |
    2514             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2515             :  |             range : 0x8000 0000 <= var_out <= 0x7fff 0000.                |
    2516             :  |___________________________________________________________________________|
    2517             : */
    2518    57950631 : Word32 L_deposit_h( Word16 var1 )
    2519             : {
    2520             :     Word32 L_var_out;
    2521             : 
    2522    57950631 :     L_var_out = (Word32) var1 << 16;
    2523             : 
    2524             : #ifdef WMOPS
    2525             :     multiCounter[currCounter].L_deposit_h++;
    2526             : #endif
    2527             : 
    2528             :     BASOP_CHECK();
    2529             : 
    2530             : 
    2531    57950631 :     return ( L_var_out );
    2532             : }
    2533             : 
    2534             : 
    2535             : /*___________________________________________________________________________
    2536             :  |                                                                           |
    2537             :  |   Function Name : L_deposit_l                                             |
    2538             :  |                                                                           |
    2539             :  |   Purpose :                                                               |
    2540             :  |                                                                           |
    2541             :  |   Deposit the 16 bit var1 into the 16 LS bits of the 32 bit output. The   |
    2542             :  |   16 MS bits of the output are sign extended.                             |
    2543             :  |                                                                           |
    2544             :  |   Complexity weight : 1                                                   |
    2545             :  |                                                                           |
    2546             :  |   Inputs :                                                                |
    2547             :  |                                                                           |
    2548             :  |    var1                                                                   |
    2549             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2550             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2551             :  |                                                                           |
    2552             :  |   Outputs :                                                               |
    2553             :  |                                                                           |
    2554             :  |    none                                                                   |
    2555             :  |                                                                           |
    2556             :  |   Return Value :                                                          |
    2557             :  |                                                                           |
    2558             :  |    L_var_out                                                              |
    2559             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2560             :  |             range : 0xFFFF 8000 <= var_out <= 0x0000 7fff.                |
    2561             :  |___________________________________________________________________________|
    2562             : */
    2563     8874811 : Word32 L_deposit_l( Word16 var1 )
    2564             : {
    2565             :     Word32 L_var_out;
    2566             : 
    2567     8874811 :     L_var_out = (Word32) var1;
    2568             : 
    2569             : #ifdef WMOPS
    2570             :     multiCounter[currCounter].L_deposit_l++;
    2571             : #endif
    2572             : 
    2573             :     BASOP_CHECK();
    2574             : 
    2575             : 
    2576     8874811 :     return ( L_var_out );
    2577             : }
    2578             : 
    2579             : 
    2580             : /*___________________________________________________________________________
    2581             :  |                                                                           |
    2582             :  |   Function Name : L_shr_r                                                 |
    2583             :  |                                                                           |
    2584             :  |   Purpose :                                                               |
    2585             :  |                                                                           |
    2586             :  |   Same as L_shr(L_var1,var2) but with rounding. Saturate the result in    |
    2587             :  |   case of underflows or overflows :                                       |
    2588             :  |    - If var2 is greater than zero :                                       |
    2589             :  |          if (L_sub(L_shl(L_shr(L_var1,var2),1),L_shr(L_var1,sub(var2,1))))|
    2590             :  |          is equal to zero                                                 |
    2591             :  |                     then                                                  |
    2592             :  |                     L_shr_r(L_var1,var2) = L_shr(L_var1,var2)             |
    2593             :  |                     else                                                  |
    2594             :  |                     L_shr_r(L_var1,var2) = L_add(L_shr(L_var1,var2),1)    |
    2595             :  |    - If var2 is less than or equal to zero :                              |
    2596             :  |                     L_shr_r(L_var1,var2) = L_shr(L_var1,var2).            |
    2597             :  |                                                                           |
    2598             :  |   Complexity weight : 3                                                   |
    2599             :  |                                                                           |
    2600             :  |   Inputs :                                                                |
    2601             :  |                                                                           |
    2602             :  |    L_var1                                                                 |
    2603             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2604             :  |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
    2605             :  |                                                                           |
    2606             :  |    var2                                                                   |
    2607             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2608             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2609             :  |                                                                           |
    2610             :  |   Outputs :                                                               |
    2611             :  |                                                                           |
    2612             :  |    none                                                                   |
    2613             :  |                                                                           |
    2614             :  |   Return Value :                                                          |
    2615             :  |                                                                           |
    2616             :  |    L_var_out                                                              |
    2617             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2618             :  |             range : 0x8000 0000 <= var_out <= 0x7fff ffff.                |
    2619             :  |___________________________________________________________________________|
    2620             : */
    2621      761549 : Word32 L_shr_r( Word32 L_var1, Word16 var2 )
    2622             : {
    2623             :     Word32 L_var_out;
    2624             : 
    2625      761549 :     if ( var2 > 31 )
    2626             :     {
    2627           0 :         L_var_out = 0;
    2628             :     }
    2629             :     else
    2630             :     {
    2631      761549 :         L_var_out = L_shr( L_var1, var2 );
    2632             : 
    2633             : #ifdef WMOPS
    2634             :         multiCounter[currCounter].L_shr--;
    2635             : #endif
    2636      761549 :         if ( var2 > 0 )
    2637             :         {
    2638      758437 :             if ( ( L_var1 & ( (Word32) 1 << ( var2 - 1 ) ) ) != 0 )
    2639             :             {
    2640      375981 :                 L_var_out++;
    2641             :             }
    2642             :         }
    2643             :     }
    2644             : 
    2645             : #ifdef WMOPS
    2646             :     multiCounter[currCounter].L_shr_r++;
    2647             : #endif
    2648             : 
    2649             :     BASOP_CHECK();
    2650             : 
    2651             : 
    2652      761549 :     return ( L_var_out );
    2653             : }
    2654             : 
    2655             : 
    2656             : /*___________________________________________________________________________
    2657             :  |                                                                           |
    2658             :  |   Function Name : L_abs                                                   |
    2659             :  |                                                                           |
    2660             :  |   Purpose :                                                               |
    2661             :  |                                                                           |
    2662             :  |    Absolute value of L_var1; Saturate in case where the input is          |
    2663             :  |                                                               -214783648  |
    2664             :  |                                                                           |
    2665             :  |   Complexity weight : 1                                                   |
    2666             :  |                                                                           |
    2667             :  |   Inputs :                                                                |
    2668             :  |                                                                           |
    2669             :  |    L_var1                                                                 |
    2670             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2671             :  |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
    2672             :  |                                                                           |
    2673             :  |   Outputs :                                                               |
    2674             :  |                                                                           |
    2675             :  |    none                                                                   |
    2676             :  |                                                                           |
    2677             :  |   Return Value :                                                          |
    2678             :  |                                                                           |
    2679             :  |    L_var_out                                                              |
    2680             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2681             :  |             range : 0x0000 0000 <= var_out <= 0x7fff ffff.                |
    2682             :  |___________________________________________________________________________|
    2683             : */
    2684    22013641 : Word32 L_abs( Word32 L_var1 )
    2685             : {
    2686             :     Word32 L_var_out;
    2687             : 
    2688    22013641 :     if ( L_var1 == MIN_32 )
    2689             :     {
    2690           0 :         L_var_out = MAX_32;
    2691             :     }
    2692             :     else
    2693             :     {
    2694    22013641 :         if ( L_var1 < 0 )
    2695             :         {
    2696     7781468 :             L_var_out = -L_var1;
    2697             :         }
    2698             :         else
    2699             :         {
    2700    14232173 :             L_var_out = L_var1;
    2701             :         }
    2702             :     }
    2703             : 
    2704             : #ifdef WMOPS
    2705             :     multiCounter[currCounter].L_abs++;
    2706             : #endif
    2707             : 
    2708             :     BASOP_CHECK();
    2709             : 
    2710             : 
    2711    22013641 :     return ( L_var_out );
    2712             : }
    2713             : 
    2714             : 
    2715             : /*___________________________________________________________________________
    2716             :  |                                                                           |
    2717             :  |   Function Name : L_sat                                                   |
    2718             :  |                                                                           |
    2719             :  |   Purpose :                                                               |
    2720             :  |                                                                           |
    2721             :  |    32 bit L_var1 is set to 2147483647 if an overflow occured or to        |
    2722             :  |    -2147483648 if an underflow occured on the most recent L_add_c,        |
    2723             :  |    L_sub_c, L_macNs or L_msuNs operations. The carry and overflow values  |
    2724             :  |    are binary values which can be tested and assigned values.             |
    2725             :  |                                                                           |
    2726             :  |   Complexity weight : 4                                                   |
    2727             :  |                                                                           |
    2728             :  |   Inputs :                                                                |
    2729             :  |                                                                           |
    2730             :  |    L_var1                                                                 |
    2731             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2732             :  |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
    2733             :  |                                                                           |
    2734             :  |   Outputs :                                                               |
    2735             :  |                                                                           |
    2736             :  |    none                                                                   |
    2737             :  |                                                                           |
    2738             :  |   Return Value :                                                          |
    2739             :  |                                                                           |
    2740             :  |    L_var_out                                                              |
    2741             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2742             :  |             range : 0x8000 0000 <= var_out <= 0x7fff ffff.                |
    2743             :  |___________________________________________________________________________|
    2744             : */
    2745             : #ifndef BASOP_NOGLOB
    2746             : Word32 L_sat( Word32 L_var1 )
    2747             : #else  /* BASOP_NOGLOB */
    2748           0 : Word32 DEPR_L_sat_co( Word32 L_var1, Flag Overflow, Flag Carry )
    2749             : #endif /* BASOP_NOGLOB */
    2750             : {
    2751             :     Word32 L_var_out;
    2752             : 
    2753           0 :     L_var_out = L_var1;
    2754             : 
    2755           0 :     if ( Overflow )
    2756             :     {
    2757             : 
    2758           0 :         if ( Carry )
    2759             :         {
    2760           0 :             L_var_out = MIN_32;
    2761             :         }
    2762             :         else
    2763             :         {
    2764           0 :             L_var_out = MAX_32;
    2765             :         }
    2766             : #ifndef BASOP_NOGLOB
    2767             : 
    2768             :         Carry = 0;
    2769             :         Overflow = 0;
    2770             : #endif /* ! BASOP_NOGLOB */
    2771             :     }
    2772             : 
    2773             : #ifdef WMOPS
    2774             :     multiCounter[currCounter].L_sat++;
    2775             : #endif
    2776             : 
    2777             :     BASOP_CHECK();
    2778             : 
    2779             : 
    2780           0 :     return ( L_var_out );
    2781             : }
    2782             : 
    2783             : 
    2784             : /*___________________________________________________________________________
    2785             :  |                                                                           |
    2786             :  |   Function Name : norm_s                                                  |
    2787             :  |                                                                           |
    2788             :  |   Purpose :                                                               |
    2789             :  |                                                                           |
    2790             :  |   Produces the number of left shift needed to normalize the 16 bit varia- |
    2791             :  |   ble var1 for positive values on the interval with minimum of 16384 and  |
    2792             :  |   maximum of 32767, and for negative values on the interval with minimum  |
    2793             :  |   of -32768 and maximum of -16384; in order to normalize the result, the  |
    2794             :  |   following operation must be done :                                      |
    2795             :  |                    norm_var1 = shl(var1,norm_s(var1)).                    |
    2796             :  |                                                                           |
    2797             :  |   Complexity weight : 1                                                   |
    2798             :  |                                                                           |
    2799             :  |   Inputs :                                                                |
    2800             :  |                                                                           |
    2801             :  |    var1                                                                   |
    2802             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2803             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2804             :  |                                                                           |
    2805             :  |   Outputs :                                                               |
    2806             :  |                                                                           |
    2807             :  |    none                                                                   |
    2808             :  |                                                                           |
    2809             :  |   Return Value :                                                          |
    2810             :  |                                                                           |
    2811             :  |    var_out                                                                |
    2812             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2813             :  |             range : 0x0000 0000 <= var_out <= 0x0000 000f.                |
    2814             :  |___________________________________________________________________________|
    2815             : */
    2816    41752063 : Word16 norm_s( Word16 var1 )
    2817             : {
    2818             :     Word16 var_out;
    2819             : 
    2820    41752063 :     if ( var1 == 0 )
    2821             :     {
    2822           0 :         var_out = 0;
    2823             :     }
    2824             :     else
    2825             :     {
    2826    41752063 :         if ( var1 == (Word16) 0xffff )
    2827             :         {
    2828           0 :             var_out = 15;
    2829             :         }
    2830             :         else
    2831             :         {
    2832    41752063 :             if ( var1 < 0 )
    2833             :             {
    2834           0 :                 var1 = ~var1;
    2835             :             }
    2836    91075685 :             for ( var_out = 0; var1 < 0x4000; var_out++ )
    2837             :             {
    2838    49323622 :                 var1 <<= 1;
    2839             :             }
    2840             :         }
    2841             :     }
    2842             : 
    2843             : #ifdef WMOPS
    2844             :     multiCounter[currCounter].norm_s++;
    2845             : #endif
    2846             : 
    2847             :     BASOP_CHECK();
    2848             : 
    2849             : 
    2850    41752063 :     return ( var_out );
    2851             : }
    2852             : 
    2853             : 
    2854             : /*___________________________________________________________________________
    2855             :  |                                                                           |
    2856             :  |   Function Name : div_s                                                   |
    2857             :  |                                                                           |
    2858             :  |   Purpose :                                                               |
    2859             :  |                                                                           |
    2860             :  |   Produces a result which is the fractional integer division of var1  by  |
    2861             :  |   var2; var1 and var2 must be positive and var2 must be greater or equal  |
    2862             :  |   to var1; the result is positive (leading bit equal to 0) and truncated  |
    2863             :  |   to 16 bits.                                                             |
    2864             :  |   If var1 = var2 then div(var1,var2) = 32767.                             |
    2865             :  |                                                                           |
    2866             :  |   Complexity weight : 18                                                  |
    2867             :  |                                                                           |
    2868             :  |   Inputs :                                                                |
    2869             :  |                                                                           |
    2870             :  |    var1                                                                   |
    2871             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2872             :  |             range : 0x0000 0000 <= var1 <= var2 and var2 != 0.            |
    2873             :  |                                                                           |
    2874             :  |    var2                                                                   |
    2875             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2876             :  |             range : var1 <= var2 <= 0x0000 7fff and var2 != 0.            |
    2877             :  |                                                                           |
    2878             :  |   Outputs :                                                               |
    2879             :  |                                                                           |
    2880             :  |    none                                                                   |
    2881             :  |                                                                           |
    2882             :  |   Return Value :                                                          |
    2883             :  |                                                                           |
    2884             :  |    var_out                                                                |
    2885             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2886             :  |             range : 0x0000 0000 <= var_out <= 0x0000 7fff.                |
    2887             :  |             It's a Q15 value (point between b15 and b14).                 |
    2888             :  |___________________________________________________________________________|
    2889             : */
    2890     3052998 : Word16 div_s( Word16 var1, Word16 var2 )
    2891             : {
    2892     3052998 :     Word16 var_out = 0;
    2893             :     Word16 iteration;
    2894             :     Word32 L_num;
    2895             :     Word32 L_denom;
    2896             : 
    2897     3052998 :     if ( ( var1 > var2 ) || ( var1 < 0 ) || ( var2 < 0 ) )
    2898             :     {
    2899             :         /* printf ("Division Error var1=%d  var2=%d in ", var1, var2); printStack(); */
    2900             :         char text[60];
    2901           0 :         sprintf( text, "Division Error var1=%d  var2=%d in ", var1, var2 );
    2902           0 :         abort(); /* exit (0); */
    2903             :     }
    2904     3052998 :     if ( var2 == 0 )
    2905             :     {
    2906             :         /* printf ("Division by 0, Fatal error in "); printStack(); */
    2907           0 :         abort(); /* exit (0); */
    2908             :     }
    2909     3052998 :     if ( var1 == 0 )
    2910             :     {
    2911           0 :         var_out = 0;
    2912             :     }
    2913             :     else
    2914             :     {
    2915     3052998 :         if ( var1 == var2 )
    2916             :         {
    2917       39610 :             var_out = MAX_16;
    2918             :         }
    2919             :         else
    2920             :         {
    2921     3013388 :             L_num = L_deposit_l( var1 );
    2922     3013388 :             L_denom = L_deposit_l( var2 );
    2923             : 
    2924             : #ifdef WMOPS
    2925             :             multiCounter[currCounter].L_deposit_l--;
    2926             :             multiCounter[currCounter].L_deposit_l--;
    2927             : #endif
    2928             : 
    2929    48214208 :             for ( iteration = 0; iteration < 15; iteration++ )
    2930             :             {
    2931    45200820 :                 var_out <<= 1;
    2932    45200820 :                 L_num <<= 1;
    2933             : 
    2934    45200820 :                 if ( L_num >= L_denom )
    2935             :                 {
    2936    13708230 :                     L_num = L_sub( L_num, L_denom );
    2937    13708230 :                     var_out = add( var_out, 1 );
    2938             : #ifdef WMOPS
    2939             :                     multiCounter[currCounter].L_sub--;
    2940             :                     multiCounter[currCounter].add--;
    2941             : #endif
    2942             :                 }
    2943             :             }
    2944             :         }
    2945             :     }
    2946             : 
    2947             : #ifdef WMOPS
    2948             :     multiCounter[currCounter].div_s++;
    2949             : #endif
    2950             : 
    2951             :     BASOP_CHECK();
    2952             : 
    2953             : 
    2954     3052998 :     return ( var_out );
    2955             : }
    2956             : 
    2957             : 
    2958             : /*___________________________________________________________________________
    2959             :  |                                                                           |
    2960             :  |   Function Name : norm_l                                                  |
    2961             :  |                                                                           |
    2962             :  |   Purpose :                                                               |
    2963             :  |                                                                           |
    2964             :  |   Produces the number of left shifts needed to normalize the 32 bit varia-|
    2965             :  |   ble L_var1 for positive values on the interval with minimum of          |
    2966             :  |   1073741824 and maximum of 2147483647, and for negative values on the in-|
    2967             :  |   terval with minimum of -2147483648 and maximum of -1073741824; in order |
    2968             :  |   to normalize the result, the following operation must be done :         |
    2969             :  |                   norm_L_var1 = L_shl(L_var1,norm_l(L_var1)).             |
    2970             :  |                                                                           |
    2971             :  |   Complexity weight : 1                                                   |
    2972             :  |                                                                           |
    2973             :  |   Inputs :                                                                |
    2974             :  |                                                                           |
    2975             :  |    L_var1                                                                 |
    2976             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2977             :  |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
    2978             :  |                                                                           |
    2979             :  |   Outputs :                                                               |
    2980             :  |                                                                           |
    2981             :  |    none                                                                   |
    2982             :  |                                                                           |
    2983             :  |   Return Value :                                                          |
    2984             :  |                                                                           |
    2985             :  |    var_out                                                                |
    2986             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2987             :  |             range : 0x0000 0000 <= var_out <= 0x0000 001f.                |
    2988             :  |___________________________________________________________________________|
    2989             : */
    2990  1245243065 : Word16 norm_l( Word32 L_var1 )
    2991             : {
    2992             :     Word16 var_out;
    2993             : 
    2994  1245243065 :     if ( L_var1 == 0 )
    2995             :     {
    2996       24809 :         var_out = 0;
    2997             :     }
    2998             :     else
    2999             :     {
    3000  1245218256 :         if ( L_var1 == (Word32) 0xffffffffL )
    3001             :         {
    3002          93 :             var_out = 31;
    3003             :         }
    3004             :         else
    3005             :         {
    3006  1245218163 :             if ( L_var1 < 0 )
    3007             :             {
    3008       84462 :                 L_var1 = ~L_var1;
    3009             :             }
    3010 33388116797 :             for ( var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++ )
    3011             :             {
    3012 32142898634 :                 L_var1 <<= 1;
    3013             :             }
    3014             :         }
    3015             :     }
    3016             : 
    3017             : #ifdef WMOPS
    3018             :     multiCounter[currCounter].norm_l++;
    3019             : #endif
    3020             : 
    3021             :     BASOP_CHECK();
    3022             : 
    3023             : 
    3024  1245243065 :     return ( var_out );
    3025             : }
    3026             : 
    3027             : /*
    3028             :  ******************************************************************************
    3029             :  * Additional operators extracted from the G.723.1 Library
    3030             :  * Adapted for WMOPS calculations
    3031             :  ******************************************************************************
    3032             :  */
    3033             : 
    3034             : /*___________________________________________________________________________
    3035             :  |                                                                           |
    3036             :  |   Function Name : L_mls                                                   |
    3037             :  |                                                                           |
    3038             :  |   Purpose :                                                               |
    3039             :  |                                                                           |
    3040             :  |   Multiplies a 16 bit word v by a 32 bit word Lv and returns a 32 bit     |
    3041             :  |   word (multiplying 16 by 32 bit words gives 48 bit word; the function    |
    3042             :  |   extracts the 32 MSB and shift the result to the left by 1).             |
    3043             :  |                                                                           |
    3044             :  |   A 32 bit word can be written as                                         |
    3045             :  |    Lv = a  +  b * 2^16                                                    |
    3046             :  |   where a= unsigned 16 LSBs and b= signed 16 MSBs.                        |
    3047             :  |   The function returns v * Lv  /  2^15  which is equivalent to            |
    3048             :  |        a*v / 2^15 + b*v*2                                                 |
    3049             :  |                                                                           |
    3050             :  |   Complexity weight : 5                                                   |
    3051             :  |                                                                           |
    3052             :  |   Inputs :                                                                |
    3053             :  |                                                                           |
    3054             :  |   Lv                                                                      |
    3055             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    3056             :  |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
    3057             :  |   v                                                                       |
    3058             :  |             16 bit short signed integer (Word16) whose value falls in the |
    3059             :  |             range : 0x8000 <= var1 <= 0x7fff.                             |
    3060             :  |                                                                           |
    3061             :  |   Outputs :                                                               |
    3062             :  |                                                                           |
    3063             :  |    none                                                                   |
    3064             :  |                                                                           |
    3065             :  |   Return Value :                                                          |
    3066             :  |                                                                           |
    3067             :  |    var_out                                                                |
    3068             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    3069             :  |             range : 0x8000 0000 <= var_out <= 0x7fff ffff.                |
    3070             :  |                                                                           |
    3071             :  |___________________________________________________________________________|
    3072             : */
    3073             : #ifdef BASOP_NOGLOB
    3074           0 : Word32 L_mls_o( Word32 Lv, Word16 v, Flag *Overflow )
    3075             : {
    3076             :     Word32 Temp;
    3077             : 
    3078           0 :     Temp = Lv & (Word32) 0x0000ffff;
    3079           0 :     Temp = Temp * (Word32) v;
    3080           0 :     Temp = L_shr( Temp, (Word16) 15 );
    3081           0 :     Temp = L_mac_o( Temp, v, extract_h( Lv ), Overflow );
    3082             : 
    3083             : #ifdef WMOPS
    3084             :     multiCounter[currCounter].L_shr--;
    3085             :     multiCounter[currCounter].L_mac--;
    3086             :     multiCounter[currCounter].extract_h--;
    3087             :     multiCounter[currCounter].L_mls++;
    3088             : #endif
    3089             : 
    3090             :     BASOP_CHECK();
    3091             : 
    3092           0 :     return Temp;
    3093             : }
    3094             : 
    3095             : #endif /* BASOP_NOGLOB */
    3096        3890 : Word32 L_mls( Word32 Lv, Word16 v )
    3097             : {
    3098             :     Word32 Temp;
    3099             : 
    3100        3890 :     Temp = Lv & (Word32) 0x0000ffff;
    3101        3890 :     Temp = Temp * (Word32) v;
    3102        3890 :     Temp = L_shr( Temp, (Word16) 15 );
    3103        3890 :     Temp = L_mac( Temp, v, extract_h( Lv ) );
    3104             : 
    3105             : #ifdef WMOPS
    3106             :     multiCounter[currCounter].L_shr--;
    3107             :     multiCounter[currCounter].L_mac--;
    3108             :     multiCounter[currCounter].extract_h--;
    3109             :     multiCounter[currCounter].L_mls++;
    3110             : #endif
    3111             : 
    3112             :     BASOP_CHECK();
    3113             : 
    3114        3890 :     return Temp;
    3115             : }
    3116             : 
    3117             : 
    3118             : /*__________________________________________________________________________
    3119             : |                                                                           |
    3120             : |   Function Name : div_l                                                   |
    3121             : |                                                                           |
    3122             : |   Purpose :                                                               |
    3123             : |                                                                           |
    3124             : |   Produces a result which is the fractional integer division of L_var1 by |
    3125             : |   var2; L_var1 and var2 must be positive and var2 << 16 must be greater or|
    3126             : |   equal to L_var1; the result is positive (leading bit equal to 0) and    |
    3127             : |   truncated to 16 bits.                                                   |
    3128             : |   If L_var1 == var2 << 16 then div_l(L_var1,var2) = 32767.                |
    3129             : |                                                                           |
    3130             : |   Complexity weight : 32                                                  |
    3131             : |                                                                           |
    3132             : |   Inputs :                                                                |
    3133             : |                                                                           |
    3134             : |    L_var1                                                                 |
    3135             : |             32 bit long signed integer (Word32) whose value falls in the  |
    3136             : |             range : 0x0000 0000 <= var1 <= (var2 << 16)  and var2 != 0.   |
    3137             : |             L_var1 must be considered as a Q.31 value                     |
    3138             : |                                                                           |
    3139             : |    var2                                                                   |
    3140             : |             16 bit short signed integer (Word16) whose value falls in the |
    3141             : |             range : var1 <= (var2<< 16) <= 0x7fff0000 and var2 != 0.      |
    3142             : |             var2 must be considered as a Q.15 value                       |
    3143             : |                                                                           |
    3144             : |   Outputs :                                                               |
    3145             : |                                                                           |
    3146             : |    none                                                                   |
    3147             : |                                                                           |
    3148             : |   Return Value :                                                          |
    3149             : |                                                                           |
    3150             : |    var_out                                                                |
    3151             : |             16 bit short signed integer (Word16) whose value falls in the |
    3152             : |             range : 0x0000 0000 <= var_out <= 0x0000 7fff.                |
    3153             : |             It's a Q15 value (point between b15 and b14).                 |
    3154             : |___________________________________________________________________________|
    3155             : */
    3156       38189 : Word16 div_l( Word32 L_num, Word16 den )
    3157             : {
    3158       38189 :     Word16 var_out = (Word16) 0;
    3159             :     Word32 L_den;
    3160             :     Word16 iteration;
    3161             : 
    3162             : #ifdef WMOPS
    3163             :     multiCounter[currCounter].div_l++;
    3164             : #endif
    3165             : 
    3166       38189 :     if ( den == (Word16) 0 )
    3167             :     {
    3168             :         /* printf("Division by 0 in div_l, Fatal error in "); printStack(); */
    3169           0 :         exit( -1 );
    3170             :     }
    3171             : 
    3172       38189 :     if ( ( L_num < (Word32) 0 ) || ( den < (Word16) 0 ) )
    3173             :     {
    3174             :         /* printf("Division Error in div_l, Fatal error in "); printStack(); */
    3175           0 :         exit( -1 );
    3176             :     }
    3177             : 
    3178       38189 :     L_den = L_deposit_h( den );
    3179             : #ifdef WMOPS
    3180             :     multiCounter[currCounter].L_deposit_h--;
    3181             : #endif
    3182             : 
    3183       38189 :     if ( L_num >= L_den )
    3184             :     {
    3185             : 
    3186             : 
    3187             :         BASOP_CHECK();
    3188        1737 :         return MAX_16;
    3189             :     }
    3190             :     else
    3191             :     {
    3192       36452 :         L_num = L_shr( L_num, (Word16) 1 );
    3193       36452 :         L_den = L_shr( L_den, (Word16) 1 );
    3194             : #ifdef WMOPS
    3195             :         multiCounter[currCounter].L_shr -= 2;
    3196             : #endif
    3197      583232 :         for ( iteration = (Word16) 0; iteration < (Word16) 15; iteration++ )
    3198             :         {
    3199      546780 :             var_out = shl( var_out, (Word16) 1 );
    3200      546780 :             L_num = L_shl( L_num, (Word16) 1 );
    3201             : #ifdef WMOPS
    3202             :             multiCounter[currCounter].shl--;
    3203             :             multiCounter[currCounter].L_shl--;
    3204             : #endif
    3205      546780 :             if ( L_num >= L_den )
    3206             :             {
    3207      208555 :                 L_num = L_sub( L_num, L_den );
    3208      208555 :                 var_out = add( var_out, (Word16) 1 );
    3209             : #ifdef WMOPS
    3210             :                 multiCounter[currCounter].L_sub--;
    3211             :                 multiCounter[currCounter].add--;
    3212             : #endif
    3213             :             }
    3214             :         }
    3215             : 
    3216             : 
    3217             :         BASOP_CHECK();
    3218             : 
    3219       36452 :         return var_out;
    3220             :     }
    3221             : }
    3222             : 
    3223             : 
    3224             : /*__________________________________________________________________________
    3225             : |                                                                           |
    3226             : |   Function Name : i_mult                                                  |
    3227             : |                                                                           |
    3228             : |   Purpose :                                                               |
    3229             : |                                                                           |
    3230             : |   Integer 16-bit multiplication with overflow control.                    |
    3231             : |   No overflow protection is performed if ORIGINAL_G7231 is defined.       |
    3232             : |                                                                           |
    3233             : |   Complexity weight : 3 (it is performing something equivalent to         |
    3234             : |                          extract_h( L_shl( L_mult0( v1, v2), 16))         |
    3235             : |                                                                           |
    3236             : |   Inputs :                                                                |
    3237             : |                                                                           |
    3238             : |    a                                                                      |
    3239             : |             16 bit short signed integer (Word16).                         |
    3240             : |                                                                           |
    3241             : |    b                                                                      |
    3242             : |             16 bit short signed integer (Word16).                         |
    3243             : |                                                                           |
    3244             : |   Outputs :                                                               |
    3245             : |                                                                           |
    3246             : |    none                                                                   |
    3247             : |                                                                           |
    3248             : |   Return Value :                                                          |
    3249             : |                                                                           |
    3250             : |             16 bit short signed integer (Word16). No overflow checks      |
    3251             : |             are performed if ORIGINAL_G7231 is defined.                   |
    3252             : |___________________________________________________________________________|
    3253             : */
    3254             : #ifndef BASOP_NOGLOB
    3255             : Word16 i_mult( Word16 a, Word16 b )
    3256             : #else  /* BASOP_NOGLOB */
    3257           0 : Word16 DEPR_i_mult( Word16 a, Word16 b )
    3258             : #endif /* BASOP_NOGLOB */
    3259             : {
    3260             : #ifdef ORIGINAL_G7231
    3261             :     return a * b;
    3262             : #else
    3263           0 :     Word32 /*register*/ c = a * b;
    3264             : #ifdef WMOPS
    3265             :     multiCounter[currCounter].i_mult++;
    3266             : #endif
    3267           0 :     return saturate( c );
    3268             : #endif
    3269             : }
    3270             : 
    3271             : 
    3272             : /*
    3273             :  ******************************************************************************
    3274             :  * The following three operators are not part of the original
    3275             :  * G.729/G.723.1 set of basic operators and implement shiftless
    3276             :  * accumulation operation.
    3277             :  ******************************************************************************
    3278             :  */
    3279             : 
    3280             : /*___________________________________________________________________________
    3281             :  |
    3282             :  |   Function Name : L_mult0
    3283             :  |
    3284             :  |   Purpose :
    3285             :  |
    3286             :  |   L_mult0 is the 32 bit result of the multiplication of var1 times var2
    3287             :  |   without one left shift.
    3288             :  |
    3289             :  |   Complexity weight : 1
    3290             :  |
    3291             :  |   Inputs :
    3292             :  |
    3293             :  |    var1     16 bit short signed integer (Word16) whose value falls in the
    3294             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3295             :  |
    3296             :  |    var2     16 bit short signed integer (Word16) whose value falls in the
    3297             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3298             :  |
    3299             :  |   Return Value :
    3300             :  |
    3301             :  |    L_var_out
    3302             :  |             32 bit long signed integer (Word32) whose value falls in the
    3303             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
    3304             :  |___________________________________________________________________________
    3305             : */
    3306   175291611 : Word32 L_mult0( Word16 var1, Word16 var2 )
    3307             : {
    3308             :     Word32 L_var_out;
    3309             : 
    3310   175291611 :     L_var_out = (Word32) var1 * (Word32) var2;
    3311             : 
    3312             : #ifdef WMOPS
    3313             :     multiCounter[currCounter].L_mult0++;
    3314             : #endif
    3315             : 
    3316             : 
    3317   175291611 :     return ( L_var_out );
    3318             : }
    3319             : 
    3320             : 
    3321             : /*___________________________________________________________________________
    3322             :  |
    3323             :  |   Function Name : L_mac0
    3324             :  |
    3325             :  |   Purpose :
    3326             :  |
    3327             :  |   Multiply var1 by var2 (without left shift) and add the 32 bit result to
    3328             :  |   L_var3 with saturation, return a 32 bit result:
    3329             :  |        L_mac0(L_var3,var1,var2) = L_add(L_var3,(L_mult0(var1,var2)).
    3330             :  |
    3331             :  |   Complexity weight : 1
    3332             :  |
    3333             :  |   Inputs :
    3334             :  |
    3335             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the
    3336             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
    3337             :  |
    3338             :  |    var1     16 bit short signed integer (Word16) whose value falls in the
    3339             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3340             :  |
    3341             :  |    var2     16 bit short signed integer (Word16) whose value falls in the
    3342             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3343             :  |
    3344             :  |   Return Value :
    3345             :  |
    3346             :  |    L_var_out
    3347             :  |             32 bit long signed integer (Word32) whose value falls in the
    3348             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
    3349             :  |___________________________________________________________________________
    3350             : */
    3351             : #ifdef BASOP_NOGLOB
    3352           0 : Word32 L_mac0_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    3353             : {
    3354             :     Word32 L_var_out;
    3355             :     Word32 L_product;
    3356             : 
    3357           0 :     L_product = L_mult0( var1, var2 );
    3358           0 :     L_var_out = L_add_o( L_var3, L_product, Overflow );
    3359             : 
    3360             : #ifdef WMOPS
    3361             :     multiCounter[currCounter].L_mac0++;
    3362             :     multiCounter[currCounter].L_mult0--;
    3363             :     multiCounter[currCounter].L_add--;
    3364             : #endif
    3365             : 
    3366             :     BASOP_CHECK();
    3367             : 
    3368           0 :     return ( L_var_out );
    3369             : }
    3370             : 
    3371             : #endif /* BASOP_NOGLOB */
    3372   171088284 : Word32 L_mac0( Word32 L_var3, Word16 var1, Word16 var2 )
    3373             : {
    3374             :     Word32 L_var_out;
    3375             :     Word32 L_product;
    3376             : 
    3377   171088284 :     L_product = L_mult0( var1, var2 );
    3378   171088284 :     L_var_out = L_add( L_var3, L_product );
    3379             : 
    3380             : #ifdef WMOPS
    3381             :     multiCounter[currCounter].L_mac0++;
    3382             :     multiCounter[currCounter].L_mult0--;
    3383             :     multiCounter[currCounter].L_add--;
    3384             : #endif
    3385             : 
    3386             :     BASOP_CHECK();
    3387             : 
    3388             : 
    3389   171088284 :     return ( L_var_out );
    3390             : }
    3391             : 
    3392             : 
    3393             : /*___________________________________________________________________________
    3394             :  |
    3395             :  |   Function Name : L_msu0
    3396             :  |
    3397             :  |   Purpose :
    3398             :  |
    3399             :  |   Multiply var1 by var2 (without left shift) and subtract the 32 bit
    3400             :  |   result to L_var3 with saturation, return a 32 bit result:
    3401             :  |        L_msu0(L_var3,var1,var2) = L_sub(L_var3,(L_mult0(var1,var2)).
    3402             :  |
    3403             :  |   Complexity weight : 1
    3404             :  |
    3405             :  |   Inputs :
    3406             :  |
    3407             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the
    3408             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
    3409             :  |
    3410             :  |    var1     16 bit short signed integer (Word16) whose value falls in the
    3411             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3412             :  |
    3413             :  |    var2     16 bit short signed integer (Word16) whose value falls in the
    3414             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3415             :  |
    3416             :  |   Return Value :
    3417             :  |
    3418             :  |    L_var_out
    3419             :  |             32 bit long signed integer (Word32) whose value falls in the
    3420             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
    3421             :  |___________________________________________________________________________
    3422             : */
    3423             : #ifdef BASOP_NOGLOB
    3424           0 : Word32 L_msu0_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    3425             : {
    3426             :     Word32 L_var_out;
    3427             :     Word32 L_product;
    3428             : 
    3429           0 :     L_product = L_mult0( var1, var2 );
    3430           0 :     L_var_out = L_sub_o( L_var3, L_product, Overflow );
    3431             : 
    3432             : #ifdef WMOPS
    3433             :     multiCounter[currCounter].L_msu0++;
    3434             :     multiCounter[currCounter].L_mult0--;
    3435             :     multiCounter[currCounter].L_sub--;
    3436             : #endif
    3437             : 
    3438             :     BASOP_CHECK();
    3439             : 
    3440           0 :     return ( L_var_out );
    3441             : }
    3442             : 
    3443             : #endif /* BASOP_NOGLOB */
    3444        3369 : Word32 L_msu0( Word32 L_var3, Word16 var1, Word16 var2 )
    3445             : {
    3446             :     Word32 L_var_out;
    3447             :     Word32 L_product;
    3448             : 
    3449        3369 :     L_product = L_mult0( var1, var2 );
    3450        3369 :     L_var_out = L_sub( L_var3, L_product );
    3451             : 
    3452             : #ifdef WMOPS
    3453             :     multiCounter[currCounter].L_msu0++;
    3454             :     multiCounter[currCounter].L_mult0--;
    3455             :     multiCounter[currCounter].L_sub--;
    3456             : #endif
    3457             : 
    3458             :     BASOP_CHECK();
    3459             : 
    3460             : 
    3461        3369 :     return ( L_var_out );
    3462             : }
    3463             : 
    3464             : #undef WMC_TOOL_SKIP

Generated by: LCOV version 1.14