LCOV - code coverage report
Current view: top level - lib_com - enh40.h (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 15 20 75.0 %
Date: 2025-05-03 01:55:50 Functions: 4 5 80.0 %

          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             : /*
      34             :   ===========================================================================
      35             :    File: ENH40.H                                         v.2.3 - 30.Nov.2009
      36             :   ===========================================================================
      37             : 
      38             :             ITU-T  STL  BASIC OPERATORS
      39             : 
      40             :             40-BIT ARITHMETIC OPERATORS
      41             : 
      42             :    History:
      43             :    07 Nov 04   v2.0     Incorporation of new 32-bit / 40-bit / control
      44             :                         operators for the ITU-T Standard Tool Library as
      45             :                         described in Geneva, 20-30 January 2004 WP 3/16 Q10/16
      46             :                         TD 11 document and subsequent discussions on the
      47             :                         wp3audio@yahoogroups.com email reflector.
      48             :    March 06   v2.1      Changed to improve portability.
      49             : 
      50             :   ============================================================================
      51             : */
      52             : 
      53             : 
      54             : #ifndef _ENH40_H
      55             : #define _ENH40_H
      56             : 
      57             : #include "stl.h"
      58             : 
      59             : #define MAX_40 ( 0x0000007fffffffff )
      60             : #define MIN_40 ( 0xffffff8000000000 )
      61             : 
      62             : #define L40_OVERFLOW_OCCURED( L40_var1 )  ( Overflow = 1, exit( 1 ), L40_var1 )
      63             : #define L40_UNDERFLOW_OCCURED( L40_var1 ) ( Overflow = 1, exit( 2 ), L40_var1 )
      64             : 
      65             : /*****************************************************************************
      66             :  *
      67             :  *  Prototypes for enhanced 40 bit arithmetic operators
      68             :  *
      69             :  *****************************************************************************/
      70             : Word40 L40_shr( Word40 L40_var1, Word16 var2 );
      71             : Word40 L40_shr_r( Word40 L40_var1, Word16 var2 );
      72             : Word40 L40_shl( Word40 L40_var1, Word16 var2 );
      73             : Word40 L40_shl_r( Word40 L40_var1, Word16 var2 );
      74             : 
      75             : static __inline Word40 L40_mult( Word16 var1, Word16 var2 );
      76             : 
      77             : static __inline Word40 L40_mac( Word40 L40_var1, Word16 var1, Word16 var2 );
      78             : static __inline Word16 mac_r40( Word40 L40_var1, Word16 var1, Word16 var2 );
      79             : 
      80             : static __inline Word40 L40_msu( Word40 L40_var1, Word16 var1, Word16 var2 );
      81             : static __inline Word16 msu_r40( Word40 L40_var1, Word16 var1, Word16 var2 );
      82             : 
      83             : 
      84             : void Mpy_32_16_ss( Word32 L_var1, Word16 var2, Word32 *L_varout_h, UWord16 *varout_l );
      85             : void Mpy_32_32_ss( Word32 L_var1, Word32 L_var2, Word32 *L_varout_h, UWord32 *L_varout_l );
      86             : 
      87             : 
      88             : Word40 L40_lshl( Word40 L40_var1, Word16 var2 );
      89             : Word40 L40_lshr( Word40 L40_var1, Word16 var2 );
      90             : 
      91             : static __inline Word40 L40_set( Word40 L40_var1 );
      92             : static __inline UWord16 Extract40_H( Word40 L40_var1 );
      93             : static __inline UWord16 Extract40_L( Word40 L40_var1 );
      94             : static __inline UWord32 L_Extract40( Word40 L40_var1 );
      95             : 
      96             : static __inline Word40 L40_deposit_h( Word16 var1 );
      97             : static __inline Word40 L40_deposit_l( Word16 var1 );
      98             : static __inline Word40 L40_deposit32( Word32 L_var1 );
      99             : 
     100             : static __inline Word40 L40_round( Word40 L40_var1 );
     101             : static __inline Word16 round40( Word40 L40_var1 );
     102             : 
     103             : 
     104             : Word40 L40_add( Word40 L40_var1, Word40 L40_var2 );
     105             : Word40 L40_sub( Word40 L40_var1, Word40 L40_var2 );
     106             : Word40 L40_abs( Word40 L40_var1 );
     107             : Word40 L40_negate( Word40 L40_var1 );
     108             : Word40 L40_max( Word40 L40_var1, Word40 L40_var2 );
     109             : Word40 L40_min( Word40 L40_var1, Word40 L40_var2 );
     110             : Word32 L_saturate40( Word40 L40_var1 );
     111             : Word16 norm_L40( Word40 L40_var1 );
     112             : /*
     113             :  * Overflowing operators
     114             :  */
     115             : Word40 L40_shl_o( Word40 L40_var1, Word16 var2, Flag *Overflow );
     116             : Word40 L40_add_o( Word40 L40_var1, Word40 L40_var2, Flag *Overflow );
     117             : Word40 L40_sub_o( Word40 L40_var1, Word40 L40_var2, Flag *Overflow );
     118             : Word32 L_saturate40_o( Word40 L40_var1, Flag *Overflow );
     119             : /*#ifdef _MSC_VER*/
     120           0 : static __inline Word40 L40_set( Word40 L40_var1 )
     121             : {
     122             :     Word40 L40_var_out;
     123             : 
     124             : #if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
     125             :     L40_var_out = L40_var1 & 0x000000ffffffffff;
     126             : 
     127             :     if ( L40_var1 & 0x8000000000 )
     128             :         L40_var_out = L40_var_out | 0xffffff0000000000;
     129             : #else
     130           0 :     L40_var_out = L40_var1 & 0x000000ffffffffffLL;
     131             : 
     132           0 :     if ( L40_var1 & 0x8000000000LL )
     133           0 :         L40_var_out = L40_var_out | 0xffffff0000000000LL;
     134             : #endif
     135             : 
     136             : #ifdef WMOPS
     137             :     multiCounter[currCounter].L40_set++;
     138             : #endif
     139             : 
     140           0 :     return ( L40_var_out );
     141             : }
     142             : /*#endif*/ /* ifdef _MSC_VER */
     143             : 
     144             : 
     145             : static __inline UWord16 Extract40_H( Word40 L40_var1 )
     146             : {
     147             :     UWord16 var_out;
     148             : 
     149             :     var_out = (UWord16) ( L40_var1 >> 16 );
     150             : 
     151             : #ifdef WMOPS
     152             :     multiCounter[currCounter].Extract40_H++;
     153             : #endif
     154             : 
     155             :     return ( var_out );
     156             : }
     157             : 
     158             : 
     159  4570598873 : static __inline UWord16 Extract40_L( Word40 L40_var1 )
     160             : {
     161             :     UWord16 var_out;
     162             : 
     163  4570598873 :     var_out = (UWord16) ( L40_var1 );
     164             : 
     165             : #ifdef WMOPS
     166             :     multiCounter[currCounter].Extract40_L++;
     167             : #endif
     168             : 
     169  4570598873 :     return ( var_out );
     170             : }
     171             : 
     172             : 
     173  4640510426 : static __inline UWord32 L_Extract40( Word40 L40_var1 )
     174             : {
     175             :     UWord32 L_var_out;
     176             : 
     177  4640510426 :     L_var_out = (UWord32) L40_var1;
     178             : 
     179             : #ifdef WMOPS
     180             :     multiCounter[currCounter].L_Extract40++;
     181             : #endif
     182             : 
     183  4640510426 :     return ( L_var_out );
     184             : }
     185             : 
     186             : 
     187             : static __inline Word40 L40_deposit_h( Word16 var1 )
     188             : {
     189             :     Word40 L40_var_out;
     190             : 
     191             :     L40_var_out = ( (Word40) var1 ) << 16;
     192             : 
     193             : #if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
     194             :     if ( var1 & 0x8000 )
     195             :     {
     196             :         L40_var_out = L40_set( L40_var_out | 0xff00000000 );
     197             : 
     198             : #ifdef WMOPS
     199             :         multiCounter[currCounter].L40_set--;
     200             : #endif
     201             :     }
     202             : #else
     203             :     if ( var1 & 0x8000 )
     204             :     {
     205             :         L40_var_out = L40_set( L40_var_out | 0xff00000000LL );
     206             : 
     207             : #ifdef WMOPS
     208             :         multiCounter[currCounter].L40_set--;
     209             : #endif
     210             :     }
     211             : #endif
     212             : 
     213             : #ifdef WMOPS
     214             :     multiCounter[currCounter].L40_deposit_h++;
     215             : #endif
     216             : 
     217             :     return ( L40_var_out );
     218             : }
     219             : 
     220             : 
     221             : static __inline Word40 L40_deposit_l( Word16 var1 )
     222             : {
     223             :     Word40 L40_var_out;
     224             : 
     225             :     L40_var_out = var1;
     226             : 
     227             : #if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
     228             :     if ( var1 & 0x8000 )
     229             :     {
     230             :         L40_var_out = L40_set( L40_var_out | 0xffffff0000 );
     231             : 
     232             : #ifdef WMOPS
     233             :         multiCounter[currCounter].L40_set--;
     234             : #endif
     235             :     }
     236             : #else
     237             :     if ( var1 & 0x8000 )
     238             :     {
     239             :         L40_var_out = L40_set( L40_var_out | 0xffffff0000LL );
     240             : 
     241             : #ifdef WMOPS
     242             :         multiCounter[currCounter].L40_set--;
     243             : #endif
     244             :     }
     245             : #endif
     246             : 
     247             : #ifdef WMOPS
     248             :     multiCounter[currCounter].L40_deposit_l++;
     249             : #endif
     250             : 
     251             :     return ( L40_var_out );
     252             : }
     253             : 
     254             : 
     255             : static __inline Word40 L40_deposit32( Word32 L_var1 )
     256             : {
     257             :     Word40 L40_var_out;
     258             : 
     259             :     L40_var_out = (Word40) L_var1;
     260             : 
     261             : #if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
     262             :     if ( L_var1 & 0x80000000 )
     263             :     {
     264             :         L40_var_out = L40_set( L40_var_out | 0xff00000000 );
     265             : 
     266             : #ifdef WMOPS
     267             :         multiCounter[currCounter].L40_set--;
     268             : #endif
     269             :     }
     270             : #else
     271             :     if ( L_var1 & 0x80000000 )
     272             :     {
     273             :         L40_var_out = L40_set( L40_var_out | 0xff00000000LL );
     274             : 
     275             : #ifdef WMOPS
     276             :         multiCounter[currCounter].L40_set--;
     277             : #endif
     278             :     }
     279             : #endif
     280             : 
     281             : #ifdef WMOPS
     282             :     multiCounter[currCounter].L40_deposit32++;
     283             : #endif
     284             : 
     285             :     return ( L40_var_out );
     286             : }
     287             : 
     288             : 
     289             : static __inline Word40 L40_round( Word40 L40_var1 )
     290             : {
     291             :     Word40 L40_var_out;
     292             :     Word40 L40_constant;
     293             : 
     294             : #if defined( _MSC_VER ) && ( _MSC_VER <= 1200 )
     295             :     L40_constant = L40_set( 0xffffff0000 );
     296             : #else
     297             :     L40_constant = L40_set( 0xffffff0000LL );
     298             : #endif
     299             : 
     300             :     L40_var_out = L40_add( 0x8000, L40_var1 );
     301             :     L40_var_out = L40_var_out & L40_constant;
     302             : 
     303             : #ifdef WMOPS
     304             :     multiCounter[currCounter].L40_set--;
     305             :     multiCounter[currCounter].L40_add--;
     306             :     multiCounter[currCounter].L40_round++;
     307             : #endif
     308             : 
     309             :     return ( L40_var_out );
     310             : }
     311             : 
     312             : 
     313             : static __inline Word16 round40( Word40 L40_var1 )
     314             : {
     315             :     Word16 var_out;
     316             : 
     317             :     var_out = extract_h( L_saturate40( L40_round( L40_var1 ) ) );
     318             : 
     319             : #ifdef WMOPS
     320             :     multiCounter[currCounter].L40_round--;
     321             :     multiCounter[currCounter].L_saturate40--;
     322             :     multiCounter[currCounter].extract_h--;
     323             :     multiCounter[currCounter].round40++;
     324             : #endif
     325             : 
     326             :     return ( var_out );
     327             : }
     328             : 
     329             : 
     330  4593902724 : static __inline Word40 L40_mult( Word16 var1, Word16 var2 )
     331             : {
     332             :     Word32 L_var_out;
     333             :     Word40 L40_var_out;
     334             : 
     335  4593902724 :     L_var_out = (Word32) var1 * (Word32) var2;
     336  4593902724 :     L40_var_out = (Word40) L_var_out;
     337             : 
     338             :     /* Below line can not overflow, so we can use << instead of L40_shl. */
     339  4593902724 :     L40_var_out = L40_var_out << 1;
     340             : 
     341             : #ifdef WMOPS
     342             :     multiCounter[currCounter].L40_mult++;
     343             : #endif
     344             : 
     345  4593902724 :     return ( L40_var_out );
     346             : }
     347             : 
     348             : 
     349  4593902724 : static __inline Word40 L40_mac( Word40 L40_var1, Word16 var2, Word16 var3 )
     350             : {
     351             :     Word40 L40_var_out;
     352             : 
     353  4593902724 :     L40_var_out = L40_mult( var2, var3 );
     354  4593902724 :     L40_var_out = L40_add( L40_var1, L40_var_out );
     355             : 
     356             : #ifdef WMOPS
     357             :     multiCounter[currCounter].L40_mac++;
     358             : #endif
     359             : 
     360  4593902724 :     return ( L40_var_out );
     361             : }
     362             : 
     363             : 
     364             : static __inline Word16 mac_r40( Word40 L40_var1, Word16 var2, Word16 var3 )
     365             : {
     366             :     Word40 L40_var_out;
     367             :     Word16 var_out;
     368             : 
     369             :     L40_var_out = L40_mac( L40_var1, var2, var3 );
     370             :     var_out = round40( L40_var_out );
     371             : 
     372             : 
     373             :     return ( var_out );
     374             : }
     375             : 
     376             : 
     377             : static __inline Word40 L40_msu( Word40 L40_var1, Word16 var2, Word16 var3 )
     378             : {
     379             :     Word40 L40_var_out;
     380             : 
     381             :     L40_var_out = L40_mult( var2, var3 );
     382             :     L40_var_out = L40_sub( L40_var1, L40_var_out );
     383             : 
     384             : 
     385             :     return ( L40_var_out );
     386             : }
     387             : 
     388             : 
     389             : static __inline Word16 msu_r40( Word40 L40_var1, Word16 var2, Word16 var3 )
     390             : {
     391             :     Word40 L40_var_out;
     392             :     Word16 var_out;
     393             : 
     394             :     L40_var_out = L40_msu( L40_var1, var2, var3 );
     395             :     var_out = round40( L40_var_out );
     396             : 
     397             : 
     398             :     return ( var_out );
     399             : }
     400             : 
     401             : 
     402             : #endif /*_ENH40_H*/
     403             : 
     404             : 
     405             : /* end of file */

Generated by: LCOV version 1.14