LCOV - code coverage report
Current view: top level - lib_com - basop32.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 465 607 76.6 %
Date: 2025-05-03 01:55:50 Functions: 85 103 82.5 %

          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 "options.h"
     163             : #include "stl.h"
     164             : 
     165             : #include <assert.h>
     166             : 
     167             : #define WMC_TOOL_SKIP
     168             : 
     169             : #ifdef _MSC_VER
     170             : #pragma warning( disable : 4310 )
     171             : #endif
     172             : 
     173             : 
     174             : /*___________________________________________________________________________
     175             :  |                                                                           |
     176             :  |   Local Functions                                                         |
     177             :  |___________________________________________________________________________|
     178             : */
     179             : static Word16 saturate_o( Word32 L_var1, Flag *Overflow );
     180             : static Word16 saturate( Word32 L_var1 );
     181             : 
     182             : 
     183             : /*___________________________________________________________________________
     184             :  |                                                                           |
     185             :  |   Constants and Globals                                                   |
     186             :  |___________________________________________________________________________|
     187             : */
     188             : 
     189             : #ifdef BASOP_PRINT_ON_WARNING
     190             : #include <stdio.h>
     191             : #if defined( __unix__ ) || defined( __unix ) || defined( __APPLE__ )
     192             : #include <execinfo.h>
     193             : /* Using macro instead of function here to avoid pushing new frames onto the stack */
     194             : #define PRINT_STACK()                                          \
     195             :     do                                                         \
     196             :     {                                                          \
     197             :         void *call_stack[200];                                 \
     198             :         int i;                                                 \
     199             :         int num_frames;                                        \
     200             :         char **strings;                                        \
     201             :                                                                \
     202             :         num_frames = backtrace( call_stack, 200 );             \
     203             :         strings = backtrace_symbols( call_stack, num_frames ); \
     204             :         for ( i = 0; i < num_frames; ++i )                     \
     205             :         {                                                      \
     206             :             printf( "[BASOP] %s\n", strings[i] );              \
     207             :         }                                                      \
     208             :         free( strings );                                       \
     209             :     } while ( 0 )
     210             : #elif defined _WIN32 || defined _WIN64
     211             : #include <windows.h>
     212             : #include <dbghelp.h>
     213             : #pragma comment( lib, "Dbghelp.lib" )
     214             : 
     215             : /* Using macro instead of function here to avoid pushing new frames onto the stack */
     216             : #define PRINT_STACK()                                                                  \
     217             :     do                                                                                 \
     218             :     {                                                                                  \
     219             :         void *call_stack[200];                                                         \
     220             :         int i;                                                                         \
     221             :         int num_frames;                                                                \
     222             :         DWORD64 offset;                                                                \
     223             :         SYMBOL_INFO *symbol;                                                           \
     224             :         IMAGEHLP_MODULE module;                                                        \
     225             :         HANDLE process;                                                                \
     226             :                                                                                        \
     227             :         process = GetCurrentProcess();                                                 \
     228             :         SymInitialize( process, NULL, TRUE );                                          \
     229             :         symbol =                                                                       \
     230             :             (SYMBOL_INFO *) calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 ); \
     231             :         symbol->MaxNameLen = 255;                                                      \
     232             :         symbol->SizeOfStruct = sizeof( SYMBOL_INFO );                                  \
     233             :         module.SizeOfStruct = sizeof( IMAGEHLP_MODULE64 );                             \
     234             :                                                                                        \
     235             :         IMAGEHLP_LINE *line_info =                                                     \
     236             :             (IMAGEHLP_LINE *) calloc( sizeof( IMAGEHLP_LINE ), 1 );                    \
     237             :         line_info->SizeOfStruct = sizeof( IMAGEHLP_LINE );                             \
     238             :                                                                                        \
     239             :         num_frames = CaptureStackBackTrace( 0, 200, call_stack, NULL );                \
     240             :         for ( i = 0; i < num_frames; ++i )                                             \
     241             :         {                                                                              \
     242             :             DWORD dwLineDisplacement;                                                  \
     243             :             SymFromAddr( process, (DWORD64) ( call_stack[i] ), &offset, symbol );      \
     244             :             SymGetModuleInfo( process, (DWORD) symbol->ModBase, &module );             \
     245             :             if ( SymGetLineFromAddr( process, (DWORD64) ( call_stack[i] ),             \
     246             :                                      &dwLineDisplacement, line_info ) )                \
     247             :             {                                                                          \
     248             :                 printf( "[BASOP] %i\t%s(%s+0x%llX) [0x%llX] %s:%d\n", i,               \
     249             :                         module.ModuleName, symbol->Name, offset, symbol->Address,      \
     250             :                         line_info->FileName, line_info->LineNumber );                  \
     251             :             }                                                                          \
     252             :             else                                                                       \
     253             :             {                                                                          \
     254             :                 printf( "[BASOP] %i\t%s(%s+0x%llX) [0x%llX]\n", i, module.ModuleName,  \
     255             :                         symbol->Name, offset, symbol->Address );                       \
     256             :             }                                                                          \
     257             :         }                                                                              \
     258             :         free( line_info );                                                             \
     259             :         free( symbol );                                                                \
     260             :     } while ( 0 )
     261             : #else
     262             : #define PRINT_STACK()                                                              \
     263             :     do                                                                             \
     264             :     {                                                                              \
     265             :         printf( "[BASOP] <call stack would be here> - printing call stack is not " \
     266             :                 "supported on this platform\n" );                                  \
     267             :     } while ( 0 )
     268             : #endif
     269             : 
     270             : /* Using macro instead of function here to avoid pushing new frames onto the stack */
     271             : #define PRINT_BASOP_NOGLOB_WARNING()                         \
     272             :     do                                                       \
     273             :     {                                                        \
     274             :         printf( "[BASOP] Overflow occured. Call stack:\n" ); \
     275             :         PRINT_STACK();                                       \
     276             :     } while ( 0 )
     277             : 
     278             : /* Using macro instead of function here to avoid pushing new frames onto the stack */
     279             : #define PRINT_BASOP_NOGLOB_ERROR()                                 \
     280             :     do                                                             \
     281             :     {                                                              \
     282             :         printf( "[BASOP] Overflow error occured. Call stack:\n" ); \
     283             :         PRINT_STACK();                                             \
     284             :     } while ( 0 )
     285             : #endif /* BASOP_PRINT_ON_WARNING */
     286             : 
     287             : #if defined BASOP_PRINT_ON_WARNING || defined BASOP_ABORT_ON_WARNING
     288             : int BASOP_saturation_warning_enable = 1, BASOP_saturation_warning_disable_counter = 0;
     289             : int BASOP_warnings_as_errors = 0;
     290             : #endif
     291             : 
     292             : #ifdef BASOP_PRINT_ON_WARNING
     293             : #define B_HELPER_PRINT_WARNING()               \
     294             :     do                                         \
     295             :     {                                          \
     296             :         if ( BASOP_saturation_warning_enable ) \
     297             :         {                                      \
     298             :             if ( BASOP_warnings_as_errors )    \
     299             :             {                                  \
     300             :                 PRINT_BASOP_NOGLOB_ERROR();    \
     301             :             }                                  \
     302             :             else                               \
     303             :             {                                  \
     304             :                 PRINT_BASOP_NOGLOB_WARNING();  \
     305             :             }                                  \
     306             :         }                                      \
     307             :     } while ( 0 )
     308             : #else
     309             : #define B_HELPER_PRINT_WARNING() \
     310             :     do                           \
     311             :     {                            \
     312             :         (void) 0;                \
     313             :     } while ( 0 ) /* no-op */
     314             : #endif
     315             : 
     316             : #ifdef BASOP_ABORT_ON_WARNING
     317             : #define B_HELPER_ABORT()                       \
     318             :     do                                         \
     319             :     {                                          \
     320             :         if ( BASOP_saturation_warning_enable ) \
     321             :         {                                      \
     322             :             assert( 0 );                       \
     323             :         }                                      \
     324             :     } while ( 0 )
     325             : #else
     326             : #define B_HELPER_ABORT() \
     327             :     do                   \
     328             :     {                    \
     329             :         (void) 0;        \
     330             :     } while ( 0 ) /* no-op */
     331             : #endif
     332             : 
     333             : #ifdef BASOP_NOGLOB_DEV_USE_GLOBALS
     334             : Flag Overflow = 0;
     335             : Flag Carry = 0;
     336             : 
     337             : #define B_HELPER_SET_GLOBAL( global_flag, value ) \
     338             :     do                                            \
     339             :     {                                             \
     340             :         ( global_flag ) = ( value );              \
     341             :     } while ( 0 )
     342             : #define B_HELPER_GET_GLOBAL( global_flag ) ( global_flag )
     343             : #else
     344             : #define B_HELPER_SET_GLOBAL( global_flag, value ) \
     345             :     do                                            \
     346             :     {                                             \
     347             :         (void) 0;                                 \
     348             :     } while ( 0 )                            /* no-op */
     349             : #define B_HELPER_GET_GLOBAL( global_flag ) 0 /* Default to 0 */
     350             : #endif
     351             : 
     352    14262744 : void set_overflow( Flag *overflow )
     353             : {
     354    14262744 :     if ( overflow )
     355    13874322 :         *overflow = 1;
     356             :     else
     357             :     {
     358             :         B_HELPER_PRINT_WARNING();
     359             :         B_HELPER_ABORT();
     360             :         B_HELPER_SET_GLOBAL( Overflow, 1 );
     361             :     }
     362    14262744 : }
     363  2022726590 : void unset_overflow( Flag *overflow )
     364             : {
     365  2022726590 :     if ( overflow )
     366  2022726590 :         *overflow = 0;
     367             :     else
     368             :     {
     369             :         B_HELPER_PRINT_WARNING();
     370             :         B_HELPER_ABORT();
     371             :         B_HELPER_SET_GLOBAL( Overflow, 0 );
     372             :     }
     373  2022726590 : }
     374     6254237 : void set_carry( Flag *carry )
     375             : {
     376     6254237 :     if ( carry )
     377     6254237 :         *carry = 1;
     378             :     else
     379             :     {
     380             :         B_HELPER_PRINT_WARNING();
     381             :         B_HELPER_ABORT();
     382             :         B_HELPER_SET_GLOBAL( Carry, 1 );
     383             :     }
     384     6254237 : }
     385  2025355811 : void unset_carry( Flag *carry )
     386             : {
     387  2025355811 :     if ( carry )
     388  2025355811 :         *carry = 0;
     389             :     else
     390             :     {
     391             :         B_HELPER_PRINT_WARNING();
     392             :         B_HELPER_ABORT();
     393             :         B_HELPER_SET_GLOBAL( Carry, 0 );
     394             :     }
     395  2025355811 : }
     396  4063220096 : Flag get_carry( const Flag *carry )
     397             : {
     398  4063220096 :     if ( carry )
     399  4063220096 :         return *carry;
     400             :     else
     401             :     {
     402             :         B_HELPER_PRINT_WARNING();
     403             :         B_HELPER_ABORT();
     404             :     }
     405           0 :     return B_HELPER_GET_GLOBAL( Carry );
     406             : }
     407             : 
     408             : /* Undef helper macros - these should only be used in functions above */
     409             : #undef B_HELPER_PRINT_WARNING
     410             : #undef B_HELPER_ABORT
     411             : #undef B_HELPER_SET_GLOBAL
     412             : #undef B_HELPER_GET_GLOBAL
     413             : 
     414             : 
     415             : /*___________________________________________________________________________
     416             :  |                                                                           |
     417             :  |   Functions                                                               |
     418             :  |___________________________________________________________________________|
     419             : */
     420             : 
     421             : #define PRINT_STACK_ID_ALL "*"
     422             : 
     423             : 
     424             : /*___________________________________________________________________________
     425             :  |                                                                           |
     426             :  |   Function Name : saturate                                                |
     427             :  |                                                                           |
     428             :  |   Purpose :                                                               |
     429             :  |                                                                           |
     430             :  |    Limit the 32 bit input to the range of a 16 bit word. Must NOT be      |
     431             :  |    referenced from outside applications.                                  |
     432             :  |                                                                           |
     433             :  |   Inputs :                                                                |
     434             :  |                                                                           |
     435             :  |    L_var1                                                                 |
     436             :  |             32 bit long signed integer (Word32) whose value falls in the  |
     437             :  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
     438             :  |                                                                           |
     439             :  |   Outputs :                                                               |
     440             :  |                                                                           |
     441             :  |    none                                                                   |
     442             :  |                                                                           |
     443             :  |   Return Value :                                                          |
     444             :  |                                                                           |
     445             :  |    var_out                                                                |
     446             :  |             16 bit short signed integer (Word16) whose value falls in the |
     447             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     448             :  |___________________________________________________________________________|
     449             : */
     450 11269153854 : static Word16 saturate_o( Word32 L_var1, Flag *Overflow )
     451             : {
     452             :     Word16 var_out;
     453             : 
     454 11269153854 :     if ( L_var1 > 0X00007fffL )
     455             :     {
     456     6023538 :         *Overflow = 1;
     457     6023538 :         var_out = MAX_16;
     458             :     }
     459 11263130316 :     else if ( L_var1 < (Word32) 0xffff8000L )
     460             :     {
     461     4654088 :         *Overflow = 1;
     462     4654088 :         var_out = MIN_16;
     463             :     }
     464             :     else
     465             :     {
     466 11258476228 :         var_out = extract_l( L_var1 );
     467             : #ifdef WMOPS
     468             :         multiCounter[currCounter].extract_l--;
     469             : #endif
     470             :     }
     471             : 
     472             :     BASOP_CHECK();
     473             : 
     474 11269153854 :     return ( var_out );
     475             : }
     476             : 
     477 >21868*10^7 : static Word16 saturate( Word32 L_var1 )
     478             : {
     479             :     Word16 var_out;
     480             : 
     481 >21868*10^7 :     if ( L_var1 > 0X00007fffL )
     482             :     {
     483           0 :         assert( 0 );
     484             :         var_out = MAX_16;
     485             :     }
     486 >21868*10^7 :     else if ( L_var1 < (Word32) 0xffff8000L )
     487             :     {
     488           0 :         assert( 0 );
     489             :         var_out = MIN_16;
     490             :     }
     491             :     else
     492             :     {
     493 >21868*10^7 :         var_out = extract_l( L_var1 );
     494             : #ifdef WMOPS
     495             :         multiCounter[currCounter].extract_l--;
     496             : #endif
     497             :     }
     498             : 
     499             :     BASOP_CHECK();
     500             : 
     501 >21868*10^7 :     return ( var_out );
     502             : }
     503             : 
     504             : /*___________________________________________________________________________
     505             :  |                                                                           |
     506             :  |   Function Name : add                                                     |
     507             :  |                                                                           |
     508             :  |   Purpose :                                                               |
     509             :  |                                                                           |
     510             :  |    Performs the addition (var1+var2) with overflow control and saturation;|
     511             :  |    the 16 bit result is set at +32767 when overflow occurs or at -32768   |
     512             :  |    when underflow occurs.                                                 |
     513             :  |                                                                           |
     514             :  |   Complexity weight : 1                                                   |
     515             :  |                                                                           |
     516             :  |   Inputs :                                                                |
     517             :  |                                                                           |
     518             :  |    var1                                                                   |
     519             :  |             16 bit short signed integer (Word16) whose value falls in the |
     520             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     521             :  |                                                                           |
     522             :  |    var2                                                                   |
     523             :  |             16 bit short signed integer (Word16) whose value falls in the |
     524             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     525             :  |                                                                           |
     526             :  |   Outputs :                                                               |
     527             :  |                                                                           |
     528             :  |    none                                                                   |
     529             :  |                                                                           |
     530             :  |   Return Value :                                                          |
     531             :  |                                                                           |
     532             :  |    var_out                                                                |
     533             :  |             16 bit short signed integer (Word16) whose value falls in the |
     534             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     535             :  |___________________________________________________________________________|
     536             : */
     537  2594973681 : Word16 add_o( Word16 var1, Word16 var2, Flag *Overflow )
     538             : {
     539             :     Word16 var_out;
     540             :     Word32 L_sum;
     541             : 
     542  2594973681 :     L_sum = (Word32) var1 + var2;
     543  2594973681 :     var_out = saturate_o( L_sum, Overflow );
     544             : 
     545             : #ifdef WMOPS
     546             :     multiCounter[currCounter].add++;
     547             : #endif
     548  2594973681 :     return ( var_out );
     549             : }
     550             : 
     551 84368600889 : Word16 add( Word16 var1, Word16 var2 )
     552             : {
     553             :     Word16 var_out;
     554             :     Word32 L_sum;
     555             : 
     556 84368600889 :     L_sum = (Word32) var1 + var2;
     557 84368600889 :     var_out = saturate( L_sum );
     558             : 
     559             : #ifdef WMOPS
     560             :     multiCounter[currCounter].add++;
     561             : #endif
     562 84368600889 :     return ( var_out );
     563             : }
     564  1560352571 : Word16 add_sat( Word16 var1, Word16 var2 )
     565             : {
     566             :     Flag Overflow;
     567  1560352571 :     return add_o( var1, var2, &Overflow );
     568             : }
     569             : /*___________________________________________________________________________
     570             :  |                                                                           |
     571             :  |   Function Name : sub                                                     |
     572             :  |                                                                           |
     573             :  |   Purpose :                                                               |
     574             :  |                                                                           |
     575             :  |    Performs the subtraction (var1+var2) with overflow control and satu-   |
     576             :  |    ration; the 16 bit result is set at +32767 when overflow occurs or at  |
     577             :  |    -32768 when underflow occurs.                                          |
     578             :  |                                                                           |
     579             :  |   Complexity weight : 1                                                   |
     580             :  |                                                                           |
     581             :  |   Inputs :                                                                |
     582             :  |                                                                           |
     583             :  |    var1                                                                   |
     584             :  |             16 bit short signed integer (Word16) whose value falls in the |
     585             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     586             :  |                                                                           |
     587             :  |    var2                                                                   |
     588             :  |             16 bit short signed integer (Word16) whose value falls in the |
     589             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     590             :  |                                                                           |
     591             :  |   Outputs :                                                               |
     592             :  |                                                                           |
     593             :  |    none                                                                   |
     594             :  |                                                                           |
     595             :  |   Return Value :                                                          |
     596             :  |                                                                           |
     597             :  |    var_out                                                                |
     598             :  |             16 bit short signed integer (Word16) whose value falls in the |
     599             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     600             :  |___________________________________________________________________________|
     601             : */
     602  1213332515 : Word16 sub_o( Word16 var1, Word16 var2, Flag *Overflow )
     603             : {
     604             :     Word16 var_out;
     605             :     Word32 L_diff;
     606             : 
     607  1213332515 :     L_diff = (Word32) var1 - var2;
     608  1213332515 :     var_out = saturate_o( L_diff, Overflow );
     609             : 
     610             : #ifdef WMOPS
     611             :     multiCounter[currCounter].sub++;
     612             : #endif
     613  1213332515 :     return ( var_out );
     614             : }
     615             : 
     616 >11561*10^7 : Word16 sub( Word16 var1, Word16 var2 )
     617             : {
     618             :     Word16 var_out;
     619             :     Word32 L_diff;
     620             : 
     621 >11561*10^7 :     L_diff = (Word32) var1 - var2;
     622 >11561*10^7 :     var_out = saturate( L_diff );
     623             : 
     624             : #ifdef WMOPS
     625             :     multiCounter[currCounter].sub++;
     626             : #endif
     627 >11561*10^7 :     return ( var_out );
     628             : }
     629   393675799 : Word16 sub_sat( Word16 var1, Word16 var2 )
     630             : {
     631             :     Flag Overflow;
     632   393675799 :     return sub_o( var1, var2, &Overflow );
     633             : }
     634             : /*___________________________________________________________________________
     635             :  |                                                                           |
     636             :  |   Function Name : abs_s                                                   |
     637             :  |                                                                           |
     638             :  |   Purpose :                                                               |
     639             :  |                                                                           |
     640             :  |    Absolute value of var1; abs_s(-32768) = 32767.                         |
     641             :  |                                                                           |
     642             :  |   Complexity weight : 1                                                   |
     643             :  |                                                                           |
     644             :  |   Inputs :                                                                |
     645             :  |                                                                           |
     646             :  |    var1                                                                   |
     647             :  |             16 bit short signed integer (Word16) whose value falls in the |
     648             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     649             :  |                                                                           |
     650             :  |   Outputs :                                                               |
     651             :  |                                                                           |
     652             :  |    none                                                                   |
     653             :  |                                                                           |
     654             :  |   Return Value :                                                          |
     655             :  |                                                                           |
     656             :  |    var_out                                                                |
     657             :  |             16 bit short signed integer (Word16) whose value falls in the |
     658             :  |             range : 0x0000 0000 <= var_out <= 0x0000 7fff.                |
     659             :  |___________________________________________________________________________|
     660             : */
     661 10184747913 : Word16 abs_s( Word16 var1 )
     662             : {
     663             :     Word16 var_out;
     664             : 
     665 10184747913 :     if ( var1 == (Word16) MIN_16 )
     666             :     {
     667      461139 :         var_out = MAX_16;
     668             :     }
     669             :     else
     670             :     {
     671 10184286774 :         if ( var1 < 0 )
     672             :         {
     673  2792118640 :             var_out = -var1;
     674             :         }
     675             :         else
     676             :         {
     677  7392168134 :             var_out = var1;
     678             :         }
     679             :     }
     680             : 
     681             : #ifdef WMOPS
     682             :     multiCounter[currCounter].abs_s++;
     683             : #endif
     684             :     BASOP_CHECK();
     685             : 
     686             : 
     687 10184747913 :     return ( var_out );
     688             : }
     689             : 
     690             : 
     691             : /*___________________________________________________________________________
     692             :  |                                                                           |
     693             :  |   Function Name : shl                                                     |
     694             :  |                                                                           |
     695             :  |   Purpose :                                                               |
     696             :  |                                                                           |
     697             :  |   Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill|
     698             :  |   the var2 LSB of the result. If var2 is negative, arithmetically shift   |
     699             :  |   var1 right by -var2 with sign extension. Saturate the result in case of |
     700             :  |   underflows or overflows.                                                |
     701             :  |                                                                           |
     702             :  |   Complexity weight : 1                                                   |
     703             :  |                                                                           |
     704             :  |   Inputs :                                                                |
     705             :  |                                                                           |
     706             :  |    var1                                                                   |
     707             :  |             16 bit short signed integer (Word16) whose value falls in the |
     708             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     709             :  |                                                                           |
     710             :  |    var2                                                                   |
     711             :  |             16 bit short signed integer (Word16) whose value falls in the |
     712             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     713             :  |                                                                           |
     714             :  |   Outputs :                                                               |
     715             :  |                                                                           |
     716             :  |    none                                                                   |
     717             :  |                                                                           |
     718             :  |   Return Value :                                                          |
     719             :  |                                                                           |
     720             :  |    var_out                                                                |
     721             :  |             16 bit short signed integer (Word16) whose value falls in the |
     722             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     723             :  |___________________________________________________________________________|
     724             : */
     725 14280251475 : Word16 shl_o( Word16 var1, Word16 var2, Flag *Overflow )
     726             : {
     727             :     Word16 var_out;
     728             :     Word32 result;
     729             : 
     730 14280251475 :     if ( var2 < 0 )
     731             :     {
     732   219354508 :         if ( var2 < -16 )
     733      988415 :             var2 = -16;
     734   219354508 :         var2 = -var2;
     735   219354508 :         var_out = shr( var1, var2 );
     736             : 
     737             : #ifdef WMOPS
     738             :         multiCounter[currCounter].shr--;
     739             : #endif
     740             :     }
     741             :     else
     742             :     {
     743 14060896967 :         result = (Word32) var1 * ( (Word32) 1 << var2 );
     744             : 
     745 14060896967 :         if ( ( var2 > 15 && var1 != 0 ) || ( result != (Word32) ( (Word16) result ) ) )
     746             :         {
     747   118115891 :             *Overflow = 1;
     748   118115891 :             var_out = ( var1 > 0 ) ? MAX_16 : MIN_16;
     749             :         }
     750             :         else
     751             :         {
     752 13942781076 :             var_out = extract_l( result );
     753             : 
     754             : #ifdef WMOPS
     755             :             multiCounter[currCounter].extract_l--;
     756             : #endif
     757             :         }
     758             :     }
     759             : 
     760             : #ifdef WMOPS
     761             :     multiCounter[currCounter].shl++;
     762             : #endif
     763             : 
     764             :     BASOP_CHECK();
     765             : 
     766             : 
     767 14280251475 :     return ( var_out );
     768             : }
     769             : 
     770 20420929807 : Word16 shl( Word16 var1, Word16 var2 )
     771             : {
     772             :     Word16 var_out;
     773             :     Word32 result;
     774             : 
     775 20420929807 :     if ( var2 < 0 )
     776             :     {
     777  1238750078 :         if ( var2 < -16 )
     778      114617 :             var2 = -16;
     779  1238750078 :         var2 = -var2;
     780  1238750078 :         var_out = shr( var1, var2 );
     781             : 
     782             : #ifdef WMOPS
     783             :         multiCounter[currCounter].shr--;
     784             : #endif
     785             :     }
     786             :     else
     787             :     {
     788 19182179729 :         result = (Word32) var1 * ( (Word32) 1 << var2 );
     789             : 
     790 19182179729 :         if ( ( var2 > 15 && var1 != 0 ) || ( result != (Word32) ( (Word16) result ) ) )
     791             :         {
     792           0 :             assert( 0 );
     793             :             var_out = ( var1 > 0 ) ? MAX_16 : MIN_16;
     794             :         }
     795             :         else
     796             :         {
     797 19182179729 :             var_out = extract_l( result );
     798             : 
     799             : #ifdef WMOPS
     800             :             multiCounter[currCounter].extract_l--;
     801             : #endif
     802             :         }
     803             :     }
     804             : 
     805             : #ifdef WMOPS
     806             :     multiCounter[currCounter].shl++;
     807             : #endif
     808             :     BASOP_CHECK();
     809             : 
     810             : 
     811 20420929807 :     return ( var_out );
     812             : }
     813             : 
     814 11821893772 : Word16 shl_sat( Word16 var1, Word16 var2 )
     815             : {
     816             :     Flag Overflow;
     817 11821893772 :     return shl_o( var1, var2, &Overflow );
     818             : }
     819             : 
     820             : /*___________________________________________________________________________
     821             :  |                                                                           |
     822             :  |   Function Name : shr                                                     |
     823             :  |                                                                           |
     824             :  |   Purpose :                                                               |
     825             :  |                                                                           |
     826             :  |   Arithmetically shift the 16 bit input var1 right var2 positions with    |
     827             :  |   sign extension. If var2 is negative, arithmetically shift var1 left by  |
     828             :  |   -var2 with sign extension. Saturate the result in case of underflows or |
     829             :  |   overflows.                                                              |
     830             :  |                                                                           |
     831             :  |   Complexity weight : 1                                                   |
     832             :  |                                                                           |
     833             :  |   Inputs :                                                                |
     834             :  |                                                                           |
     835             :  |    var1                                                                   |
     836             :  |             16 bit short signed integer (Word16) whose value falls in the |
     837             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     838             :  |                                                                           |
     839             :  |    var2                                                                   |
     840             :  |             16 bit short signed integer (Word16) whose value falls in the |
     841             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     842             :  |                                                                           |
     843             :  |   Outputs :                                                               |
     844             :  |                                                                           |
     845             :  |    none                                                                   |
     846             :  |                                                                           |
     847             :  |   Return Value :                                                          |
     848             :  |                                                                           |
     849             :  |    var_out                                                                |
     850             :  |             16 bit short signed integer (Word16) whose value falls in the |
     851             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     852             :  |___________________________________________________________________________|
     853             : */
     854 14399470169 : Word16 shr_o( Word16 var1, Word16 var2, Flag *Overflow )
     855             : {
     856             :     Word16 var_out;
     857             : 
     858 14399470169 :     if ( var2 < 0 )
     859             :     {
     860   158277649 :         if ( var2 < -16 )
     861     2798669 :             var2 = -16;
     862   158277649 :         var2 = -var2;
     863   158277649 :         var_out = shl_o( var1, var2, Overflow );
     864             : 
     865             : #ifdef WMOPS
     866             :         multiCounter[currCounter].shl--;
     867             : #endif
     868             :     }
     869             :     else
     870             :     {
     871 14241192520 :         if ( var2 >= 15 )
     872             :         {
     873   525731653 :             var_out = ( var1 < 0 ) ? -1 : 0;
     874             :         }
     875             :         else
     876             :         {
     877 13715460867 :             if ( var1 < 0 )
     878             :             {
     879  3786447441 :                 var_out = ~( ( ~var1 ) >> var2 );
     880             :             }
     881             :             else
     882             :             {
     883  9929013426 :                 var_out = var1 >> var2;
     884             :             }
     885             :         }
     886             :     }
     887             : 
     888             : #ifdef WMOPS
     889             :     multiCounter[currCounter].shr++;
     890             : #endif
     891             : 
     892             :     BASOP_CHECK();
     893             : 
     894 14399470169 :     return ( var_out );
     895             : }
     896             : 
     897 11489905483 : Word16 shr( Word16 var1, Word16 var2 )
     898             : {
     899 11489905483 :     return shr_o( var1, var2, NULL );
     900             : }
     901  2762000216 : Word16 shr_sat( Word16 var1, Word16 var2 )
     902             : {
     903             :     Flag Overflow;
     904  2762000216 :     return shr_o( var1, var2, &Overflow );
     905             : }
     906             : 
     907             : 
     908             : /*___________________________________________________________________________
     909             :  |                                                                           |
     910             :  |   Function Name : mult                                                    |
     911             :  |                                                                           |
     912             :  |   Purpose :                                                               |
     913             :  |                                                                           |
     914             :  |    Performs the multiplication of var1 by var2 and gives a 16 bit result  |
     915             :  |    which is scaled i.e.:                                                  |
     916             :  |             mult(var1,var2) = extract_l(L_shr((var1 times var2),15)) and  |
     917             :  |             mult(-32768,-32768) = 32767.                                  |
     918             :  |                                                                           |
     919             :  |   Complexity weight : 1                                                   |
     920             :  |                                                                           |
     921             :  |   Inputs :                                                                |
     922             :  |                                                                           |
     923             :  |    var1                                                                   |
     924             :  |             16 bit short signed integer (Word16) whose value falls in the |
     925             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     926             :  |                                                                           |
     927             :  |    var2                                                                   |
     928             :  |             16 bit short signed integer (Word16) whose value falls in the |
     929             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
     930             :  |                                                                           |
     931             :  |   Outputs :                                                               |
     932             :  |                                                                           |
     933             :  |    none                                                                   |
     934             :  |                                                                           |
     935             :  |   Return Value :                                                          |
     936             :  |                                                                           |
     937             :  |    var_out                                                                |
     938             :  |             16 bit short signed integer (Word16) whose value falls in the |
     939             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
     940             :  |___________________________________________________________________________|
     941             : */
     942    41203901 : Word16 mult_o( Word16 var1, Word16 var2, Flag *Overflow )
     943             : {
     944             :     Word16 var_out;
     945             :     Word32 L_product;
     946             : 
     947    41203901 :     L_product = (Word32) var1 * (Word32) var2;
     948             : 
     949    41203901 :     L_product = ( L_product & (Word32) 0xffff8000L ) >> 15;
     950             : 
     951    41203901 :     if ( L_product & (Word32) 0x00010000L )
     952    18665665 :         L_product = L_product | (Word32) 0xffff0000L;
     953             : 
     954    41203901 :     var_out = saturate_o( L_product, Overflow );
     955             : 
     956             : #ifdef WMOPS
     957             :     multiCounter[currCounter].mult++;
     958             : #endif
     959             : 
     960             :     BASOP_CHECK();
     961    41203901 :     return ( var_out );
     962             : }
     963  9751823543 : Word16 mult( Word16 var1, Word16 var2 )
     964             : {
     965             :     Word16 var_out;
     966             :     Word32 L_product;
     967             : 
     968  9751823543 :     L_product = (Word32) var1 * (Word32) var2;
     969             : 
     970  9751823543 :     L_product = ( L_product & (Word32) 0xffff8000L ) >> 15;
     971             : 
     972  9751823543 :     if ( L_product & (Word32) 0x00010000L )
     973  1267812997 :         L_product = L_product | (Word32) 0xffff0000L;
     974             : 
     975  9751823543 :     var_out = saturate( L_product );
     976             : 
     977             : #ifdef WMOPS
     978             :     multiCounter[currCounter].mult++;
     979             : #endif
     980  9751823543 :     return ( var_out );
     981             : }
     982             : 
     983    41203901 : Word16 mult_sat( Word16 var1, Word16 var2 )
     984             : {
     985             :     Flag Overflow;
     986    41203901 :     return mult_o( var1, var2, &Overflow );
     987             : }
     988             : 
     989             : 
     990             : /*___________________________________________________________________________
     991             :  |                                                                           |
     992             :  |   Function Name : L_mult                                                  |
     993             :  |                                                                           |
     994             :  |   Purpose :                                                               |
     995             :  |                                                                           |
     996             :  |   L_mult is the 32 bit result of the multiplication of var1 times var2    |
     997             :  |   with one shift left i.e.:                                               |
     998             :  |        L_mult(var1,var2) = L_shl((var1 times var2),1) and                 |
     999             :  |        L_mult(-32768,-32768) = 2147483647.                                |
    1000             :  |                                                                           |
    1001             :  |   Complexity weight : 1                                                   |
    1002             :  |                                                                           |
    1003             :  |   Inputs :                                                                |
    1004             :  |                                                                           |
    1005             :  |    var1                                                                   |
    1006             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1007             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1008             :  |                                                                           |
    1009             :  |    var2                                                                   |
    1010             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1011             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1012             :  |                                                                           |
    1013             :  |   Outputs :                                                               |
    1014             :  |                                                                           |
    1015             :  |    none                                                                   |
    1016             :  |                                                                           |
    1017             :  |   Return Value :                                                          |
    1018             :  |                                                                           |
    1019             :  |    L_var_out                                                              |
    1020             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1021             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1022             :  |___________________________________________________________________________|
    1023             : */
    1024 55511192309 : Word32 L_mult_o( Word16 var1, Word16 var2, Flag *Overflow )
    1025             : {
    1026             :     Word32 L_var_out;
    1027             : 
    1028 55511192309 :     L_var_out = (Word32) var1 * (Word32) var2;
    1029             : 
    1030 55511192309 :     if ( L_var_out != (Word32) 0x40000000L )
    1031             :     {
    1032 55510903564 :         L_var_out *= 2;
    1033             :     }
    1034             :     else
    1035             :     {
    1036      288745 :         *Overflow = 1;
    1037      288745 :         L_var_out = MAX_32;
    1038             :     }
    1039             : 
    1040             : #ifdef WMOPS
    1041             :     multiCounter[currCounter].L_mult++;
    1042             : #endif
    1043             : 
    1044             :     BASOP_CHECK();
    1045             : 
    1046 55511192309 :     return ( L_var_out );
    1047             : }
    1048             : 
    1049 56891974281 : Word32 L_mult( Word16 var1, Word16 var2 )
    1050             : {
    1051             :     Word32 L_var_out;
    1052             : 
    1053 56891974281 :     L_var_out = (Word32) var1 * (Word32) var2;
    1054             : 
    1055 56891974281 :     if ( L_var_out != (Word32) 0x40000000L )
    1056             :     {
    1057 56891974281 :         L_var_out *= 2;
    1058             :     }
    1059             :     else
    1060             :     {
    1061           0 :         assert( 0 );
    1062             :         L_var_out = MAX_32;
    1063             :     }
    1064             : 
    1065             : #ifdef WMOPS
    1066             :     multiCounter[currCounter].L_mult++;
    1067             : #endif
    1068             : 
    1069             :     BASOP_CHECK();
    1070             : 
    1071 56891974281 :     return ( L_var_out );
    1072             : }
    1073             : 
    1074   128431763 : Word32 L_mult_sat( Word16 var1, Word16 var2 )
    1075             : {
    1076             :     Flag Overflow;
    1077   128431763 :     return L_mult_o( var1, var2, &Overflow );
    1078             : }
    1079             : 
    1080             : /*___________________________________________________________________________
    1081             :  |                                                                           |
    1082             :  |   Function Name : negate                                                  |
    1083             :  |                                                                           |
    1084             :  |   Purpose :                                                               |
    1085             :  |                                                                           |
    1086             :  |   Negate var1 with saturation, saturate in the case where input is -32768:|
    1087             :  |                negate(var1) = sub(0,var1).                                |
    1088             :  |                                                                           |
    1089             :  |   Complexity weight : 1                                                   |
    1090             :  |                                                                           |
    1091             :  |   Inputs :                                                                |
    1092             :  |                                                                           |
    1093             :  |    var1                                                                   |
    1094             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1095             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1096             :  |                                                                           |
    1097             :  |   Outputs :                                                               |
    1098             :  |                                                                           |
    1099             :  |    none                                                                   |
    1100             :  |                                                                           |
    1101             :  |   Return Value :                                                          |
    1102             :  |                                                                           |
    1103             :  |    var_out                                                                |
    1104             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1105             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
    1106             :  |___________________________________________________________________________|
    1107             : */
    1108  2743006067 : Word16 negate( Word16 var1 )
    1109             : {
    1110             :     Word16 var_out;
    1111             : 
    1112  2743006067 :     var_out = ( var1 == MIN_16 ) ? MAX_16 : -var1;
    1113             : 
    1114             : 
    1115             : #ifdef WMOPS
    1116             :     multiCounter[currCounter].negate++;
    1117             : #endif
    1118             : 
    1119             :     BASOP_CHECK();
    1120             : 
    1121             : 
    1122  2743006067 :     return ( var_out );
    1123             : }
    1124             : 
    1125             : 
    1126             : /*___________________________________________________________________________
    1127             :  |                                                                           |
    1128             :  |   Function Name : extract_h                                               |
    1129             :  |                                                                           |
    1130             :  |   Purpose :                                                               |
    1131             :  |                                                                           |
    1132             :  |   Return the 16 MSB of L_var1.                                            |
    1133             :  |                                                                           |
    1134             :  |   Complexity weight : 1                                                   |
    1135             :  |                                                                           |
    1136             :  |   Inputs :                                                                |
    1137             :  |                                                                           |
    1138             :  |    L_var1                                                                 |
    1139             :  |             32 bit long signed integer (Word32 ) whose value falls in the |
    1140             :  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
    1141             :  |                                                                           |
    1142             :  |   Outputs :                                                               |
    1143             :  |                                                                           |
    1144             :  |    none                                                                   |
    1145             :  |                                                                           |
    1146             :  |   Return Value :                                                          |
    1147             :  |                                                                           |
    1148             :  |    var_out                                                                |
    1149             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1150             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
    1151             :  |___________________________________________________________________________|
    1152             : */
    1153 72555123111 : Word16 extract_h( Word32 L_var1 )
    1154             : {
    1155             :     Word16 var_out;
    1156             : 
    1157 72555123111 :     var_out = (Word16) ( L_var1 >> 16 );
    1158             : 
    1159             : #ifdef WMOPS
    1160             :     multiCounter[currCounter].extract_h++;
    1161             : #endif
    1162             : 
    1163             :     BASOP_CHECK();
    1164             : 
    1165             : 
    1166 72555123111 :     return ( var_out );
    1167             : }
    1168             : 
    1169             : 
    1170             : /*___________________________________________________________________________
    1171             :  |                                                                           |
    1172             :  |   Function Name : extract_l                                               |
    1173             :  |                                                                           |
    1174             :  |   Purpose :                                                               |
    1175             :  |                                                                           |
    1176             :  |   Return the 16 LSB of L_var1.                                            |
    1177             :  |                                                                           |
    1178             :  |   Complexity weight : 1                                                   |
    1179             :  |                                                                           |
    1180             :  |   Inputs :                                                                |
    1181             :  |                                                                           |
    1182             :  |    L_var1                                                                 |
    1183             :  |             32 bit long signed integer (Word32 ) whose value falls in the |
    1184             :  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
    1185             :  |                                                                           |
    1186             :  |   Outputs :                                                               |
    1187             :  |                                                                           |
    1188             :  |    none                                                                   |
    1189             :  |                                                                           |
    1190             :  |   Return Value :                                                          |
    1191             :  |                                                                           |
    1192             :  |    var_out                                                                |
    1193             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1194             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
    1195             :  |___________________________________________________________________________|
    1196             : */
    1197 >27821*10^7 : Word16 extract_l( Word32 L_var1 )
    1198             : {
    1199             :     Word16 var_out;
    1200             : 
    1201 >27821*10^7 :     var_out = (Word16) L_var1;
    1202             : 
    1203             : #ifdef WMOPS
    1204             :     multiCounter[currCounter].extract_l++;
    1205             : #endif
    1206             : 
    1207             :     BASOP_CHECK();
    1208             : 
    1209             : 
    1210 >27821*10^7 :     return ( var_out );
    1211             : }
    1212             : 
    1213             : 
    1214             : /*___________________________________________________________________________
    1215             :  |                                                                           |
    1216             :  |   Function Name : round_fx                                                |
    1217             :  |                                                                           |
    1218             :  |   Purpose :                                                               |
    1219             :  |                                                                           |
    1220             :  |   Round the lower 16 bits of the 32 bit input number into the MS 16 bits  |
    1221             :  |   with saturation. Shift the resulting bits right by 16 and return the 16 |
    1222             :  |   bit number:                                                             |
    1223             :  |               round_fx(L_var1) = extract_h(L_add(L_var1,32768))           |
    1224             :  |                                                                           |
    1225             :  |   Complexity weight : 1                                                   |
    1226             :  |                                                                           |
    1227             :  |   Inputs :                                                                |
    1228             :  |                                                                           |
    1229             :  |    L_var1                                                                 |
    1230             :  |             32 bit long signed integer (Word32 ) whose value falls in the |
    1231             :  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 |
    1232             :  |                                                                           |
    1233             :  |   Outputs :                                                               |
    1234             :  |                                                                           |
    1235             :  |    none                                                                   |
    1236             :  |                                                                           |
    1237             :  |   Return Value :                                                          |
    1238             :  |                                                                           |
    1239             :  |    var_out                                                                |
    1240             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1241             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
    1242             :  |___________________________________________________________________________|
    1243             : */
    1244 20354464117 : Word16 round_fx_o( Word32 L_var1, Flag *Overflow )
    1245             : {
    1246             :     Word16 var_out;
    1247             :     Word32 L_rounded;
    1248             : 
    1249             :     BASOP_SATURATE_WARNING_OFF
    1250 20354464117 :     L_rounded = L_add_o( L_var1, (Word32) 0x00008000L, Overflow );
    1251             :     BASOP_SATURATE_WARNING_ON
    1252 20354464117 :     var_out = extract_h( L_rounded );
    1253             : 
    1254             : #ifdef WMOPS
    1255             :     multiCounter[currCounter].L_add--;
    1256             :     multiCounter[currCounter].extract_h--;
    1257             :     multiCounter[currCounter].round++;
    1258             : #endif
    1259             : 
    1260             :     BASOP_CHECK();
    1261             : 
    1262 20354464117 :     return ( var_out );
    1263             : }
    1264             : 
    1265  6443647988 : Word16 round_fx( Word32 L_var1 )
    1266             : {
    1267             :     Word16 var_out;
    1268             :     Word32 L_rounded;
    1269             : 
    1270             :     BASOP_SATURATE_WARNING_OFF
    1271  6443647988 :     L_rounded = L_add( L_var1, (Word32) 0x00008000L );
    1272             :     BASOP_SATURATE_WARNING_ON
    1273  6443647988 :     var_out = extract_h( L_rounded );
    1274             : 
    1275             : #ifdef WMOPS
    1276             :     multiCounter[currCounter].L_add--;
    1277             :     multiCounter[currCounter].extract_h--;
    1278             :     multiCounter[currCounter].round++;
    1279             : #endif
    1280             :     BASOP_CHECK();
    1281             : 
    1282  6443647988 :     return ( var_out );
    1283             : }
    1284  8330081382 : Word16 round_fx_sat( Word32 L_var1 )
    1285             : {
    1286             :     Flag Overflow;
    1287  8330081382 :     return round_fx_o( L_var1, &Overflow );
    1288             : }
    1289             : /*___________________________________________________________________________
    1290             :  |                                                                           |
    1291             :  |   Function Name : L_mac                                                   |
    1292             :  |                                                                           |
    1293             :  |   Purpose :                                                               |
    1294             :  |                                                                           |
    1295             :  |   Multiply var1 by var2 and shift the result left by 1. Add the 32 bit    |
    1296             :  |   result to L_var3 with saturation, return a 32 bit result:               |
    1297             :  |        L_mac(L_var3,var1,var2) = L_add(L_var3,L_mult(var1,var2)).         |
    1298             :  |                                                                           |
    1299             :  |   Complexity weight : 1                                                   |
    1300             :  |                                                                           |
    1301             :  |   Inputs :                                                                |
    1302             :  |                                                                           |
    1303             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    1304             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1305             :  |                                                                           |
    1306             :  |    var1                                                                   |
    1307             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1308             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1309             :  |                                                                           |
    1310             :  |    var2                                                                   |
    1311             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1312             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1313             :  |                                                                           |
    1314             :  |   Outputs :                                                               |
    1315             :  |                                                                           |
    1316             :  |    none                                                                   |
    1317             :  |                                                                           |
    1318             :  |   Return Value :                                                          |
    1319             :  |                                                                           |
    1320             :  |    L_var_out                                                              |
    1321             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1322             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1323             :  |___________________________________________________________________________|
    1324             : */
    1325 23089578543 : Word32 L_mac_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    1326             : {
    1327             :     Word32 L_var_out;
    1328             :     Word32 L_product;
    1329             : 
    1330 23089578543 :     L_product = L_mult_o( var1, var2, Overflow );
    1331 23089578543 :     L_var_out = L_add_o( L_var3, L_product, Overflow );
    1332             : 
    1333             : #ifdef WMOPS
    1334             :     multiCounter[currCounter].L_mult--;
    1335             :     multiCounter[currCounter].L_add--;
    1336             :     multiCounter[currCounter].L_mac++;
    1337             : #endif
    1338             : 
    1339 23089578543 :     return ( L_var_out );
    1340             : }
    1341             : 
    1342 30749107323 : Word32 L_mac( Word32 L_var3, Word16 var1, Word16 var2 )
    1343             : {
    1344             :     Word32 L_var_out;
    1345             :     Word32 L_product;
    1346             : 
    1347 30749107323 :     L_product = L_mult( var1, var2 );
    1348 30749107323 :     L_var_out = L_add( L_var3, L_product );
    1349             : 
    1350             : #ifdef WMOPS
    1351             :     multiCounter[currCounter].L_mult--;
    1352             :     multiCounter[currCounter].L_add--;
    1353             :     multiCounter[currCounter].L_mac++;
    1354             : #endif
    1355             :     BASOP_CHECK();
    1356             : 
    1357 30749107323 :     return ( L_var_out );
    1358             : }
    1359  2039484465 : Word32 L_mac_sat( Word32 L_var3, Word16 var1, Word16 var2 )
    1360             : {
    1361             :     Flag Overflow;
    1362  2039484465 :     return L_mac_o( L_var3, var1, var2, &Overflow );
    1363             : }
    1364             : /*___________________________________________________________________________
    1365             :  |                                                                           |
    1366             :  |   Function Name : L_msu                                                   |
    1367             :  |                                                                           |
    1368             :  |   Purpose :                                                               |
    1369             :  |                                                                           |
    1370             :  |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   |
    1371             :  |   bit result from L_var3 with saturation, return a 32 bit result:         |
    1372             :  |        L_msu(L_var3,var1,var2) = L_sub(L_var3,L_mult(var1,var2)).         |
    1373             :  |                                                                           |
    1374             :  |   Complexity weight : 1                                                   |
    1375             :  |                                                                           |
    1376             :  |   Inputs :                                                                |
    1377             :  |                                                                           |
    1378             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    1379             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1380             :  |                                                                           |
    1381             :  |    var1                                                                   |
    1382             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1383             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1384             :  |                                                                           |
    1385             :  |    var2                                                                   |
    1386             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1387             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1388             :  |                                                                           |
    1389             :  |   Outputs :                                                               |
    1390             :  |                                                                           |
    1391             :  |    none                                                                   |
    1392             :  |                                                                           |
    1393             :  |   Return Value :                                                          |
    1394             :  |                                                                           |
    1395             :  |    L_var_out                                                              |
    1396             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1397             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1398             :  |___________________________________________________________________________|
    1399             : */
    1400 29909048113 : Word32 L_msu_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    1401             : {
    1402             :     Word32 L_var_out;
    1403             :     Word32 L_product;
    1404             : 
    1405 29909048113 :     L_product = L_mult_o( var1, var2, Overflow );
    1406 29909048113 :     L_var_out = L_sub_o( L_var3, L_product, Overflow );
    1407             : 
    1408             : #ifdef WMOPS
    1409             :     multiCounter[currCounter].L_mult--;
    1410             :     multiCounter[currCounter].L_sub--;
    1411             :     multiCounter[currCounter].L_msu++;
    1412             : #endif
    1413             : 
    1414 29909048113 :     return ( L_var_out );
    1415             : }
    1416             : 
    1417  7311117390 : Word32 L_msu( Word32 L_var3, Word16 var1, Word16 var2 )
    1418             : {
    1419             :     Word32 L_var_out;
    1420             :     Word32 L_product;
    1421             : 
    1422  7311117390 :     L_product = L_mult( var1, var2 );
    1423  7311117390 :     L_var_out = L_sub( L_var3, L_product );
    1424             : 
    1425             : #ifdef WMOPS
    1426             :     multiCounter[currCounter].L_mult--;
    1427             :     multiCounter[currCounter].L_sub--;
    1428             :     multiCounter[currCounter].L_msu++;
    1429             : #endif
    1430             :     BASOP_CHECK();
    1431             : 
    1432  7311117390 :     return ( L_var_out );
    1433             : }
    1434  3084290642 : Word32 L_msu_sat( Word32 L_var3, Word16 var1, Word16 var2 )
    1435             : {
    1436             :     Flag Overflow;
    1437  3084290642 :     return L_msu_o( L_var3, var1, var2, &Overflow );
    1438             : }
    1439             : /*___________________________________________________________________________
    1440             :  |                                                                           |
    1441             :  |   Function Name : L_macNs                                                 |
    1442             :  |                                                                           |
    1443             :  |   Purpose :                                                               |
    1444             :  |                                                                           |
    1445             :  |   Multiply var1 by var2 and shift the result left by 1. Add the 32 bit    |
    1446             :  |   result to L_var3 without saturation, return a 32 bit result. Generate   |
    1447             :  |   carry and overflow values :                                             |
    1448             :  |        L_macNs(L_var3,var1,var2) = L_add_c(L_var3,L_mult(var1,var2)).     |
    1449             :  |                                                                           |
    1450             :  |   Complexity weight : 1                                                   |
    1451             :  |                                                                           |
    1452             :  |   Inputs :                                                                |
    1453             :  |                                                                           |
    1454             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    1455             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1456             :  |                                                                           |
    1457             :  |    var1                                                                   |
    1458             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1459             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1460             :  |                                                                           |
    1461             :  |    var2                                                                   |
    1462             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1463             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1464             :  |                                                                           |
    1465             :  |   Outputs :                                                               |
    1466             :  |                                                                           |
    1467             :  |    none                                                                   |
    1468             :  |                                                                           |
    1469             :  |   Return Value :                                                          |
    1470             :  |                                                                           |
    1471             :  |    L_var_out                                                              |
    1472             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1473             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1474             :  |                                                                           |
    1475             :  |   Caution :                                                               |
    1476             :  |                                                                           |
    1477             :  |    In some cases the BASOP_Carry flag has to be cleared or set before using     |
    1478             :  |    operators which take into account its value.                           |
    1479             :  |___________________________________________________________________________|
    1480             : */
    1481           0 : Word32 DEPR_L_macNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry )
    1482             : {
    1483             :     Word32 L_var_out;
    1484             : 
    1485           0 :     L_var_out = L_mult( var1, var2 );
    1486           0 :     L_var_out = L_add_c( L_var3, L_var_out, Carry );
    1487             : 
    1488             : #ifdef WMOPS
    1489             :     multiCounter[currCounter].L_mult--;
    1490             :     multiCounter[currCounter].L_add_c--;
    1491             :     multiCounter[currCounter].L_macNs++;
    1492             : #endif
    1493             : 
    1494             :     /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
    1495           0 :     return ( L_var_out );
    1496             : }
    1497  1645820364 : Word32 L_macNs_co( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry, Flag *Overflow )
    1498             : {
    1499             :     Word32 L_var_out;
    1500             : 
    1501  1645820364 :     L_var_out = L_mult_o( var1, var2, Overflow );
    1502  1645820364 :     L_var_out = L_add_co( L_var3, L_var_out, Carry, Overflow );
    1503  1645820364 :     return ( L_var_out );
    1504             : }
    1505           0 : Word32 L_macNs( Word32 L_var3, Word16 var1, Word16 var2 )
    1506             : {
    1507           0 :     return L_macNs_co( L_var3, var1, var2, NULL, NULL );
    1508             : }
    1509           0 : Word32 L_macNs_sat( Word32 L_var3, Word16 var1, Word16 var2 )
    1510             : {
    1511             :     Flag Carry, Overflow;
    1512           0 :     return L_macNs_co( L_var3, var1, var2, &Carry, &Overflow );
    1513             : }
    1514             : /*___________________________________________________________________________
    1515             :  |                                                                           |
    1516             :  |   Function Name : L_msuNs                                                 |
    1517             :  |                                                                           |
    1518             :  |   Purpose :                                                               |
    1519             :  |                                                                           |
    1520             :  |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   |
    1521             :  |   bit result from L_var3 without saturation, return a 32 bit result. Ge-  |
    1522             :  |   nerate carry and overflow values :                                      |
    1523             :  |        L_msuNs(L_var3,var1,var2) = L_sub_c(L_var3,L_mult(var1,var2)).     |
    1524             :  |                                                                           |
    1525             :  |   Complexity weight : 1                                                   |
    1526             :  |                                                                           |
    1527             :  |   Inputs :                                                                |
    1528             :  |                                                                           |
    1529             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    1530             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1531             :  |                                                                           |
    1532             :  |    var1                                                                   |
    1533             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1534             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1535             :  |                                                                           |
    1536             :  |    var2                                                                   |
    1537             :  |             16 bit short signed integer (Word16) whose value falls in the |
    1538             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    1539             :  |                                                                           |
    1540             :  |   Outputs :                                                               |
    1541             :  |                                                                           |
    1542             :  |    none                                                                   |
    1543             :  |                                                                           |
    1544             :  |   Return Value :                                                          |
    1545             :  |                                                                           |
    1546             :  |    L_var_out                                                              |
    1547             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1548             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1549             :  |                                                                           |
    1550             :  |   Caution :                                                               |
    1551             :  |                                                                           |
    1552             :  |    In some cases the BASOP_Carry flag has to be cleared or set before using     |
    1553             :  |    operators which take into account its value.                           |
    1554             :  |___________________________________________________________________________|
    1555             : */
    1556           0 : Word32 DEPR_L_msuNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry )
    1557             : {
    1558             :     Word32 L_var_out;
    1559             : 
    1560           0 :     L_var_out = L_mult( var1, var2 );
    1561           0 :     L_var_out = DEPR_L_sub_c( L_var3, L_var_out, Carry );
    1562             : 
    1563             : #ifdef WMOPS
    1564             :     multiCounter[currCounter].L_mult--;
    1565             :     multiCounter[currCounter].L_sub_c--;
    1566             :     multiCounter[currCounter].L_msuNs++;
    1567             : #endif
    1568             : 
    1569             :     /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
    1570             : 
    1571           0 :     return ( L_var_out );
    1572             : }
    1573             : 
    1574           0 : Word32 L_msuNs_co( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry, Flag *Overflow )
    1575             : {
    1576             :     Word32 L_var_out;
    1577             : 
    1578           0 :     L_var_out = L_mult_o( var1, var2, Overflow );
    1579           0 :     L_var_out = L_sub_co( L_var3, L_var_out, Carry, Overflow );
    1580             : 
    1581           0 :     return ( L_var_out );
    1582             : }
    1583             : 
    1584             : 
    1585           0 : Word32 L_msuNs( Word32 L_var3, Word16 var1, Word16 var2 )
    1586             : {
    1587           0 :     return L_msuNs_co( L_var3, var1, var2, NULL, NULL );
    1588             : }
    1589           0 : Word32 L_msuNs_sat( Word32 L_var3, Word16 var1, Word16 var2 )
    1590             : {
    1591             :     Flag Carry, Overflow;
    1592           0 :     return L_msuNs_co( L_var3, var1, var2, &Carry, &Overflow );
    1593             : }
    1594             : /*___________________________________________________________________________
    1595             :  |                                                                           |
    1596             :  |   Function Name : L_add                                                   |
    1597             :  |                                                                           |
    1598             :  |   Purpose :                                                               |
    1599             :  |                                                                           |
    1600             :  |   32 bits addition of the two 32 bits variables (L_var1+L_var2) with      |
    1601             :  |   overflow control and saturation; the result is set at +2147483647 when  |
    1602             :  |   overflow occurs or at -2147483648 when underflow occurs.                |
    1603             :  |                                                                           |
    1604             :  |   Complexity weight : 1                                                   |
    1605             :  |                                                                           |
    1606             :  |   Inputs :                                                                |
    1607             :  |                                                                           |
    1608             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    1609             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1610             :  |                                                                           |
    1611             :  |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |
    1612             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1613             :  |                                                                           |
    1614             :  |   Outputs :                                                               |
    1615             :  |                                                                           |
    1616             :  |    none                                                                   |
    1617             :  |                                                                           |
    1618             :  |   Return Value :                                                          |
    1619             :  |                                                                           |
    1620             :  |    L_var_out                                                              |
    1621             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1622             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1623             :  |___________________________________________________________________________|
    1624             : */
    1625 >10331*10^7 : Word32 L_add_o( Word32 L_var1, Word32 L_var2, Flag *Overflow )
    1626             : {
    1627             :     Word32 L_var_out;
    1628             : 
    1629 >10331*10^7 :     L_var_out = L_var1 + L_var2;
    1630             : 
    1631 >10331*10^7 :     if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) == 0 )
    1632             :     {
    1633 63936765339 :         if ( ( L_var_out ^ L_var1 ) & MIN_32 )
    1634             :         {
    1635    41660992 :             L_var_out = ( L_var1 < 0 ) ? MIN_32 : MAX_32;
    1636    41660992 :             *Overflow = 1;
    1637             :         }
    1638             :     }
    1639             : 
    1640             : #ifdef WMOPS
    1641             :     multiCounter[currCounter].L_add++;
    1642             : #endif
    1643             : 
    1644             :     BASOP_CHECK();
    1645             : 
    1646             : 
    1647 >10331*10^7 :     return ( L_var_out );
    1648             : }
    1649             : 
    1650 >32164*10^7 : Word32 L_add( Word32 L_var1, Word32 L_var2 )
    1651             : {
    1652             :     Word32 L_var_out;
    1653             : 
    1654 >32164*10^7 :     L_var_out = L_var1 + L_var2;
    1655             : 
    1656 >32164*10^7 :     if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) == 0 )
    1657             :     {
    1658 >19745*10^7 :         if ( ( L_var_out ^ L_var1 ) & MIN_32 )
    1659             :         {
    1660           0 :             L_var_out = ( L_var1 < 0 ) ? MIN_32 : MAX_32;
    1661           0 :             assert( 0 );
    1662             :         }
    1663             :     }
    1664             : 
    1665             : #ifdef WMOPS
    1666             :     multiCounter[currCounter].L_add++;
    1667             : #endif
    1668 >32164*10^7 :     return ( L_var_out );
    1669             : }
    1670 13936150197 : Word32 L_add_sat( Word32 L_var1, Word32 L_var2 )
    1671             : {
    1672             :     Flag Overflow;
    1673 13936150197 :     return L_add_o( L_var1, L_var2, &Overflow );
    1674             : }
    1675             : 
    1676             : /*___________________________________________________________________________
    1677             :  |                                                                           |
    1678             :  |   Function Name : L_sub                                                   |
    1679             :  |                                                                           |
    1680             :  |   Purpose :                                                               |
    1681             :  |                                                                           |
    1682             :  |   32 bits subtraction of the two 32 bits variables (L_var1-L_var2) with   |
    1683             :  |   overflow control and saturation; the result is set at +2147483647 when  |
    1684             :  |   overflow occurs or at -2147483648 when underflow occurs.                |
    1685             :  |                                                                           |
    1686             :  |   Complexity weight : 1                                                   |
    1687             :  |                                                                           |
    1688             :  |   Inputs :                                                                |
    1689             :  |                                                                           |
    1690             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    1691             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1692             :  |                                                                           |
    1693             :  |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |
    1694             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1695             :  |                                                                           |
    1696             :  |   Outputs :                                                               |
    1697             :  |                                                                           |
    1698             :  |    none                                                                   |
    1699             :  |                                                                           |
    1700             :  |   Return Value :                                                          |
    1701             :  |                                                                           |
    1702             :  |    L_var_out                                                              |
    1703             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1704             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1705             :  |___________________________________________________________________________|
    1706             : */
    1707 49587599283 : Word32 L_sub_o( Word32 L_var1, Word32 L_var2, Flag *Overflow )
    1708             : {
    1709             :     Word32 L_var_out;
    1710             : 
    1711 49587599283 :     L_var_out = L_var1 - L_var2;
    1712             : 
    1713 49587599283 :     if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) != 0 )
    1714             :     {
    1715 18669863497 :         if ( ( L_var_out ^ L_var1 ) & MIN_32 )
    1716             :         {
    1717    32425150 :             L_var_out = ( L_var1 < 0L ) ? MIN_32 : MAX_32;
    1718    32425150 :             *Overflow = 1;
    1719             :         }
    1720             :     }
    1721             : 
    1722             : #ifdef WMOPS
    1723             :     multiCounter[currCounter].L_sub++;
    1724             : #endif
    1725             : 
    1726             :     BASOP_CHECK();
    1727             : 
    1728 49587599283 :     return ( L_var_out );
    1729             : }
    1730             : 
    1731 >14890*10^7 : Word32 L_sub( Word32 L_var1, Word32 L_var2 )
    1732             : {
    1733             :     Word32 L_var_out;
    1734             : 
    1735 >14890*10^7 :     L_var_out = L_var1 - L_var2;
    1736             : 
    1737 >14890*10^7 :     if ( ( ( L_var1 ^ L_var2 ) & MIN_32 ) != 0 )
    1738             :     {
    1739 53745059347 :         if ( ( L_var_out ^ L_var1 ) & MIN_32 )
    1740             :         {
    1741           0 :             L_var_out = ( L_var1 < 0L ) ? MIN_32 : MAX_32;
    1742           0 :             assert( 0 );
    1743             :         }
    1744             :     }
    1745             : 
    1746             : #ifdef WMOPS
    1747             :     multiCounter[currCounter].L_sub++;
    1748             : #endif
    1749             :     BASOP_CHECK();
    1750             : 
    1751 >14890*10^7 :     return ( L_var_out );
    1752             : }
    1753  1978204386 : Word32 L_sub_sat( Word32 L_var1, Word32 L_var2 )
    1754             : {
    1755             :     Flag Overflow;
    1756  1978204386 :     return L_sub_o( L_var1, L_var2, &Overflow );
    1757             : }
    1758             : 
    1759             : /*___________________________________________________________________________
    1760             :  |                                                                           |
    1761             :  |   Function Name : L_add_c                                                 |
    1762             :  |                                                                           |
    1763             :  |   Purpose :                                                               |
    1764             :  |                                                                           |
    1765             :  |   Performs 32 bits addition of the two 32 bits variables (L_var1+L_var2+C)|
    1766             :  |   with carry. No saturation. Generate carry and BASOP_Overflow values. The car- |
    1767             :  |   ry and overflow values are binary variables which can be tested and as- |
    1768             :  |   signed values.                                                          |
    1769             :  |                                                                           |
    1770             :  |   Complexity weight : 2                                                   |
    1771             :  |                                                                           |
    1772             :  |   Inputs :                                                                |
    1773             :  |                                                                           |
    1774             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    1775             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1776             :  |                                                                           |
    1777             :  |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |
    1778             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1779             :  |                                                                           |
    1780             :  |   Outputs :                                                               |
    1781             :  |                                                                           |
    1782             :  |    none                                                                   |
    1783             :  |                                                                           |
    1784             :  |   Return Value :                                                          |
    1785             :  |                                                                           |
    1786             :  |    L_var_out                                                              |
    1787             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1788             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1789             :  |                                                                           |
    1790             :  |   Caution :                                                               |
    1791             :  |                                                                           |
    1792             :  |    In some cases the BASOP_Carry flag has to be cleared or set before using     |
    1793             :  |    operators which take into account its value.                           |
    1794             :  |___________________________________________________________________________|
    1795             : */
    1796           0 : Word32 L_add_c( Word32 L_var1, Word32 L_var2, Flag *Carry )
    1797             : {
    1798             :     Word32 L_var_out;
    1799             :     Word32 L_test;
    1800           0 :     Flag carry_int = 0;
    1801             : 
    1802           0 :     L_var_out = L_var1 + L_var2 + *Carry;
    1803             : 
    1804           0 :     L_test = L_var1 + L_var2;
    1805             : 
    1806           0 :     if ( ( L_var1 > 0 ) && ( L_var2 > 0 ) && ( L_test < 0 ) )
    1807             :     {
    1808           0 :         carry_int = 0;
    1809             :     }
    1810             :     else
    1811             :     {
    1812           0 :         if ( ( L_var1 < 0 ) && ( L_var2 < 0 ) )
    1813             :         {
    1814           0 :             if ( L_test >= 0 )
    1815             :             {
    1816           0 :                 carry_int = 1;
    1817             :             }
    1818             :             else
    1819             :             {
    1820           0 :                 carry_int = 1;
    1821             :             }
    1822             :         }
    1823             :         else
    1824             :         {
    1825           0 :             if ( ( ( L_var1 ^ L_var2 ) < 0 ) && ( L_test >= 0 ) )
    1826             :             {
    1827           0 :                 carry_int = 1;
    1828             :             }
    1829             :             else
    1830             :             {
    1831           0 :                 carry_int = 0;
    1832             :             }
    1833             :         }
    1834             :     }
    1835             : 
    1836           0 :     if ( *Carry )
    1837             :     {
    1838           0 :         if ( L_test == MAX_32 )
    1839             :         {
    1840           0 :             *Carry = carry_int;
    1841             :         }
    1842             :         else
    1843             :         {
    1844           0 :             if ( L_test == (Word32) 0xFFFFFFFFL )
    1845             :             {
    1846           0 :                 *Carry = 1;
    1847             :             }
    1848             :             else
    1849             :             {
    1850           0 :                 *Carry = carry_int;
    1851             :             }
    1852             :         }
    1853             :     }
    1854             :     else
    1855             :     {
    1856           0 :         *Carry = carry_int;
    1857             :     }
    1858             : 
    1859             : #ifdef WMOPS
    1860             :     multiCounter[currCounter].L_add_c++;
    1861             : #endif
    1862             : 
    1863             :     /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
    1864             : 
    1865             : 
    1866           0 :     return ( L_var_out );
    1867             : }
    1868  2031610048 : Word32 L_add_co( Word32 L_var1, Word32 L_var2, Flag *Carry, Flag *Overflow )
    1869             : {
    1870             :     Word32 L_var_out;
    1871             :     Word32 L_test;
    1872  2031610048 :     Flag carry_int = 0;
    1873             : 
    1874  2031610048 :     L_var_out = L_var1 + L_var2 + get_carry( Carry );
    1875             : 
    1876  2031610048 :     L_test = L_var1 + L_var2;
    1877             : 
    1878  2031610048 :     if ( ( L_var1 > 0 ) && ( L_var2 > 0 ) && ( L_test < 0 ) )
    1879             :     {
    1880     7767651 :         set_overflow( Overflow );
    1881     7767651 :         carry_int = 0;
    1882             :     }
    1883             :     else
    1884             :     {
    1885  2023842397 :         if ( ( L_var1 < 0 ) && ( L_var2 < 0 ) )
    1886             :         {
    1887     1970954 :             if ( L_test >= 0 )
    1888             :             {
    1889     1115807 :                 set_overflow( Overflow );
    1890     1115807 :                 carry_int = 1;
    1891             :             }
    1892             :             else
    1893             :             {
    1894      855147 :                 unset_overflow( Overflow );
    1895      855147 :                 carry_int = 1;
    1896             :             }
    1897             :         }
    1898             :         else
    1899             :         {
    1900  2021871443 :             if ( ( ( L_var1 ^ L_var2 ) < 0 ) && ( L_test >= 0 ) )
    1901             :             {
    1902     4283283 :                 unset_overflow( Overflow );
    1903     4283283 :                 carry_int = 1;
    1904             :             }
    1905             :             else
    1906             :             {
    1907  2017588160 :                 unset_overflow( Overflow );
    1908  2017588160 :                 carry_int = 0;
    1909             :             }
    1910             :         }
    1911             :     }
    1912             : 
    1913  2031610048 :     if ( get_carry( Carry ) )
    1914             :     {
    1915     6254237 :         if ( L_test == MAX_32 )
    1916             :         {
    1917           0 :             set_overflow( Overflow );
    1918           0 :             carry_int ? set_carry( Carry ) : unset_carry( Carry );
    1919             :         }
    1920             :         else
    1921             :         {
    1922     6254237 :             if ( L_test == (Word32) 0xFFFFFFFFL )
    1923             :             {
    1924           0 :                 set_carry( Carry );
    1925             :             }
    1926             :             else
    1927             :             {
    1928     6254237 :                 carry_int ? set_carry( Carry ) : unset_carry( Carry );
    1929             :             }
    1930             :         }
    1931             :     }
    1932             :     else
    1933             :     {
    1934  2025355811 :         carry_int ? set_carry( Carry ) : unset_carry( Carry );
    1935             :     }
    1936             : 
    1937             : #ifdef WMOPS
    1938             :     multiCounter[currCounter].L_add_c++;
    1939             : #endif
    1940  2031610048 :     return ( L_var_out );
    1941             : }
    1942             : 
    1943             : /*___________________________________________________________________________
    1944             :  |                                                                           |
    1945             :  |   Function Name : L_sub_c                                                 |
    1946             :  |                                                                           |
    1947             :  |   Purpose :                                                               |
    1948             :  |                                                                           |
    1949             :  |   Performs 32 bits subtraction of the two 32 bits variables with carry    |
    1950             :  |   (borrow) : L_var1-L_var2-C. No saturation. Generate carry and BASOP_Overflow  |
    1951             :  |   values. The carry and overflow values are binary variables which can    |
    1952             :  |   be tested and assigned values.                                          |
    1953             :  |                                                                           |
    1954             :  |   Complexity weight : 2                                                   |
    1955             :  |                                                                           |
    1956             :  |   Inputs :                                                                |
    1957             :  |                                                                           |
    1958             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    1959             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1960             :  |                                                                           |
    1961             :  |    L_var2   32 bit long signed integer (Word32) whose value falls in the  |
    1962             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    1963             :  |                                                                           |
    1964             :  |   Outputs :                                                               |
    1965             :  |                                                                           |
    1966             :  |    none                                                                   |
    1967             :  |                                                                           |
    1968             :  |   Return Value :                                                          |
    1969             :  |                                                                           |
    1970             :  |    L_var_out                                                              |
    1971             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    1972             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    1973             :  |                                                                           |
    1974             :  |   Caution :                                                               |
    1975             :  |                                                                           |
    1976             :  |    In some cases the BASOP_Carry flag has to be cleared or set before using     |
    1977             :  |    operators which take into account its value.                           |
    1978             :  |___________________________________________________________________________|
    1979             : */
    1980           0 : Word32 DEPR_L_sub_c( Word32 L_var1, Word32 L_var2, Flag *Carry )
    1981             : {
    1982             :     Word32 L_var_out;
    1983             :     Word32 L_test;
    1984           0 :     Flag carry_int = 0;
    1985             : 
    1986           0 :     if ( *Carry )
    1987             :     {
    1988           0 :         *Carry = 0;
    1989           0 :         if ( L_var2 != MIN_32 )
    1990             :         {
    1991           0 :             L_var_out = L_add_c( L_var1, -L_var2, Carry );
    1992             : #ifdef WMOPS
    1993             :             multiCounter[currCounter].L_add_c--;
    1994             : #endif
    1995             :         }
    1996             :         else
    1997             :         {
    1998           0 :             L_var_out = L_var1 - L_var2;
    1999           0 :             if ( L_var1 > 0L )
    2000             :             {
    2001           0 :                 *Carry = 0;
    2002             :             }
    2003             :         }
    2004             :     }
    2005             :     else
    2006             :     {
    2007           0 :         L_var_out = L_var1 - L_var2 - (Word32) 0X00000001L;
    2008           0 :         L_test = L_var1 - L_var2;
    2009             : 
    2010           0 :         if ( ( L_test < 0 ) && ( L_var1 > 0 ) && ( L_var2 < 0 ) )
    2011             :         {
    2012           0 :             carry_int = 0;
    2013             :         }
    2014           0 :         else if ( ( L_test > 0 ) && ( L_var1 < 0 ) && ( L_var2 > 0 ) )
    2015             :         {
    2016           0 :             carry_int = 1;
    2017             :         }
    2018           0 :         else if ( ( L_test > 0 ) && ( ( L_var1 ^ L_var2 ) > 0 ) )
    2019             :         {
    2020           0 :             carry_int = 1;
    2021             :         }
    2022           0 :         if ( L_test == MIN_32 )
    2023             :         {
    2024           0 :             *Carry = carry_int;
    2025             :         }
    2026             :         else
    2027             :         {
    2028           0 :             *Carry = carry_int;
    2029             :         }
    2030             :     }
    2031             : 
    2032             : #ifdef WMOPS
    2033             :     multiCounter[currCounter].L_sub_c++;
    2034             : #endif
    2035             : 
    2036             :     /* BASOP_CHECK(); Do not check for overflow here, function produces the carry bit instead */
    2037             : 
    2038             : 
    2039           0 :     return ( L_var_out );
    2040             : }
    2041             : 
    2042           0 : Word32 L_sub_co( Word32 L_var1, Word32 L_var2, Flag *Carry, Flag *Overflow )
    2043             : {
    2044             :     Word32 L_var_out;
    2045             :     Word32 L_test;
    2046           0 :     Flag carry_int = 0;
    2047             : 
    2048           0 :     if ( get_carry( Carry ) )
    2049             :     {
    2050           0 :         unset_carry( Carry );
    2051           0 :         if ( L_var2 != MIN_32 )
    2052             :         {
    2053           0 :             L_var_out = L_add_co( L_var1, -L_var2, Carry, Overflow );
    2054             :         }
    2055             :         else
    2056             :         {
    2057           0 :             L_var_out = L_var1 - L_var2;
    2058           0 :             if ( L_var1 > 0L )
    2059             :             {
    2060           0 :                 set_overflow( Overflow );
    2061           0 :                 unset_carry( Carry );
    2062             :             }
    2063             :         }
    2064             :     }
    2065             :     else
    2066             :     {
    2067           0 :         L_var_out = L_var1 - L_var2 - (Word32) 0X00000001L;
    2068           0 :         L_test = L_var1 - L_var2;
    2069             : 
    2070           0 :         if ( ( L_test < 0 ) && ( L_var1 > 0 ) && ( L_var2 < 0 ) )
    2071             :         {
    2072           0 :             set_overflow( Overflow );
    2073           0 :             carry_int = 0;
    2074             :         }
    2075           0 :         else if ( ( L_test > 0 ) && ( L_var1 < 0 ) && ( L_var2 > 0 ) )
    2076             :         {
    2077           0 :             set_overflow( Overflow );
    2078           0 :             carry_int = 1;
    2079             :         }
    2080           0 :         else if ( ( L_test > 0 ) && ( ( L_var1 ^ L_var2 ) > 0 ) )
    2081             :         {
    2082           0 :             unset_overflow( Overflow );
    2083           0 :             carry_int = 1;
    2084             :         }
    2085           0 :         if ( L_test == MIN_32 )
    2086             :         {
    2087           0 :             set_overflow( Overflow );
    2088           0 :             carry_int ? set_carry( Carry ) : unset_carry( Carry );
    2089             :         }
    2090             :         else
    2091             :         {
    2092           0 :             carry_int ? set_carry( Carry ) : unset_carry( Carry );
    2093             :         }
    2094             :     }
    2095             : 
    2096           0 :     return ( L_var_out );
    2097             : }
    2098           0 : Word32 L_sub_c( Word32 L_var1, Word32 L_var2 )
    2099             : {
    2100           0 :     return L_sub_co( L_var1, L_var2, NULL, NULL );
    2101             : }
    2102             : /*___________________________________________________________________________
    2103             :  |                                                                           |
    2104             :  |   Function Name : L_negate                                                |
    2105             :  |                                                                           |
    2106             :  |   Purpose :                                                               |
    2107             :  |                                                                           |
    2108             :  |   Negate the 32 bit variable L_var1 with saturation; saturate in the case |
    2109             :  |   where input is -2147483648 (0x8000 0000).                               |
    2110             :  |                                                                           |
    2111             :  |   Complexity weight : 1                                                   |
    2112             :  |                                                                           |
    2113             :  |   Inputs :                                                                |
    2114             :  |                                                                           |
    2115             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    2116             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    2117             :  |                                                                           |
    2118             :  |   Outputs :                                                               |
    2119             :  |                                                                           |
    2120             :  |    none                                                                   |
    2121             :  |                                                                           |
    2122             :  |   Return Value :                                                          |
    2123             :  |                                                                           |
    2124             :  |    L_var_out                                                              |
    2125             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2126             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    2127             :  |___________________________________________________________________________|
    2128             : */
    2129 23887164879 : Word32 L_negate( Word32 L_var1 )
    2130             : {
    2131             :     Word32 L_var_out;
    2132             : 
    2133 23887164879 :     L_var_out = ( L_var1 == MIN_32 ) ? MAX_32 : -L_var1;
    2134             : 
    2135             : 
    2136             : #ifdef WMOPS
    2137             :     multiCounter[currCounter].L_negate++;
    2138             : #endif
    2139             : 
    2140             :     BASOP_CHECK();
    2141             : 
    2142 23887164879 :     return ( L_var_out );
    2143             : }
    2144             : 
    2145             : 
    2146             : /*___________________________________________________________________________
    2147             :  |                                                                           |
    2148             :  |   Function Name : mult_r                                                  |
    2149             :  |                                                                           |
    2150             :  |   Purpose :                                                               |
    2151             :  |                                                                           |
    2152             :  |   Same as mult with rounding, i.e.:                                       |
    2153             :  |     mult_r(var1,var2) = extract_l(L_shr(((var1 * var2) + 16384),15)) and  |
    2154             :  |     mult_r(-32768,-32768) = 32767.                                        |
    2155             :  |                                                                           |
    2156             :  |   Complexity weight : 1                                                   |
    2157             :  |                                                                           |
    2158             :  |   Inputs :                                                                |
    2159             :  |                                                                           |
    2160             :  |    var1                                                                   |
    2161             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2162             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2163             :  |                                                                           |
    2164             :  |    var2                                                                   |
    2165             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2166             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2167             :  |                                                                           |
    2168             :  |   Outputs :                                                               |
    2169             :  |                                                                           |
    2170             :  |    none                                                                   |
    2171             :  |                                                                           |
    2172             :  |   Return Value :                                                          |
    2173             :  |                                                                           |
    2174             :  |    var_out                                                                |
    2175             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2176             :  |             range : 0x8000 <= var_out <= 0x7fff.                          |
    2177             :  |___________________________________________________________________________|
    2178             : */
    2179   253754367 : Word16 mult_ro( Word16 var1, Word16 var2, Flag *Overflow )
    2180             : {
    2181             :     Word16 var_out;
    2182             :     Word32 L_product_arr;
    2183             : 
    2184   253754367 :     L_product_arr = (Word32) var1 * (Word32) var2; /* product */
    2185   253754367 :     L_product_arr += (Word32) 0x00004000L;         /* round */
    2186   253754367 :     L_product_arr &= (Word32) 0xffff8000L;
    2187   253754367 :     L_product_arr >>= 15; /* shift */
    2188             : 
    2189   253754367 :     if ( L_product_arr & (Word32) 0x00010000L ) /* sign extend when necessary */
    2190             :     {
    2191    84052109 :         L_product_arr |= (Word32) 0xffff0000L;
    2192             :     }
    2193   253754367 :     var_out = saturate_o( L_product_arr, Overflow );
    2194             : 
    2195             : #ifdef WMOPS
    2196             :     multiCounter[currCounter].mult_r++;
    2197             : #endif
    2198             : 
    2199   253754367 :     return ( var_out );
    2200             : }
    2201             : 
    2202  8950137510 : Word16 mult_r( Word16 var1, Word16 var2 )
    2203             : {
    2204             :     Word16 var_out;
    2205             :     Word32 L_product_arr;
    2206             : 
    2207  8950137510 :     L_product_arr = (Word32) var1 * (Word32) var2; /* product */
    2208  8950137510 :     L_product_arr += (Word32) 0x00004000L;         /* round */
    2209  8950137510 :     L_product_arr &= (Word32) 0xffff8000L;
    2210  8950137510 :     L_product_arr >>= 15; /* shift */
    2211             : 
    2212  8950137510 :     if ( L_product_arr & (Word32) 0x00010000L ) /* sign extend when necessary */
    2213             :     {
    2214  2540426925 :         L_product_arr |= (Word32) 0xffff0000L;
    2215             :     }
    2216  8950137510 :     var_out = saturate( L_product_arr );
    2217             : 
    2218             : #ifdef WMOPS
    2219             :     multiCounter[currCounter].mult_r++;
    2220             : #endif
    2221  8950137510 :     return ( var_out );
    2222             : }
    2223             : 
    2224    47705293 : Word16 mult_r_sat( Word16 var1, Word16 var2 )
    2225             : {
    2226             :     Flag Overflow;
    2227    47705293 :     return mult_ro( var1, var2, &Overflow );
    2228             : }
    2229             : /*___________________________________________________________________________
    2230             :  |                                                                           |
    2231             :  |   Function Name : L_shl                                                   |
    2232             :  |                                                                           |
    2233             :  |   Purpose :                                                               |
    2234             :  |                                                                           |
    2235             :  |   Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero  |
    2236             :  |   fill the var2 LSB of the result. If var2 is negative, arithmetically    |
    2237             :  |   shift L_var1 right by -var2 with sign extension. Saturate the result in |
    2238             :  |   case of underflows or overflows.                                        |
    2239             :  |                                                                           |
    2240             :  |   Complexity weight : 1                                                   |
    2241             :  |                                                                           |
    2242             :  |   Inputs :                                                                |
    2243             :  |                                                                           |
    2244             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    2245             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    2246             :  |                                                                           |
    2247             :  |    var2                                                                   |
    2248             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2249             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2250             :  |                                                                           |
    2251             :  |   Outputs :                                                               |
    2252             :  |                                                                           |
    2253             :  |    none                                                                   |
    2254             :  |                                                                           |
    2255             :  |   Return Value :                                                          |
    2256             :  |                                                                           |
    2257             :  |    L_var_out                                                              |
    2258             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2259             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    2260             :  |___________________________________________________________________________|
    2261             : */
    2262 55688396054 : Word32 L_shl_o( Word32 L_var1, Word16 var2, Flag *Overflow )
    2263             : {
    2264             : 
    2265 55688396054 :     Word32 L_var_out = 0L;
    2266             : 
    2267 55688396054 :     if ( var2 <= 0 )
    2268             :     {
    2269 18662255021 :         if ( var2 < -32 )
    2270    62204114 :             var2 = -32;
    2271 18662255021 :         var2 = -var2;
    2272 18662255021 :         L_var_out = L_shr( L_var1, var2 );
    2273             : #ifdef WMOPS
    2274             :         multiCounter[currCounter].L_shr--;
    2275             : #endif
    2276             :     }
    2277             :     else
    2278             :     {
    2279 >25564*10^7 :         for ( ; var2 > 0; var2-- )
    2280             :         {
    2281 >21887*10^7 :             if ( L_var1 > (Word32) 0X3fffffffL )
    2282             :             {
    2283   236766378 :                 *Overflow = 1;
    2284   236766378 :                 L_var_out = MAX_32;
    2285   236766378 :                 break;
    2286             :             }
    2287             :             else
    2288             :             {
    2289 >21864*10^7 :                 if ( L_var1 < (Word32) 0xc0000000L )
    2290             :                 {
    2291    20939973 :                     *Overflow = 1;
    2292    20939973 :                     L_var_out = MIN_32;
    2293    20939973 :                     break;
    2294             :                 }
    2295             :             }
    2296 >21862*10^7 :             L_var1 *= 2;
    2297 >21862*10^7 :             L_var_out = L_var1;
    2298             :         }
    2299             :     }
    2300             : 
    2301             : #ifdef WMOPS
    2302             :     multiCounter[currCounter].L_shl++;
    2303             : #endif
    2304             : 
    2305             :     BASOP_CHECK();
    2306             : 
    2307             : 
    2308 55688396054 :     return ( L_var_out );
    2309             : }
    2310             : 
    2311 >12951*10^7 : Word32 L_shl( Word32 L_var1, Word16 var2 )
    2312             : {
    2313             : 
    2314 >12951*10^7 :     Word32 L_var_out = 0L;
    2315             : 
    2316 >12951*10^7 :     if ( var2 <= 0 )
    2317             :     {
    2318 38856548360 :         if ( var2 < -32 )
    2319   102699267 :             var2 = -32;
    2320 38856548360 :         var2 = -var2;
    2321 38856548360 :         L_var_out = L_shr( L_var1, var2 );
    2322             : #ifdef WMOPS
    2323             :         multiCounter[currCounter].L_shr--;
    2324             : #endif
    2325             :     }
    2326             :     else
    2327             :     {
    2328 >71630*10^7 :         for ( ; var2 > 0; var2-- )
    2329             :         {
    2330 >62564*10^7 :             if ( L_var1 > (Word32) 0X3fffffffL )
    2331             :             {
    2332           0 :                 assert( 0 );
    2333             :                 L_var_out = MAX_32;
    2334             :                 break;
    2335             :             }
    2336             :             else
    2337             :             {
    2338 >62564*10^7 :                 if ( L_var1 < (Word32) 0xc0000000L )
    2339             :                 {
    2340           0 :                     assert( 0 );
    2341             :                     L_var_out = MIN_32;
    2342             :                     break;
    2343             :                 }
    2344             :             }
    2345 >62564*10^7 :             L_var1 *= 2;
    2346 >62564*10^7 :             L_var_out = L_var1;
    2347             :         }
    2348             :     }
    2349             : 
    2350             : #ifdef WMOPS
    2351             :     multiCounter[currCounter].L_shl++;
    2352             : #endif
    2353             :     BASOP_CHECK();
    2354             : 
    2355             : 
    2356 >12951*10^7 :     return ( L_var_out );
    2357             : }
    2358             : 
    2359 13318747114 : Word32 L_shl_sat( Word32 L_var1, Word16 var2 )
    2360             : {
    2361             :     Flag Overflow;
    2362 13318747114 :     return L_shl_o( L_var1, var2, &Overflow );
    2363             : }
    2364             : 
    2365             : /*___________________________________________________________________________
    2366             :  |                                                                           |
    2367             :  |   Function Name : L_shr                                                   |
    2368             :  |                                                                           |
    2369             :  |   Purpose :                                                               |
    2370             :  |                                                                           |
    2371             :  |   Arithmetically shift the 32 bit input L_var1 right var2 positions with  |
    2372             :  |   sign extension. If var2 is negative, arithmetically shift L_var1 left   |
    2373             :  |   by -var2 and zero fill the -var2 LSB of the result. Saturate the result |
    2374             :  |   in case of underflows or overflows.                                     |
    2375             :  |                                                                           |
    2376             :  |   Complexity weight : 1                                                   |
    2377             :  |                                                                           |
    2378             :  |   Inputs :                                                                |
    2379             :  |                                                                           |
    2380             :  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  |
    2381             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    2382             :  |                                                                           |
    2383             :  |    var2                                                                   |
    2384             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2385             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2386             :  |                                                                           |
    2387             :  |   Outputs :                                                               |
    2388             :  |                                                                           |
    2389             :  |    none                                                                   |
    2390             :  |                                                                           |
    2391             :  |   Return Value :                                                          |
    2392             :  |                                                                           |
    2393             :  |    L_var_out                                                              |
    2394             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2395             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              |
    2396             :  |___________________________________________________________________________|
    2397             : */
    2398   632939971 : Word32 L_shr_o( Word32 L_var1, Word16 var2, Flag *Overflow )
    2399             : {
    2400             :     Word32 L_var_out;
    2401             : 
    2402   632939971 :     if ( var2 < 0 )
    2403             :     {
    2404   156153120 :         if ( var2 < -32 )
    2405       29776 :             var2 = -32;
    2406   156153120 :         var2 = -var2;
    2407   156153120 :         L_var_out = L_shl_o( L_var1, var2, Overflow );
    2408             : #ifdef WMOPS
    2409             :         multiCounter[currCounter].L_shl--;
    2410             : #endif
    2411             :     }
    2412             :     else
    2413             :     {
    2414   476786851 :         if ( var2 >= 31 )
    2415             :         {
    2416     3838940 :             L_var_out = ( L_var1 < 0L ) ? -1 : 0;
    2417             :         }
    2418             :         else
    2419             :         {
    2420   472947911 :             if ( L_var1 < 0 )
    2421             :             {
    2422   116418753 :                 L_var_out = ~( ( ~L_var1 ) >> var2 );
    2423             :             }
    2424             :             else
    2425             :             {
    2426   356529158 :                 L_var_out = L_var1 >> var2;
    2427             :             }
    2428             :         }
    2429             :     }
    2430             : 
    2431             : #ifdef WMOPS
    2432             :     multiCounter[currCounter].L_shr++;
    2433             : #endif
    2434             : 
    2435             :     BASOP_CHECK();
    2436             : 
    2437             : 
    2438   632939971 :     return ( L_var_out );
    2439             : }
    2440             : 
    2441 >16336*10^7 : Word32 L_shr( Word32 L_var1, Word16 var2 )
    2442             : {
    2443             :     Word32 L_var_out;
    2444             : 
    2445 >16336*10^7 :     if ( var2 < 0 )
    2446             :     {
    2447   840186605 :         if ( var2 < -32 )
    2448    32028665 :             var2 = -32;
    2449   840186605 :         var2 = -var2;
    2450   840186605 :         L_var_out = L_shl( L_var1, var2 );
    2451             : #ifdef WMOPS
    2452             :         multiCounter[currCounter].L_shl--;
    2453             : #endif
    2454             :     }
    2455             :     else
    2456             :     {
    2457 >16252*10^7 :         if ( var2 >= 31 )
    2458             :         {
    2459  1630232612 :             L_var_out = ( L_var1 < 0L ) ? -1 : 0;
    2460             :         }
    2461             :         else
    2462             :         {
    2463 >16089*10^7 :             if ( L_var1 < 0 )
    2464             :             {
    2465 48128794361 :                 L_var_out = ~( ( ~L_var1 ) >> var2 );
    2466             :             }
    2467             :             else
    2468             :             {
    2469 >11276*10^7 :                 L_var_out = L_var1 >> var2;
    2470             :             }
    2471             :         }
    2472             :     }
    2473             : 
    2474             : #ifdef WMOPS
    2475             :     multiCounter[currCounter].L_shr++;
    2476             : #endif
    2477             :     BASOP_CHECK();
    2478             : 
    2479             : 
    2480 >16336*10^7 :     return ( L_var_out );
    2481             : }
    2482   198803470 : Word32 L_shr_sat( Word32 L_var1, Word16 var2 )
    2483             : {
    2484             :     Flag Overflow;
    2485   198803470 :     return L_shr_o( L_var1, var2, &Overflow );
    2486             : }
    2487             : /*___________________________________________________________________________
    2488             :  |                                                                           |
    2489             :  |   Function Name : shr_r                                                   |
    2490             :  |                                                                           |
    2491             :  |   Purpose :                                                               |
    2492             :  |                                                                           |
    2493             :  |   Same as shr(var1,var2) but with rounding. Saturate the result in case of|
    2494             :  |   underflows or overflows :                                               |
    2495             :  |    - If var2 is greater than zero :                                       |
    2496             :  |          if (sub(shl(shr(var1,var2),1),shr(var1,sub(var2,1))))            |
    2497             :  |          is equal to zero                                                 |
    2498             :  |                     then                                                  |
    2499             :  |                     shr_r(var1,var2) = shr(var1,var2)                     |
    2500             :  |                     else                                                  |
    2501             :  |                     shr_r(var1,var2) = add(shr(var1,var2),1)              |
    2502             :  |    - If var2 is less than or equal to zero :                              |
    2503             :  |                     shr_r(var1,var2) = shr(var1,var2).                    |
    2504             :  |                                                                           |
    2505             :  |   Complexity weight : 3                                                   |
    2506             :  |                                                                           |
    2507             :  |   Inputs :                                                                |
    2508             :  |                                                                           |
    2509             :  |    var1                                                                   |
    2510             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2511             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2512             :  |                                                                           |
    2513             :  |    var2                                                                   |
    2514             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2515             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2516             :  |                                                                           |
    2517             :  |   Outputs :                                                               |
    2518             :  |                                                                           |
    2519             :  |    none                                                                   |
    2520             :  |                                                                           |
    2521             :  |   Return Value :                                                          |
    2522             :  |                                                                           |
    2523             :  |    var_out                                                                |
    2524             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2525             :  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                |
    2526             :  |___________________________________________________________________________|
    2527             : */
    2528    36028145 : Word16 shr_r( Word16 var1, Word16 var2 )
    2529             : {
    2530             :     Word16 var_out;
    2531             : 
    2532    36028145 :     if ( var2 > 15 )
    2533             :     {
    2534          65 :         var_out = 0;
    2535             :     }
    2536             :     else
    2537             :     {
    2538    36028080 :         var_out = shr( var1, var2 );
    2539             : 
    2540             : #ifdef WMOPS
    2541             :         multiCounter[currCounter].shr--;
    2542             : #endif
    2543    36028080 :         if ( var2 > 0 )
    2544             :         {
    2545    34354896 :             if ( ( var1 & ( (Word16) 1 << ( var2 - 1 ) ) ) != 0 )
    2546             :             {
    2547    27753142 :                 var_out++;
    2548             :             }
    2549             :         }
    2550             :     }
    2551             : 
    2552             : #ifdef WMOPS
    2553             :     multiCounter[currCounter].shr_r++;
    2554             : #endif
    2555             : 
    2556             :     BASOP_CHECK();
    2557             : 
    2558    36028145 :     return ( var_out );
    2559             : }
    2560     2203800 : Word16 shr_ro( Word16 var1, Word16 var2, Flag *Overflow )
    2561             : {
    2562             :     Word16 var_out;
    2563             : 
    2564     2203800 :     if ( var2 > 15 )
    2565             :     {
    2566        5621 :         var_out = 0;
    2567             :     }
    2568             :     else
    2569             :     {
    2570     2198179 :         var_out = shr_o( var1, var2, Overflow );
    2571             : 
    2572             : #ifdef WMOPS
    2573             :         multiCounter[currCounter].shr--;
    2574             : #endif
    2575     2198179 :         if ( var2 > 0 )
    2576             :         {
    2577     1757271 :             if ( ( var1 & ( (Word16) 1 << ( var2 - 1 ) ) ) != 0 )
    2578             :             {
    2579      811131 :                 var_out++;
    2580             :             }
    2581             :         }
    2582             :     }
    2583             : 
    2584             : #ifdef WMOPS
    2585             :     multiCounter[currCounter].shr_r++;
    2586             : #endif
    2587             : 
    2588             :     BASOP_CHECK();
    2589             : 
    2590     2203800 :     return ( var_out );
    2591             : }
    2592      260608 : Word16 shr_r_sat( Word16 var1, Word16 var2 )
    2593             : {
    2594             :     Flag Overflow;
    2595      260608 :     return shr_ro( var1, var2, &Overflow );
    2596             : }
    2597             : /*___________________________________________________________________________
    2598             :  |                                                                           |
    2599             :  |   Function Name : mac_r                                                   |
    2600             :  |                                                                           |
    2601             :  |   Purpose :                                                               |
    2602             :  |                                                                           |
    2603             :  |   Multiply var1 by var2 and shift the result left by 1. Add the 32 bit    |
    2604             :  |   result to L_var3 with saturation. Round the LS 16 bits of the result    |
    2605             :  |   into the MS 16 bits with saturation and shift the result right by 16.   |
    2606             :  |   Return a 16 bit result.                                                 |
    2607             :  |            mac_r(L_var3,var1,var2) = round_fx(L_mac(L_var3,var1,var2))    |
    2608             :  |                                                                           |
    2609             :  |   Complexity weight : 1                                                   |
    2610             :  |                                                                           |
    2611             :  |   Inputs :                                                                |
    2612             :  |                                                                           |
    2613             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    2614             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    2615             :  |                                                                           |
    2616             :  |    var1                                                                   |
    2617             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2618             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2619             :  |                                                                           |
    2620             :  |    var2                                                                   |
    2621             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2622             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2623             :  |                                                                           |
    2624             :  |   Outputs :                                                               |
    2625             :  |                                                                           |
    2626             :  |    none                                                                   |
    2627             :  |                                                                           |
    2628             :  |   Return Value :                                                          |
    2629             :  |                                                                           |
    2630             :  |    var_out                                                                |
    2631             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2632             :  |             range : 0x0000 8000 <= L_var_out <= 0x0000 7fff.              |
    2633             :  |___________________________________________________________________________|
    2634             : */
    2635  3591029512 : Word16 mac_ro( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    2636             : {
    2637             :     Word16 var_out;
    2638             : 
    2639  3591029512 :     L_var3 = L_mac_o( L_var3, var1, var2, Overflow );
    2640  3591029512 :     L_var3 = L_add_o( L_var3, (Word32) 0x00008000L, Overflow );
    2641  3591029512 :     var_out = extract_h( L_var3 );
    2642             : 
    2643             : #ifdef WMOPS
    2644             :     multiCounter[currCounter].L_mac--;
    2645             :     multiCounter[currCounter].L_add--;
    2646             :     multiCounter[currCounter].extract_h--;
    2647             :     multiCounter[currCounter].mac_r++;
    2648             : #endif
    2649             : 
    2650             :     BASOP_CHECK();
    2651             : 
    2652             : 
    2653  3591029512 :     return ( var_out );
    2654             : }
    2655             : 
    2656  2396327463 : Word16 mac_r( Word32 L_var3, Word16 var1, Word16 var2 )
    2657             : {
    2658             :     Word16 var_out;
    2659             : 
    2660  2396327463 :     L_var3 = L_mac( L_var3, var1, var2 );
    2661  2396327463 :     L_var3 = L_add( L_var3, (Word32) 0x00008000L );
    2662  2396327463 :     var_out = extract_h( L_var3 );
    2663             : 
    2664             : #ifdef WMOPS
    2665             :     multiCounter[currCounter].L_mac--;
    2666             :     multiCounter[currCounter].L_add--;
    2667             :     multiCounter[currCounter].extract_h--;
    2668             :     multiCounter[currCounter].mac_r++;
    2669             : #endif
    2670             : 
    2671             :     BASOP_CHECK();
    2672             : 
    2673             : 
    2674  2396327463 :     return ( var_out );
    2675             : }
    2676  2504739141 : Word16 mac_r_sat( Word32 L_var3, Word16 var1, Word16 var2 )
    2677             : {
    2678             :     Flag Overflow;
    2679  2504739141 :     return mac_ro( L_var3, var1, var2, &Overflow );
    2680             : }
    2681             : /*___________________________________________________________________________
    2682             :  |                                                                           |
    2683             :  |   Function Name : msu_r                                                   |
    2684             :  |                                                                           |
    2685             :  |   Purpose :                                                               |
    2686             :  |                                                                           |
    2687             :  |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   |
    2688             :  |   bit result from L_var3 with saturation. Round the LS 16 bits of the res-|
    2689             :  |   ult into the MS 16 bits with saturation and shift the result right by   |
    2690             :  |   16. Return a 16 bit result.                                             |
    2691             :  |            msu_r(L_var3,var1,var2) = round_fx(L_msu(L_var3,var1,var2))    |
    2692             :  |                                                                           |
    2693             :  |   Complexity weight : 1                                                   |
    2694             :  |                                                                           |
    2695             :  |   Inputs :                                                                |
    2696             :  |                                                                           |
    2697             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  |
    2698             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 |
    2699             :  |                                                                           |
    2700             :  |    var1                                                                   |
    2701             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2702             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2703             :  |                                                                           |
    2704             :  |    var2                                                                   |
    2705             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2706             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2707             :  |                                                                           |
    2708             :  |   Outputs :                                                               |
    2709             :  |                                                                           |
    2710             :  |    none                                                                   |
    2711             :  |                                                                           |
    2712             :  |   Return Value :                                                          |
    2713             :  |                                                                           |
    2714             :  |    var_out                                                                |
    2715             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2716             :  |             range : 0x0000 8000 <= L_var_out <= 0x0000 7fff.              |
    2717             :  |___________________________________________________________________________|
    2718             : */
    2719 19051806042 : Word16 msu_ro( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    2720             : {
    2721             :     Word16 var_out;
    2722             : 
    2723 19051806042 :     L_var3 = L_msu_o( L_var3, var1, var2, Overflow );
    2724 19051806042 :     L_var3 = L_add_o( L_var3, (Word32) 0x00008000L, Overflow );
    2725 19051806042 :     var_out = extract_h( L_var3 );
    2726             : 
    2727             : #ifdef WMOPS
    2728             :     multiCounter[currCounter].L_msu--;
    2729             :     multiCounter[currCounter].L_add--;
    2730             :     multiCounter[currCounter].extract_h--;
    2731             :     multiCounter[currCounter].msu_r++;
    2732             : #endif
    2733             :     BASOP_CHECK();
    2734             : 
    2735 19051806042 :     return ( var_out );
    2736             : }
    2737             : 
    2738  4645723331 : Word16 msu_r( Word32 L_var3, Word16 var1, Word16 var2 )
    2739             : {
    2740             :     Word16 var_out;
    2741             : 
    2742  4645723331 :     L_var3 = L_msu( L_var3, var1, var2 );
    2743  4645723331 :     L_var3 = L_add( L_var3, (Word32) 0x00008000L );
    2744  4645723331 :     var_out = extract_h( L_var3 );
    2745             : 
    2746             : #ifdef WMOPS
    2747             :     multiCounter[currCounter].L_msu--;
    2748             :     multiCounter[currCounter].L_add--;
    2749             :     multiCounter[currCounter].extract_h--;
    2750             :     multiCounter[currCounter].msu_r++;
    2751             : #endif
    2752             :     BASOP_CHECK();
    2753             : 
    2754  4645723331 :     return ( var_out );
    2755             : }
    2756 18393203655 : Word16 msu_r_sat( Word32 L_var3, Word16 var1, Word16 var2 )
    2757             : {
    2758             :     Flag Overflow;
    2759 18393203655 :     return msu_ro( L_var3, var1, var2, &Overflow );
    2760             : }
    2761             : /*___________________________________________________________________________
    2762             :  |                                                                           |
    2763             :  |   Function Name : L_deposit_h                                             |
    2764             :  |                                                                           |
    2765             :  |   Purpose :                                                               |
    2766             :  |                                                                           |
    2767             :  |   Deposit the 16 bit var1 into the 16 MS bits of the 32 bit output. The   |
    2768             :  |   16 LS bits of the output are zeroed.                                    |
    2769             :  |                                                                           |
    2770             :  |   Complexity weight : 1                                                   |
    2771             :  |                                                                           |
    2772             :  |   Inputs :                                                                |
    2773             :  |                                                                           |
    2774             :  |    var1                                                                   |
    2775             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2776             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2777             :  |                                                                           |
    2778             :  |   Outputs :                                                               |
    2779             :  |                                                                           |
    2780             :  |    none                                                                   |
    2781             :  |                                                                           |
    2782             :  |   Return Value :                                                          |
    2783             :  |                                                                           |
    2784             :  |    L_var_out                                                              |
    2785             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2786             :  |             range : 0x8000 0000 <= var_out <= 0x7fff 0000.                |
    2787             :  |___________________________________________________________________________|
    2788             : */
    2789  5654945459 : Word32 L_deposit_h( Word16 var1 )
    2790             : {
    2791             :     Word32 L_var_out;
    2792             : 
    2793  5654945459 :     L_var_out = (Word32) var1 << 16;
    2794             : 
    2795             : #ifdef WMOPS
    2796             :     multiCounter[currCounter].L_deposit_h++;
    2797             : #endif
    2798             : 
    2799             :     BASOP_CHECK();
    2800             : 
    2801             : 
    2802  5654945459 :     return ( L_var_out );
    2803             : }
    2804             : 
    2805             : 
    2806             : /*___________________________________________________________________________
    2807             :  |                                                                           |
    2808             :  |   Function Name : L_deposit_l                                             |
    2809             :  |                                                                           |
    2810             :  |   Purpose :                                                               |
    2811             :  |                                                                           |
    2812             :  |   Deposit the 16 bit var1 into the 16 LS bits of the 32 bit output. The   |
    2813             :  |   16 MS bits of the output are sign extended.                             |
    2814             :  |                                                                           |
    2815             :  |   Complexity weight : 1                                                   |
    2816             :  |                                                                           |
    2817             :  |   Inputs :                                                                |
    2818             :  |                                                                           |
    2819             :  |    var1                                                                   |
    2820             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2821             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2822             :  |                                                                           |
    2823             :  |   Outputs :                                                               |
    2824             :  |                                                                           |
    2825             :  |    none                                                                   |
    2826             :  |                                                                           |
    2827             :  |   Return Value :                                                          |
    2828             :  |                                                                           |
    2829             :  |    L_var_out                                                              |
    2830             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2831             :  |             range : 0xFFFF 8000 <= var_out <= 0x0000 7fff.                |
    2832             :  |___________________________________________________________________________|
    2833             : */
    2834 14723325740 : Word32 L_deposit_l( Word16 var1 )
    2835             : {
    2836             :     Word32 L_var_out;
    2837             : 
    2838 14723325740 :     L_var_out = (Word32) var1;
    2839             : 
    2840             : #ifdef WMOPS
    2841             :     multiCounter[currCounter].L_deposit_l++;
    2842             : #endif
    2843             : 
    2844             :     BASOP_CHECK();
    2845             : 
    2846             : 
    2847 14723325740 :     return ( L_var_out );
    2848             : }
    2849             : 
    2850             : 
    2851             : /*___________________________________________________________________________
    2852             :  |                                                                           |
    2853             :  |   Function Name : L_shr_r                                                 |
    2854             :  |                                                                           |
    2855             :  |   Purpose :                                                               |
    2856             :  |                                                                           |
    2857             :  |   Same as L_shr(L_var1,var2) but with rounding. Saturate the result in    |
    2858             :  |   case of underflows or overflows :                                       |
    2859             :  |    - If var2 is greater than zero :                                       |
    2860             :  |          if (L_sub(L_shl(L_shr(L_var1,var2),1),L_shr(L_var1,sub(var2,1))))|
    2861             :  |          is equal to zero                                                 |
    2862             :  |                     then                                                  |
    2863             :  |                     L_shr_r(L_var1,var2) = L_shr(L_var1,var2)             |
    2864             :  |                     else                                                  |
    2865             :  |                     L_shr_r(L_var1,var2) = L_add(L_shr(L_var1,var2),1)    |
    2866             :  |    - If var2 is less than or equal to zero :                              |
    2867             :  |                     L_shr_r(L_var1,var2) = L_shr(L_var1,var2).            |
    2868             :  |                                                                           |
    2869             :  |   Complexity weight : 3                                                   |
    2870             :  |                                                                           |
    2871             :  |   Inputs :                                                                |
    2872             :  |                                                                           |
    2873             :  |    L_var1                                                                 |
    2874             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2875             :  |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
    2876             :  |                                                                           |
    2877             :  |    var2                                                                   |
    2878             :  |             16 bit short signed integer (Word16) whose value falls in the |
    2879             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    2880             :  |                                                                           |
    2881             :  |   Outputs :                                                               |
    2882             :  |                                                                           |
    2883             :  |    none                                                                   |
    2884             :  |                                                                           |
    2885             :  |   Return Value :                                                          |
    2886             :  |                                                                           |
    2887             :  |    L_var_out                                                              |
    2888             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2889             :  |             range : 0x8000 0000 <= var_out <= 0x7fff ffff.                |
    2890             :  |___________________________________________________________________________|
    2891             : */
    2892  1154463330 : Word32 L_shr_r( Word32 L_var1, Word16 var2 )
    2893             : {
    2894             :     Word32 L_var_out;
    2895             : 
    2896  1154463330 :     if ( var2 > 31 )
    2897             :     {
    2898     1694908 :         L_var_out = 0;
    2899             :     }
    2900             :     else
    2901             :     {
    2902  1152768422 :         L_var_out = L_shr( L_var1, var2 );
    2903             : 
    2904             : #ifdef WMOPS
    2905             :         multiCounter[currCounter].L_shr--;
    2906             : #endif
    2907  1152768422 :         if ( var2 > 0 )
    2908             :         {
    2909   484510398 :             if ( ( L_var1 & ( (Word32) 1 << ( var2 - 1 ) ) ) != 0 )
    2910             :             {
    2911   155938252 :                 L_var_out++;
    2912             :             }
    2913             :         }
    2914             :     }
    2915             : 
    2916             : #ifdef WMOPS
    2917             :     multiCounter[currCounter].L_shr_r++;
    2918             : #endif
    2919             : 
    2920             :     BASOP_CHECK();
    2921             : 
    2922             : 
    2923  1154463330 :     return ( L_var_out );
    2924             : }
    2925    45762706 : Word32 L_shr_ro( Word32 L_var1, Word16 var2, Flag *Overflow )
    2926             : {
    2927             :     Word32 L_var_out;
    2928             : 
    2929    45762706 :     if ( var2 > 31 )
    2930             :     {
    2931      197079 :         L_var_out = 0;
    2932             :     }
    2933             :     else
    2934             :     {
    2935    45565627 :         L_var_out = L_shr_o( L_var1, var2, Overflow );
    2936    45565627 :         if ( var2 > 0 )
    2937             :         {
    2938    45522011 :             if ( ( L_var1 & ( (Word32) 1 << ( var2 - 1 ) ) ) != 0 )
    2939             :             {
    2940    22757977 :                 L_var_out++;
    2941             :             }
    2942             :         }
    2943             :     }
    2944    45762706 :     return ( L_var_out );
    2945             : }
    2946             : 
    2947    45762706 : Word32 L_shr_r_sat( Word32 L_var1, Word16 var2 )
    2948             : {
    2949    45762706 :     Flag Overflow = 0;
    2950    45762706 :     return L_shr_ro( L_var1, var2, &Overflow );
    2951             : }
    2952             : /*___________________________________________________________________________
    2953             :  |                                                                           |
    2954             :  |   Function Name : L_abs                                                   |
    2955             :  |                                                                           |
    2956             :  |   Purpose :                                                               |
    2957             :  |                                                                           |
    2958             :  |    Absolute value of L_var1; Saturate in case where the input is          |
    2959             :  |                                                               -214783648  |
    2960             :  |                                                                           |
    2961             :  |   Complexity weight : 1                                                   |
    2962             :  |                                                                           |
    2963             :  |   Inputs :                                                                |
    2964             :  |                                                                           |
    2965             :  |    L_var1                                                                 |
    2966             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2967             :  |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
    2968             :  |                                                                           |
    2969             :  |   Outputs :                                                               |
    2970             :  |                                                                           |
    2971             :  |    none                                                                   |
    2972             :  |                                                                           |
    2973             :  |   Return Value :                                                          |
    2974             :  |                                                                           |
    2975             :  |    L_var_out                                                              |
    2976             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    2977             :  |             range : 0x0000 0000 <= var_out <= 0x7fff ffff.                |
    2978             :  |___________________________________________________________________________|
    2979             : */
    2980 18267781416 : Word32 L_abs( Word32 L_var1 )
    2981             : {
    2982             :     Word32 L_var_out;
    2983             : 
    2984 18267781416 :     if ( L_var1 == MIN_32 )
    2985             :     {
    2986      970046 :         L_var_out = MAX_32;
    2987             :     }
    2988             :     else
    2989             :     {
    2990 18266811370 :         if ( L_var1 < 0 )
    2991             :         {
    2992  6755576030 :             L_var_out = -L_var1;
    2993             :         }
    2994             :         else
    2995             :         {
    2996 11511235340 :             L_var_out = L_var1;
    2997             :         }
    2998             :     }
    2999             : 
    3000             : #ifdef WMOPS
    3001             :     multiCounter[currCounter].L_abs++;
    3002             : #endif
    3003             : 
    3004             :     BASOP_CHECK();
    3005             : 
    3006             : 
    3007 18267781416 :     return ( L_var_out );
    3008             : }
    3009             : 
    3010             : 
    3011             : /*___________________________________________________________________________
    3012             :  |                                                                           |
    3013             :  |   Function Name : L_sat                                                   |
    3014             :  |                                                                           |
    3015             :  |   Purpose :                                                               |
    3016             :  |                                                                           |
    3017             :  |    32 bit L_var1 is set to 2147483647 if an overflow occured or to        |
    3018             :  |    -2147483648 if an underflow occured on the most recent L_add_c,        |
    3019             :  |    L_sub_c, L_macNs or L_msuNs operations. The carry and overflow values  |
    3020             :  |    are binary values which can be tested and assigned values.             |
    3021             :  |                                                                           |
    3022             :  |   Complexity weight : 4                                                   |
    3023             :  |                                                                           |
    3024             :  |   Inputs :                                                                |
    3025             :  |                                                                           |
    3026             :  |    L_var1                                                                 |
    3027             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    3028             :  |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
    3029             :  |                                                                           |
    3030             :  |   Outputs :                                                               |
    3031             :  |                                                                           |
    3032             :  |    none                                                                   |
    3033             :  |                                                                           |
    3034             :  |   Return Value :                                                          |
    3035             :  |                                                                           |
    3036             :  |    L_var_out                                                              |
    3037             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    3038             :  |             range : 0x8000 0000 <= var_out <= 0x7fff ffff.                |
    3039             :  |___________________________________________________________________________|
    3040             : */
    3041           0 : Word32 DEPR_L_sat_co( Word32 L_var1, Flag Overflow, Flag Carry )
    3042             : {
    3043             :     Word32 L_var_out;
    3044             : 
    3045           0 :     L_var_out = L_var1;
    3046             : 
    3047           0 :     if ( Overflow )
    3048             :     {
    3049             : 
    3050           0 :         if ( Carry )
    3051             :         {
    3052           0 :             L_var_out = MIN_32;
    3053             :         }
    3054             :         else
    3055             :         {
    3056           0 :             L_var_out = MAX_32;
    3057             :         }
    3058             :     }
    3059             : 
    3060             : #ifdef WMOPS
    3061             :     multiCounter[currCounter].L_sat++;
    3062             : #endif
    3063             : 
    3064             :     BASOP_CHECK();
    3065             : 
    3066             : 
    3067           0 :     return ( L_var_out );
    3068             : }
    3069           0 : Word32 L_sat_co( Word32 L_var1, Flag Carry, Flag Overflow )
    3070             : {
    3071             :     Word32 L_var_out;
    3072             : 
    3073           0 :     L_var_out = L_var1;
    3074             : 
    3075           0 :     if ( Overflow )
    3076             :     {
    3077             : 
    3078           0 :         if ( Carry )
    3079             :         {
    3080           0 :             L_var_out = MIN_32;
    3081             :         }
    3082             :         else
    3083             :         {
    3084           0 :             L_var_out = MAX_32;
    3085             :         }
    3086             :     }
    3087           0 :     return ( L_var_out );
    3088             : }
    3089             : 
    3090           0 : Word32 L_sat( Word32 L_var1 )
    3091             : {
    3092           0 :     assert( 0 ); /* Overflow and Carry are no longer global, must be passed as parameters */
    3093             :     return L_sat_co( L_var1, 0, 0 );
    3094             : }
    3095             : /*___________________________________________________________________________
    3096             :  |                                                                           |
    3097             :  |   Function Name : norm_s                                                  |
    3098             :  |                                                                           |
    3099             :  |   Purpose :                                                               |
    3100             :  |                                                                           |
    3101             :  |   Produces the number of left shift needed to normalize the 16 bit varia- |
    3102             :  |   ble var1 for positive values on the interval with minimum of 16384 and  |
    3103             :  |   maximum of 32767, and for negative values on the interval with minimum  |
    3104             :  |   of -32768 and maximum of -16384; in order to normalize the result, the  |
    3105             :  |   following operation must be done :                                      |
    3106             :  |                    norm_var1 = shl(var1,norm_s(var1)).                    |
    3107             :  |                                                                           |
    3108             :  |   Complexity weight : 1                                                   |
    3109             :  |                                                                           |
    3110             :  |   Inputs :                                                                |
    3111             :  |                                                                           |
    3112             :  |    var1                                                                   |
    3113             :  |             16 bit short signed integer (Word16) whose value falls in the |
    3114             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   |
    3115             :  |                                                                           |
    3116             :  |   Outputs :                                                               |
    3117             :  |                                                                           |
    3118             :  |    none                                                                   |
    3119             :  |                                                                           |
    3120             :  |   Return Value :                                                          |
    3121             :  |                                                                           |
    3122             :  |    var_out                                                                |
    3123             :  |             16 bit short signed integer (Word16) whose value falls in the |
    3124             :  |             range : 0x0000 0000 <= var_out <= 0x0000 000f.                |
    3125             :  |___________________________________________________________________________|
    3126             : */
    3127  6833693495 : Word16 norm_s( Word16 var1 )
    3128             : {
    3129             :     Word16 var_out;
    3130             : 
    3131  6833693495 :     if ( var1 == 0 )
    3132             :     {
    3133    26330659 :         var_out = 0;
    3134             :     }
    3135             :     else
    3136             :     {
    3137  6807362836 :         if ( var1 == (Word16) 0xffff )
    3138             :         {
    3139    12279644 :             var_out = 15;
    3140             :         }
    3141             :         else
    3142             :         {
    3143  6795083192 :             if ( var1 < 0 )
    3144             :             {
    3145  2746696403 :                 var1 = ~var1;
    3146             :             }
    3147 33086083995 :             for ( var_out = 0; var1 < 0x4000; var_out++ )
    3148             :             {
    3149 26291000803 :                 var1 <<= 1;
    3150             :             }
    3151             :         }
    3152             :     }
    3153             : 
    3154             : #ifdef WMOPS
    3155             :     multiCounter[currCounter].norm_s++;
    3156             : #endif
    3157             : 
    3158             :     BASOP_CHECK();
    3159             : 
    3160             : 
    3161  6833693495 :     return ( var_out );
    3162             : }
    3163             : 
    3164             : 
    3165             : /*___________________________________________________________________________
    3166             :  |                                                                           |
    3167             :  |   Function Name : div_s                                                   |
    3168             :  |                                                                           |
    3169             :  |   Purpose :                                                               |
    3170             :  |                                                                           |
    3171             :  |   Produces a result which is the fractional integer division of var1  by  |
    3172             :  |   var2; var1 and var2 must be positive and var2 must be greater or equal  |
    3173             :  |   to var1; the result is positive (leading bit equal to 0) and truncated  |
    3174             :  |   to 16 bits.                                                             |
    3175             :  |   If var1 = var2 then div(var1,var2) = 32767.                             |
    3176             :  |                                                                           |
    3177             :  |   Complexity weight : 18                                                  |
    3178             :  |                                                                           |
    3179             :  |   Inputs :                                                                |
    3180             :  |                                                                           |
    3181             :  |    var1                                                                   |
    3182             :  |             16 bit short signed integer (Word16) whose value falls in the |
    3183             :  |             range : 0x0000 0000 <= var1 <= var2 and var2 != 0.            |
    3184             :  |                                                                           |
    3185             :  |    var2                                                                   |
    3186             :  |             16 bit short signed integer (Word16) whose value falls in the |
    3187             :  |             range : var1 <= var2 <= 0x0000 7fff and var2 != 0.            |
    3188             :  |                                                                           |
    3189             :  |   Outputs :                                                               |
    3190             :  |                                                                           |
    3191             :  |    none                                                                   |
    3192             :  |                                                                           |
    3193             :  |   Return Value :                                                          |
    3194             :  |                                                                           |
    3195             :  |    var_out                                                                |
    3196             :  |             16 bit short signed integer (Word16) whose value falls in the |
    3197             :  |             range : 0x0000 0000 <= var_out <= 0x0000 7fff.                |
    3198             :  |             It's a Q15 value (point between b15 and b14).                 |
    3199             :  |___________________________________________________________________________|
    3200             : */
    3201  1174010357 : Word16 div_s( Word16 var1, Word16 var2 )
    3202             : {
    3203  1174010357 :     Word16 var_out = 0;
    3204             :     Word16 iteration;
    3205             :     Word32 L_num;
    3206             :     Word32 L_denom;
    3207             : 
    3208  1174010357 :     if ( ( var1 > var2 ) || ( var1 < 0 ) || ( var2 < 0 ) )
    3209             :     {
    3210             :         /* printf ("Division Error var1=%d  var2=%d in ", var1, var2); printStack(); */
    3211             :         char text[60];
    3212           0 :         sprintf( text, "Division Error var1=%d  var2=%d in ", var1, var2 );
    3213           0 :         abort(); /* exit (0); */
    3214             :     }
    3215  1174010357 :     if ( var2 == 0 )
    3216             :     {
    3217             :         /* printf ("Division by 0, Fatal error in "); printStack(); */
    3218           0 :         abort(); /* exit (0); */
    3219             :     }
    3220  1174010357 :     if ( var1 == 0 )
    3221             :     {
    3222    13729900 :         var_out = 0;
    3223             :     }
    3224             :     else
    3225             :     {
    3226  1160280457 :         if ( var1 == var2 )
    3227             :         {
    3228    27473938 :             var_out = MAX_16;
    3229             :         }
    3230             :         else
    3231             :         {
    3232  1132806519 :             L_num = L_deposit_l( var1 );
    3233  1132806519 :             L_denom = L_deposit_l( var2 );
    3234             : 
    3235             : #ifdef WMOPS
    3236             :             multiCounter[currCounter].L_deposit_l--;
    3237             :             multiCounter[currCounter].L_deposit_l--;
    3238             : #endif
    3239             : 
    3240 18124904304 :             for ( iteration = 0; iteration < 15; iteration++ )
    3241             :             {
    3242 16992097785 :                 var_out <<= 1;
    3243 16992097785 :                 L_num <<= 1;
    3244             : 
    3245 16992097785 :                 if ( L_num >= L_denom )
    3246             :                 {
    3247  7518938906 :                     L_num = L_sub( L_num, L_denom );
    3248  7518938906 :                     var_out = add( var_out, 1 );
    3249             : #ifdef WMOPS
    3250             :                     multiCounter[currCounter].L_sub--;
    3251             :                     multiCounter[currCounter].add--;
    3252             : #endif
    3253             :                 }
    3254             :             }
    3255             :         }
    3256             :     }
    3257             : 
    3258             : #ifdef WMOPS
    3259             :     multiCounter[currCounter].div_s++;
    3260             : #endif
    3261             : 
    3262             :     BASOP_CHECK();
    3263             : 
    3264             : 
    3265  1174010357 :     return ( var_out );
    3266             : }
    3267             : 
    3268             : 
    3269             : /*___________________________________________________________________________
    3270             :  |                                                                           |
    3271             :  |   Function Name : norm_l                                                  |
    3272             :  |                                                                           |
    3273             :  |   Purpose :                                                               |
    3274             :  |                                                                           |
    3275             :  |   Produces the number of left shifts needed to normalize the 32 bit varia-|
    3276             :  |   ble L_var1 for positive values on the interval with minimum of          |
    3277             :  |   1073741824 and maximum of 2147483647, and for negative values on the in-|
    3278             :  |   terval with minimum of -2147483648 and maximum of -1073741824; in order |
    3279             :  |   to normalize the result, the following operation must be done :         |
    3280             :  |                   norm_L_var1 = L_shl(L_var1,norm_l(L_var1)).             |
    3281             :  |                                                                           |
    3282             :  |   Complexity weight : 1                                                   |
    3283             :  |                                                                           |
    3284             :  |   Inputs :                                                                |
    3285             :  |                                                                           |
    3286             :  |    L_var1                                                                 |
    3287             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    3288             :  |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
    3289             :  |                                                                           |
    3290             :  |   Outputs :                                                               |
    3291             :  |                                                                           |
    3292             :  |    none                                                                   |
    3293             :  |                                                                           |
    3294             :  |   Return Value :                                                          |
    3295             :  |                                                                           |
    3296             :  |    var_out                                                                |
    3297             :  |             16 bit short signed integer (Word16) whose value falls in the |
    3298             :  |             range : 0x0000 0000 <= var_out <= 0x0000 001f.                |
    3299             :  |___________________________________________________________________________|
    3300             : */
    3301 54274221949 : Word16 norm_l( Word32 L_var1 )
    3302             : {
    3303             :     Word16 var_out;
    3304             : 
    3305 54274221949 :     if ( L_var1 == 0 )
    3306             :     {
    3307  6475571377 :         var_out = 0;
    3308             :     }
    3309             :     else
    3310             :     {
    3311 47798650572 :         if ( L_var1 == (Word32) 0xffffffffL )
    3312             :         {
    3313    29640522 :             var_out = 31;
    3314             :         }
    3315             :         else
    3316             :         {
    3317 47769010050 :             if ( L_var1 < 0 )
    3318             :             {
    3319 15375656009 :                 L_var1 = ~L_var1;
    3320             :             }
    3321 >50769*10^7 :             for ( var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++ )
    3322             :             {
    3323 >45992*10^7 :                 L_var1 <<= 1;
    3324             :             }
    3325             :         }
    3326             :     }
    3327             : 
    3328             : #ifdef WMOPS
    3329             :     multiCounter[currCounter].norm_l++;
    3330             : #endif
    3331             : 
    3332             :     BASOP_CHECK();
    3333             : 
    3334             : 
    3335 54274221949 :     return ( var_out );
    3336             : }
    3337             : 
    3338             : /*
    3339             :  ******************************************************************************
    3340             :  * Additional operators extracted from the G.723.1 Library
    3341             :  * Adapted for WMOPS calculations
    3342             :  ******************************************************************************
    3343             :  */
    3344             : 
    3345             : /*___________________________________________________________________________
    3346             :  |                                                                           |
    3347             :  |   Function Name : L_mls                                                   |
    3348             :  |                                                                           |
    3349             :  |   Purpose :                                                               |
    3350             :  |                                                                           |
    3351             :  |   Multiplies a 16 bit word v by a 32 bit word Lv and returns a 32 bit     |
    3352             :  |   word (multiplying 16 by 32 bit words gives 48 bit word; the function    |
    3353             :  |   extracts the 32 MSB and shift the result to the left by 1).             |
    3354             :  |                                                                           |
    3355             :  |   A 32 bit word can be written as                                         |
    3356             :  |    Lv = a  +  b * 2^16                                                    |
    3357             :  |   where a= unsigned 16 LSBs and b= signed 16 MSBs.                        |
    3358             :  |   The function returns v * Lv  /  2^15  which is equivalent to            |
    3359             :  |        a*v / 2^15 + b*v*2                                                 |
    3360             :  |                                                                           |
    3361             :  |   Complexity weight : 5                                                   |
    3362             :  |                                                                           |
    3363             :  |   Inputs :                                                                |
    3364             :  |                                                                           |
    3365             :  |   Lv                                                                      |
    3366             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    3367             :  |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   |
    3368             :  |   v                                                                       |
    3369             :  |             16 bit short signed integer (Word16) whose value falls in the |
    3370             :  |             range : 0x8000 <= var1 <= 0x7fff.                             |
    3371             :  |                                                                           |
    3372             :  |   Outputs :                                                               |
    3373             :  |                                                                           |
    3374             :  |    none                                                                   |
    3375             :  |                                                                           |
    3376             :  |   Return Value :                                                          |
    3377             :  |                                                                           |
    3378             :  |    var_out                                                                |
    3379             :  |             32 bit long signed integer (Word32) whose value falls in the  |
    3380             :  |             range : 0x8000 0000 <= var_out <= 0x7fff ffff.                |
    3381             :  |                                                                           |
    3382             :  |___________________________________________________________________________|
    3383             : */
    3384           0 : Word32 L_mls_o( Word32 Lv, Word16 v, Flag *Overflow )
    3385             : {
    3386             :     Word32 Temp;
    3387             : 
    3388           0 :     Temp = Lv & (Word32) 0x0000ffff;
    3389           0 :     Temp = Temp * (Word32) v;
    3390           0 :     Temp = L_shr( Temp, (Word16) 15 );
    3391           0 :     Temp = L_mac_o( Temp, v, extract_h( Lv ), Overflow );
    3392             : 
    3393             : #ifdef WMOPS
    3394             :     multiCounter[currCounter].L_shr--;
    3395             :     multiCounter[currCounter].L_mac--;
    3396             :     multiCounter[currCounter].extract_h--;
    3397             :     multiCounter[currCounter].L_mls++;
    3398             : #endif
    3399             : 
    3400             :     BASOP_CHECK();
    3401             : 
    3402           0 :     return Temp;
    3403             : }
    3404             : 
    3405           0 : Word32 L_mls( Word32 Lv, Word16 v )
    3406             : {
    3407             :     Word32 Temp;
    3408             : 
    3409           0 :     Temp = Lv & (Word32) 0x0000ffff;
    3410           0 :     Temp = Temp * (Word32) v;
    3411           0 :     Temp = L_shr( Temp, (Word16) 15 );
    3412           0 :     Temp = L_mac( Temp, v, extract_h( Lv ) );
    3413             : 
    3414             : #ifdef WMOPS
    3415             :     multiCounter[currCounter].L_shr--;
    3416             :     multiCounter[currCounter].L_mac--;
    3417             :     multiCounter[currCounter].extract_h--;
    3418             :     multiCounter[currCounter].L_mls++;
    3419             : #endif
    3420             : 
    3421             :     BASOP_CHECK();
    3422             : 
    3423           0 :     return Temp;
    3424             : }
    3425           0 : Word32 L_mls_sat( Word32 Lv, Word16 v )
    3426             : {
    3427             :     Flag Overflow;
    3428           0 :     return L_mls_o( Lv, v, &Overflow );
    3429             : }
    3430             : 
    3431             : /*__________________________________________________________________________
    3432             : |                                                                           |
    3433             : |   Function Name : div_l                                                   |
    3434             : |                                                                           |
    3435             : |   Purpose :                                                               |
    3436             : |                                                                           |
    3437             : |   Produces a result which is the fractional integer division of L_var1 by |
    3438             : |   var2; L_var1 and var2 must be positive and var2 << 16 must be greater or|
    3439             : |   equal to L_var1; the result is positive (leading bit equal to 0) and    |
    3440             : |   truncated to 16 bits.                                                   |
    3441             : |   If L_var1 == var2 << 16 then div_l(L_var1,var2) = 32767.                |
    3442             : |                                                                           |
    3443             : |   Complexity weight : 32                                                  |
    3444             : |                                                                           |
    3445             : |   Inputs :                                                                |
    3446             : |                                                                           |
    3447             : |    L_var1                                                                 |
    3448             : |             32 bit long signed integer (Word32) whose value falls in the  |
    3449             : |             range : 0x0000 0000 <= var1 <= (var2 << 16)  and var2 != 0.   |
    3450             : |             L_var1 must be considered as a Q.31 value                     |
    3451             : |                                                                           |
    3452             : |    var2                                                                   |
    3453             : |             16 bit short signed integer (Word16) whose value falls in the |
    3454             : |             range : var1 <= (var2<< 16) <= 0x7fff0000 and var2 != 0.      |
    3455             : |             var2 must be considered as a Q.15 value                       |
    3456             : |                                                                           |
    3457             : |   Outputs :                                                               |
    3458             : |                                                                           |
    3459             : |    none                                                                   |
    3460             : |                                                                           |
    3461             : |   Return Value :                                                          |
    3462             : |                                                                           |
    3463             : |    var_out                                                                |
    3464             : |             16 bit short signed integer (Word16) whose value falls in the |
    3465             : |             range : 0x0000 0000 <= var_out <= 0x0000 7fff.                |
    3466             : |             It's a Q15 value (point between b15 and b14).                 |
    3467             : |___________________________________________________________________________|
    3468             : */
    3469    55739528 : Word16 div_l( Word32 L_num, Word16 den )
    3470             : {
    3471    55739528 :     Word16 var_out = (Word16) 0;
    3472             :     Word32 L_den;
    3473             :     Word16 iteration;
    3474             : 
    3475             : #ifdef WMOPS
    3476             :     multiCounter[currCounter].div_l++;
    3477             : #endif
    3478             : 
    3479    55739528 :     if ( den == (Word16) 0 )
    3480             :     {
    3481             :         /* printf("Division by 0 in div_l, Fatal error in "); printStack(); */
    3482           0 :         exit( -1 );
    3483             :     }
    3484             : 
    3485    55739528 :     if ( ( L_num < (Word32) 0 ) || ( den < (Word16) 0 ) )
    3486             :     {
    3487             :         /* printf("Division Error in div_l, Fatal error in "); printStack(); */
    3488           0 :         exit( -1 );
    3489             :     }
    3490             : 
    3491    55739528 :     L_den = L_deposit_h( den );
    3492             : #ifdef WMOPS
    3493             :     multiCounter[currCounter].L_deposit_h--;
    3494             : #endif
    3495             : 
    3496    55739528 :     if ( L_num >= L_den )
    3497             :     {
    3498             : 
    3499             : 
    3500             :         BASOP_CHECK();
    3501     3207125 :         return MAX_16;
    3502             :     }
    3503             :     else
    3504             :     {
    3505    52532403 :         L_num = L_shr( L_num, (Word16) 1 );
    3506    52532403 :         L_den = L_shr( L_den, (Word16) 1 );
    3507             : #ifdef WMOPS
    3508             :         multiCounter[currCounter].L_shr -= 2;
    3509             : #endif
    3510   840518448 :         for ( iteration = (Word16) 0; iteration < (Word16) 15; iteration++ )
    3511             :         {
    3512   787986045 :             var_out = shl( var_out, (Word16) 1 );
    3513   787986045 :             L_num = L_shl( L_num, (Word16) 1 );
    3514             : #ifdef WMOPS
    3515             :             multiCounter[currCounter].shl--;
    3516             :             multiCounter[currCounter].L_shl--;
    3517             : #endif
    3518   787986045 :             if ( L_num >= L_den )
    3519             :             {
    3520   266879593 :                 L_num = L_sub( L_num, L_den );
    3521   266879593 :                 var_out = add( var_out, (Word16) 1 );
    3522             : #ifdef WMOPS
    3523             :                 multiCounter[currCounter].L_sub--;
    3524             :                 multiCounter[currCounter].add--;
    3525             : #endif
    3526             :             }
    3527             :         }
    3528             : 
    3529             : 
    3530             :         BASOP_CHECK();
    3531             : 
    3532    52532403 :         return var_out;
    3533             :     }
    3534             : }
    3535             : 
    3536             : 
    3537             : /*__________________________________________________________________________
    3538             : |                                                                           |
    3539             : |   Function Name : i_mult                                                  |
    3540             : |                                                                           |
    3541             : |   Purpose :                                                               |
    3542             : |                                                                           |
    3543             : |   Integer 16-bit multiplication with overflow control.                    |
    3544             : |   No overflow protection is performed if ORIGINAL_G7231 is defined.       |
    3545             : |                                                                           |
    3546             : |   Complexity weight : 3 (it is performing something equivalent to         |
    3547             : |                          extract_h( L_shl( L_mult0( v1, v2), 16))         |
    3548             : |                                                                           |
    3549             : |   Inputs :                                                                |
    3550             : |                                                                           |
    3551             : |    a                                                                      |
    3552             : |             16 bit short signed integer (Word16).                         |
    3553             : |                                                                           |
    3554             : |    b                                                                      |
    3555             : |             16 bit short signed integer (Word16).                         |
    3556             : |                                                                           |
    3557             : |   Outputs :                                                               |
    3558             : |                                                                           |
    3559             : |    none                                                                   |
    3560             : |                                                                           |
    3561             : |   Return Value :                                                          |
    3562             : |                                                                           |
    3563             : |             16 bit short signed integer (Word16). No overflow checks      |
    3564             : |             are performed if ORIGINAL_G7231 is defined.                   |
    3565             : |___________________________________________________________________________|
    3566             : */
    3567           0 : Word16 DEPR_i_mult( Word16 a, Word16 b )
    3568             : {
    3569             : #ifdef ORIGINAL_G7231
    3570             :     return a * b;
    3571             : #else
    3572           0 :     Word32 /*register*/ c = a * b;
    3573             : #ifdef WMOPS
    3574             :     multiCounter[currCounter].i_mult++;
    3575             : #endif
    3576           0 :     return saturate( c );
    3577             : #endif
    3578             : }
    3579             : 
    3580  7165889390 : Word16 i_mult_o( Word16 a, Word16 b, Flag *Overflow )
    3581             : {
    3582             : #ifdef ORIGINAL_G7231
    3583             :     return a * b;
    3584             : #else
    3585  7165889390 :     register Word32 c = a * b;
    3586  7165889390 :     return saturate_o( c, Overflow );
    3587             : #endif
    3588             : }
    3589  7163758647 : Word16 i_mult( Word16 a, Word16 b )
    3590             : {
    3591  7163758647 :     return i_mult_o( a, b, NULL );
    3592             : }
    3593     1008983 : Word16 i_mult_sat( Word16 a, Word16 b )
    3594             : {
    3595             :     Flag Overflow;
    3596     1008983 :     return i_mult_o( a, b, &Overflow );
    3597             : }
    3598             : /*
    3599             :  ******************************************************************************
    3600             :  * The following three operators are not part of the original
    3601             :  * G.729/G.723.1 set of basic operators and implement shiftless
    3602             :  * accumulation operation.
    3603             :  ******************************************************************************
    3604             :  */
    3605             : 
    3606             : /*___________________________________________________________________________
    3607             :  |
    3608             :  |   Function Name : L_mult0
    3609             :  |
    3610             :  |   Purpose :
    3611             :  |
    3612             :  |   L_mult0 is the 32 bit result of the multiplication of var1 times var2
    3613             :  |   without one left shift.
    3614             :  |
    3615             :  |   Complexity weight : 1
    3616             :  |
    3617             :  |   Inputs :
    3618             :  |
    3619             :  |    var1     16 bit short signed integer (Word16) whose value falls in the
    3620             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3621             :  |
    3622             :  |    var2     16 bit short signed integer (Word16) whose value falls in the
    3623             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3624             :  |
    3625             :  |   Return Value :
    3626             :  |
    3627             :  |    L_var_out
    3628             :  |             32 bit long signed integer (Word32) whose value falls in the
    3629             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
    3630             :  |___________________________________________________________________________
    3631             : */
    3632 23414426760 : Word32 L_mult0( Word16 var1, Word16 var2 )
    3633             : {
    3634             :     Word32 L_var_out;
    3635             : 
    3636 23414426760 :     L_var_out = (Word32) var1 * (Word32) var2;
    3637             : 
    3638             : #ifdef WMOPS
    3639             :     multiCounter[currCounter].L_mult0++;
    3640             : #endif
    3641             : 
    3642             : 
    3643 23414426760 :     return ( L_var_out );
    3644             : }
    3645             : 
    3646             : 
    3647             : /*___________________________________________________________________________
    3648             :  |
    3649             :  |   Function Name : L_mac0
    3650             :  |
    3651             :  |   Purpose :
    3652             :  |
    3653             :  |   Multiply var1 by var2 (without left shift) and add the 32 bit result to
    3654             :  |   L_var3 with saturation, return a 32 bit result:
    3655             :  |        L_mac0(L_var3,var1,var2) = L_add(L_var3,(L_mult0(var1,var2)).
    3656             :  |
    3657             :  |   Complexity weight : 1
    3658             :  |
    3659             :  |   Inputs :
    3660             :  |
    3661             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the
    3662             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
    3663             :  |
    3664             :  |    var1     16 bit short signed integer (Word16) whose value falls in the
    3665             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3666             :  |
    3667             :  |    var2     16 bit short signed integer (Word16) whose value falls in the
    3668             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3669             :  |
    3670             :  |   Return Value :
    3671             :  |
    3672             :  |    L_var_out
    3673             :  |             32 bit long signed integer (Word32) whose value falls in the
    3674             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
    3675             :  |___________________________________________________________________________
    3676             : */
    3677  3487982019 : Word32 L_mac0_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    3678             : {
    3679             :     Word32 L_var_out;
    3680             :     Word32 L_product;
    3681             : 
    3682  3487982019 :     L_product = L_mult0( var1, var2 );
    3683  3487982019 :     L_var_out = L_add_o( L_var3, L_product, Overflow );
    3684             : 
    3685             : #ifdef WMOPS
    3686             :     multiCounter[currCounter].L_mac0++;
    3687             :     multiCounter[currCounter].L_mult0--;
    3688             :     multiCounter[currCounter].L_add--;
    3689             : #endif
    3690             : 
    3691             :     BASOP_CHECK();
    3692             : 
    3693  3487982019 :     return ( L_var_out );
    3694             : }
    3695             : 
    3696  7134259263 : Word32 L_mac0( Word32 L_var3, Word16 var1, Word16 var2 )
    3697             : {
    3698             :     Word32 L_var_out;
    3699             :     Word32 L_product;
    3700             : 
    3701  7134259263 :     L_product = L_mult0( var1, var2 );
    3702  7134259263 :     L_var_out = L_add( L_var3, L_product );
    3703             : 
    3704             : #ifdef WMOPS
    3705             :     multiCounter[currCounter].L_mac0++;
    3706             :     multiCounter[currCounter].L_mult0--;
    3707             :     multiCounter[currCounter].L_add--;
    3708             : #endif
    3709             : 
    3710             :     BASOP_CHECK();
    3711             : 
    3712             : 
    3713  7134259263 :     return ( L_var_out );
    3714             : }
    3715  2366802253 : Word32 L_mac0_sat( Word32 L_var3, Word16 var1, Word16 var2 )
    3716             : {
    3717             :     Flag Overflow;
    3718  2366802253 :     return L_mac0_o( L_var3, var1, var2, &Overflow );
    3719             : }
    3720             : /*___________________________________________________________________________
    3721             :  |
    3722             :  |   Function Name : L_msu0
    3723             :  |
    3724             :  |   Purpose :
    3725             :  |
    3726             :  |   Multiply var1 by var2 (without left shift) and subtract the 32 bit
    3727             :  |   result to L_var3 with saturation, return a 32 bit result:
    3728             :  |        L_msu0(L_var3,var1,var2) = L_sub(L_var3,(L_mult0(var1,var2)).
    3729             :  |
    3730             :  |   Complexity weight : 1
    3731             :  |
    3732             :  |   Inputs :
    3733             :  |
    3734             :  |    L_var3   32 bit long signed integer (Word32) whose value falls in the
    3735             :  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.
    3736             :  |
    3737             :  |    var1     16 bit short signed integer (Word16) whose value falls in the
    3738             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3739             :  |
    3740             :  |    var2     16 bit short signed integer (Word16) whose value falls in the
    3741             :  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.
    3742             :  |
    3743             :  |   Return Value :
    3744             :  |
    3745             :  |    L_var_out
    3746             :  |             32 bit long signed integer (Word32) whose value falls in the
    3747             :  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
    3748             :  |___________________________________________________________________________
    3749             : */
    3750   484726680 : Word32 L_msu0_o( Word32 L_var3, Word16 var1, Word16 var2, Flag *Overflow )
    3751             : {
    3752             :     Word32 L_var_out;
    3753             :     Word32 L_product;
    3754             : 
    3755   484726680 :     L_product = L_mult0( var1, var2 );
    3756   484726680 :     L_var_out = L_sub_o( L_var3, L_product, Overflow );
    3757             : 
    3758             : #ifdef WMOPS
    3759             :     multiCounter[currCounter].L_msu0++;
    3760             :     multiCounter[currCounter].L_mult0--;
    3761             :     multiCounter[currCounter].L_sub--;
    3762             : #endif
    3763             : 
    3764             :     BASOP_CHECK();
    3765             : 
    3766   484726680 :     return ( L_var_out );
    3767             : }
    3768             : 
    3769  1328192239 : Word32 L_msu0( Word32 L_var3, Word16 var1, Word16 var2 )
    3770             : {
    3771             :     Word32 L_var_out;
    3772             :     Word32 L_product;
    3773             : 
    3774  1328192239 :     L_product = L_mult0( var1, var2 );
    3775  1328192239 :     L_var_out = L_sub( L_var3, L_product );
    3776             : 
    3777             : #ifdef WMOPS
    3778             :     multiCounter[currCounter].L_msu0++;
    3779             :     multiCounter[currCounter].L_mult0--;
    3780             :     multiCounter[currCounter].L_sub--;
    3781             : #endif
    3782             : 
    3783             :     BASOP_CHECK();
    3784             : 
    3785             : 
    3786  1328192239 :     return ( L_var_out );
    3787             : }
    3788     1009336 : Word32 L_msu0_sat( Word32 L_var3, Word16 var1, Word16 var2 )
    3789             : {
    3790             :     Flag Overflow;
    3791     1009336 :     return L_msu0_o( L_var3, var1, var2, &Overflow );
    3792             : }
    3793             : 
    3794             : #undef WMC_TOOL_SKIP

Generated by: LCOV version 1.14