LCOV - code coverage report
Current view: top level - lib_com - longarith.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 38 44 86.4 %
Date: 2025-05-23 08:37:30 Functions: 3 3 100.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             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <assert.h>
      38             : #include <stdint.h>
      39             : #include "options.h"
      40             : #include "prot.h"
      41             : #include "wmc_auto.h"
      42             : 
      43             : 
      44             : /*-------------------------------------------------------------------*
      45             :  * longadd()
      46             :  *
      47             :  * long addition: a[] = a[] + b[]
      48             :  * Addition of unsigned vectors a[] and b[] without saturation.
      49             :  * All words of b[] are added with carry to the corresponding words in a.
      50             :  * An assertion failure occurs, if lenb exceeds lena or if overflow occurs.
      51             :  *--------------------------------------------------------------------*/
      52             : 
      53      164265 : void longadd(
      54             :     uint16_t a[],       /* i/o: vector of the length lena */
      55             :     const uint16_t b[], /* i/o: vector of the length lenb */
      56             :     const int16_t lena, /* i/o: length of vector a[]      */
      57             :     const int16_t lenb  /* i/o: length of vector b[]      */
      58             : )
      59             : {
      60             :     int16_t h;
      61      164265 :     int32_t carry = 0;
      62             : 
      63      164265 :     assert( lena >= lenb );
      64      328530 :     for ( h = 0; h < lenb; h++ )
      65             :     {
      66      164265 :         carry += ( (uint32_t) a[h] ) + ( (uint32_t) b[h] );
      67      164265 :         a[h] = (uint16_t) carry;
      68      164265 :         carry = carry >> 16;
      69             :     }
      70             : 
      71      466447 :     for ( ; h < lena; h++ )
      72             :     {
      73      302182 :         carry = ( (uint32_t) a[h] ) + carry;
      74      302182 :         a[h] = (uint16_t) carry;
      75      302182 :         carry = carry >> 16;
      76             :     }
      77             : 
      78      164265 :     assert( carry == 0 ); /* carry != 0 indicates addition overflow */
      79      164265 :     return;
      80             : }
      81             : 
      82             : 
      83             : /*-------------------------------------------------------------------*
      84             :  * longshiftright()
      85             :  *
      86             :  * long shift right: d[] = a[] >> b
      87             :  * Logical shift right of unsigned vectors a[] by b bit-positions.
      88             :  * Vector d[] is filled with leading zeroes, where lend exceeds lena.
      89             :  * It is allowed to overlay d[] with a[].
      90             :  *--------------------------------------------------------------------*/
      91             : 
      92      472494 : void longshiftright(
      93             :     uint16_t a[],      /* i  : vector of the length lena                */
      94             :     const int16_t b,   /* i  : number of bit positions to shift right   */
      95             :     uint16_t d[],      /* o  : vector of the length lend                */
      96             :     int16_t lena,      /* i  : length of vector a[]                     */
      97             :     const int16_t lend /* i  : length of vector d[]                     */
      98             : )
      99             : {
     100             :     int16_t intb, fracb, fracb_u, k;
     101             : 
     102      472494 :     intb = b >> 4;
     103             : 
     104      472494 :     a += intb;
     105      472494 :     lena -= intb;
     106             : 
     107      472494 :     fracb = b & 0xF;
     108      472494 :     if ( fracb )
     109             :     {
     110      472494 :         fracb_u = 16 - fracb;
     111     1336056 :         for ( k = 0; k < lena - 1; k++ )
     112             :         {
     113      863562 :             d[k] = ( ( a[k] >> fracb ) | ( a[k + 1] << fracb_u ) ) & 0xFFFF;
     114             :         }
     115      472494 :         d[k] = ( a[k] >> fracb );
     116      472494 :         k++;
     117             :     }
     118             :     else
     119             :     {
     120           0 :         for ( k = 0; k < lena; k++ )
     121             :         {
     122           0 :             d[k] = a[k];
     123             :         }
     124             :     }
     125             : 
     126             :     /* fill remaining upper bits with zero */
     127      472494 :     for ( ; k < lend; k++ )
     128             :     {
     129           0 :         d[k] = 0;
     130             :     }
     131             : 
     132      472494 :     return;
     133             : }
     134             : 
     135             : 
     136             : /*-------------------------------------------------------------------*
     137             :  * longshiftleft()
     138             :  *
     139             :  * long shift left: d[] = a[] << b
     140             :  * Logical shift left of unsigned vectors a[] by b bit-positions.
     141             :  * It is allowed to overlay d[] with a[].
     142             :  *--------------------------------------------------------------------*/
     143             : 
     144      164265 : void longshiftleft(
     145             :     const uint16_t a[], /* i  : vector of the length len              */
     146             :     const int16_t b,    /* i  : number of bit positions to shift left */
     147             :     uint16_t d[],       /* o  : vector of the length len              */
     148             :     const int16_t len   /* i  : length of vector a[] and d[]          */
     149             : )
     150             : {
     151             :     int16_t intb;    /* integer part of b */
     152             :     int16_t fracb;   /* shift left value for all upper words a[k] */
     153             :     int16_t fracb_l; /* shift right value for all lower words a[k-1] */
     154      164265 :     int16_t k = len - 1;
     155             : 
     156      164265 :     intb = b >> 4;
     157      164265 :     fracb = b & 0xF;
     158             : 
     159      164265 :     if ( fracb )
     160             :     {
     161      164265 :         fracb_l = 16 - fracb;
     162      466447 :         for ( ; k > intb; k-- )
     163             :         {
     164      302182 :             d[k] = ( a[k - intb] << fracb ) | ( a[k - intb - 1] >> fracb_l );
     165             :         }
     166      164265 :         d[k] = ( a[k - intb] << fracb );
     167      164265 :         k--;
     168             :     }
     169             :     else
     170             :     {
     171           0 :         for ( ; k >= intb; k-- )
     172             :         {
     173           0 :             d[k] = a[k - intb];
     174             :         }
     175             :     }
     176             : 
     177      164265 :     for ( ; k >= 0; k-- )
     178             :     {
     179           0 :         d[k] = 0;
     180             :     }
     181             : 
     182      164265 :     return;
     183             : }

Generated by: LCOV version 1.14