LCOV - code coverage report
Current view: top level - lib_dec - ari_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- merged total coverage @ a21f94bc6bac334fe001a5bad2f7b32b79038097 Lines: 225 228 98.7 %
Date: 2025-11-01 08:50:45 Functions: 7 7 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 "cnst.h"
      41             : #include "prot.h"
      42             : #include "stat_com.h"
      43             : #include "basop_util.h"
      44             : #include "wmc_auto.h"
      45             : 
      46             : 
      47             : /*---------------------------------------------------------------
      48             :  * Ari decode 14 bits routines
      49             :   -------------------------------------------------------------*/
      50             : 
      51             : /*---------------------------------------------------------------
      52             :  * ari_start_decoding_14bits()
      53             :  *
      54             :  * Start ArCo decoding
      55             :  *-------------------------------------------------------------*/
      56             : 
      57    30389773 : void ari_start_decoding_14bits(
      58             :     Decoder_State *st,
      59             :     Tastat *s )
      60             : {
      61             :     uint32_t val;
      62             : 
      63    30389773 :     val = get_next_indice( st, cbitsnew );
      64             : 
      65    30389773 :     s->low = 0;
      66    30389773 :     s->high = ari_q4new;
      67    30389773 :     s->value = val;
      68             : 
      69    30389773 :     return;
      70             : }
      71             : 
      72             : /*---------------------------------------------------------------
      73             :  * ari_start_decoding_14bits_prm()
      74             :  *
      75             :  * Start ArCo decoding
      76             :  *-------------------------------------------------------------*/
      77             : 
      78      836894 : int16_t ari_start_decoding_14bits_prm(
      79             :     const int16_t *ptr,
      80             :     int16_t bp,
      81             :     Tastat *s )
      82             : {
      83             :     int32_t val;
      84             :     int16_t i;
      85             :     const int16_t *p;
      86             : 
      87      836894 :     val = 0;
      88      836894 :     p = ptr + bp;
      89    14227198 :     for ( i = 0; i < cbitsnew; i++ )
      90             :     {
      91    13390304 :         val = ( val << 1 ) | *( p + i );
      92             :     }
      93             : 
      94      836894 :     s->low = 0;
      95      836894 :     s->high = ari_q4new;
      96      836894 :     s->value = val;
      97             : 
      98      836894 :     bp = bp + i;
      99             : 
     100      836894 :     return bp;
     101             : }
     102             : 
     103             : /*---------------------------------------------------------------
     104             :  * ari_decode_14bits_s17_ext()
     105             :  *
     106             :  * Only for 17 symbols with new extended Tables:
     107             :  * based on tri's optimization
     108             :  * based on extended Tables which need less branches for coding
     109             :  *-------------------------------------------------------------*/
     110             : 
     111     8640605 : void ari_decode_14bits_s17_ext(
     112             :     Decoder_State *st,
     113             :     uint16_t *res,
     114             :     Tastat *s,
     115             :     const uint16_t *cum_freq )
     116             : {
     117             :     uint16_t symbol;
     118             :     int32_t low, high;
     119             :     uint32_t range, value, cum;
     120             :     const uint16_t *p;
     121             : 
     122             :     /* read s->low,high,value sequentially */
     123     8640605 :     low = s->low;
     124     8640605 :     high = s->high;
     125     8640605 :     value = s->value;
     126             : 
     127     8640605 :     range = high - low + 1; /* keep: tmp=low-1 */
     128     8640605 :     cum = ( ( ( (uint32_t) ( value - low + 1 ) ) << stat_bitsnew ) - ( (uint32_t) 1 ) );
     129             : 
     130     8640605 :     p = cum_freq;
     131             : 
     132             :     /* Note: For each indirect addressing p[i], we assume a tmp pointer init followed by a costfree reading the value */
     133             :     /* If the value multiplied by range is greater than cum, the pointer p is set to the tmp pointer                  */
     134             :     /*    tmp_p = p+8; if (tmp_p[0]*range>cum) p = tmp_p;                                                             */
     135             : 
     136     8640605 :     if ( p[8] * range > cum )
     137             :     {
     138     2799143 :         p += 8;
     139             :     }
     140             :     /*  */
     141     8640605 :     if ( p[4] * range > cum )
     142             :     {
     143     3667229 :         p += 4;
     144             :     }
     145             :     /*  */
     146     8640605 :     if ( p[2] * range > cum )
     147             :     {
     148     2796452 :         p += 2;
     149             :     }
     150             :     /*  */
     151     8640605 :     if ( p[1] * range > cum )
     152             :     {
     153     3674227 :         p += 1;
     154     3674227 :         if ( ( p == cum_freq + 15 ) && ( p[1] * range > cum ) )
     155             :         {
     156     1715531 :             p += 1;
     157             :         }
     158             :     }
     159             : 
     160     8640605 :     symbol = (uint16_t) ( p - cum_freq );
     161             : 
     162     8640605 :     high = low + mul_sbc_14bits( range, cum_freq[symbol] ) - 1;
     163     8640605 :     low += mul_sbc_14bits( range, cum_freq[symbol + 1] );
     164             : 
     165             :     for ( ;; )
     166             :     {
     167    28878324 :         if ( high >= ari_q2new )
     168             :         {
     169    21545317 :             if ( low >= ari_q2new )
     170             :             {
     171     7401598 :                 value -= ari_q2new;
     172     7401598 :                 low -= ari_q2new;
     173     7401598 :                 high -= ari_q2new;
     174             :             }
     175             :             else
     176             :             {
     177    14143719 :                 if ( low >= ari_q1new && high < ari_q3new )
     178             :                 {
     179     5503114 :                     value -= ari_q1new;
     180     5503114 :                     low -= ari_q1new;
     181     5503114 :                     high -= ari_q1new;
     182             :                 }
     183             :                 else
     184             :                 {
     185             :                     break;
     186             :                 }
     187             :             }
     188             :         }
     189    20237719 :         low += low;
     190    20237719 :         high += high + 1;
     191             : 
     192    20237719 :         value = ( value << 1 ) | get_next_indice_1( st );
     193             :     }
     194             : 
     195     8640605 :     s->low = low;
     196     8640605 :     s->high = high;
     197     8640605 :     s->value = value;
     198             : 
     199     8640605 :     *res = symbol;
     200             : 
     201     8640605 :     return;
     202             : }
     203             : 
     204             : 
     205             : /*---------------------------------------------------------------
     206             :  * ari_decode_14bits_s27_ext()
     207             :  *
     208             :  * Only for 17 symbols with new extended Tables:
     209             :  * based on tri's optimization
     210             :  * based on extended Tables which need less branches for coding
     211             :  * copied from ari_decode_14bits_s17_ext, with changes marked
     212             :  *-------------------------------------------------------------*/
     213             : 
     214   167816520 : void ari_decode_14bits_s27_ext(
     215             :     Decoder_State *st,
     216             :     uint16_t *res,
     217             :     Tastat *s,
     218             :     const uint16_t *cum_freq )
     219             : {
     220             :     uint16_t symbol;
     221             :     int32_t low, high;
     222             :     uint32_t range, value, cum;
     223             :     uint16_t il, ih, im;
     224             : 
     225             :     /* read s->low,high,value sequentially */
     226   167816520 :     low = s->low;
     227   167816520 :     high = s->high;
     228   167816520 :     value = s->value;
     229             : 
     230   167816520 :     range = high - low + 1; /* keep: tmp=low-1 */
     231   167816520 :     cum = ( ( ( (uint32_t) ( value - low + 1 ) ) << stat_bitsnew ) - ( (uint32_t) 1 ) );
     232             : 
     233             : 
     234             :     /* Note: For each indirect addressing p[i], we assume a tmp pointer init followed by a costfree reading the value */
     235             :     /* If the value multiplied by range is greater than cum, the pointer p is set to the tmp pointer                  */
     236             :     /*    tmp_p = p+8; if (tmp_p[0]*range>cum) p = tmp_p;                                                             */
     237             : 
     238             :     /* begin change when compared with ari_decode_14bits_s17_ext,
     239             :        starting with line: if (p[8] * range > cum) { */
     240   167816520 :     il = 0;
     241   167816520 :     ih = 27;
     242             : 
     243             :     /* do a five step binary search, using the interval [il, ih) */
     244   167816520 :     im = 13; /* (il + ih) >> 1 */
     245   167816520 :     if ( cum_freq[im] * range > cum )
     246             :     {
     247   104346556 :         il = im;
     248             :     }
     249             :     else
     250             :     {
     251    63469964 :         ih = im;
     252             :     }
     253             : 
     254   167816520 :     im = ( il + ih ) >> 1;
     255   167816520 :     if ( cum_freq[im] * range > cum )
     256             :     {
     257    63854282 :         il = im;
     258             :     }
     259             :     else
     260             :     {
     261   103962238 :         ih = im;
     262             :     }
     263             : 
     264   167816520 :     im = ( il + ih ) >> 1;
     265   167816520 :     if ( cum_freq[im] * range > cum )
     266             :     {
     267    83182265 :         il = im;
     268             :     }
     269             :     else
     270             :     {
     271    84634255 :         ih = im;
     272             :     }
     273             : 
     274   167816520 :     im = ( il + ih ) >> 1;
     275   167816520 :     if ( cum_freq[im] * range > cum )
     276             :     {
     277    98081356 :         il = im;
     278             :     }
     279             :     else
     280             :     {
     281    69735164 :         ih = im;
     282             :     }
     283             : 
     284   167816520 :     if ( ih - il > 1 ) /* if the interval has more than one symbol */
     285             :     {
     286             :         /* here, only ih == il + 2 is possible, which means two symbols in the interval */
     287   142516678 :         im = il + 1; /* (il + ih) >> 1 */
     288   142516678 :         if ( cum_freq[im] * range > cum )
     289             :         {
     290    69414342 :             il = im;
     291             :         }
     292             :     }
     293             : 
     294   167816520 :     symbol = il;
     295             :     /* end change when compared with ari_decode_14bits_s17_ext,
     296             :        ending with line: symbol = p - cum_freq; */
     297             : 
     298   167816520 :     high = low + mul_sbc_14bits( range, cum_freq[symbol] ) - 1;
     299   167816520 :     low += mul_sbc_14bits( range, cum_freq[symbol + 1] );
     300             : 
     301             :     for ( ;; )
     302             :     {
     303   761213916 :         if ( high >= ari_q2new )
     304             :         {
     305   531156613 :             if ( low >= ari_q2new )
     306             :             {
     307   225494146 :                 value -= ari_q2new;
     308   225494146 :                 low -= ari_q2new;
     309   225494146 :                 high -= ari_q2new;
     310             :             }
     311             :             else
     312             :             {
     313   305662467 :                 if ( low >= ari_q1new && high < ari_q3new )
     314             :                 {
     315   137845947 :                     value -= ari_q1new;
     316   137845947 :                     low -= ari_q1new;
     317   137845947 :                     high -= ari_q1new;
     318             :                 }
     319             :                 else
     320             :                 {
     321             :                     break;
     322             :                 }
     323             :             }
     324             :         }
     325   593397396 :         low += low;
     326   593397396 :         high += high + 1;
     327             : 
     328   593397396 :         value = ( value << 1 ) | get_next_indice_1( st );
     329             :     }
     330             : 
     331   167816520 :     s->low = low;
     332   167816520 :     s->high = high;
     333   167816520 :     s->value = value;
     334             : 
     335   167816520 :     *res = symbol;
     336             : 
     337   167816520 :     return;
     338             : }
     339             : 
     340             : 
     341             : /*---------------------------------------------------------------
     342             :  * ari_decode_14bits_bit_ext()
     343             :  *
     344             :  * Only for decoding one bit with uniform probability:
     345             :  * based on tri's optimization
     346             :  * copied from ari_decode_14bits_s17_ext, with changes marked
     347             :  * the equivalent cum_freq table used is {16384, 8192, 0}
     348             :  *-------------------------------------------------------------*/
     349             : 
     350    61357888 : void ari_decode_14bits_bit_ext(
     351             :     Decoder_State *st,
     352             :     uint16_t *res,
     353             :     Tastat *s )
     354             : {
     355             :     uint16_t symbol;
     356             :     int32_t low, high;
     357             :     uint32_t range, value, cum;
     358             : 
     359             :     /* read s->low,high,value sequentially */
     360    61357888 :     low = s->low;
     361    61357888 :     high = s->high;
     362    61357888 :     value = s->value;
     363             : 
     364    61357888 :     range = high - low + 1; /* keep: tmp=low-1 */
     365    61357888 :     cum = ( ( ( (uint32_t) ( value - low + 1 ) ) << stat_bitsnew ) - ( (uint32_t) 1 ) );
     366             : 
     367             : 
     368             :     /* Note: For each indirect addressing p[i], we assume a tmp pointer init followed by a costfree reading the value */
     369             :     /* If the value multiplied by range is greater than cum, the pointer p is set to the tmp pointer                  */
     370             :     /*    tmp_p = p+8; if (tmp_p[0]*range>cum) p = tmp_p;                                                             */
     371             : 
     372             :     /* begin change when compared with ari_decode_14bits_s17_ext,
     373             :        starting with line: if (p[8] * range > cum) { */
     374    61357888 :     symbol = 0;
     375             : 
     376    61357888 :     if ( ( range << 13 ) > cum )
     377             :     {
     378    29959191 :         symbol = 1;
     379             :     }
     380             : 
     381    61357888 :     if ( symbol == 0 )
     382             :     {
     383             :         /* high is unchanged */
     384    31398697 :         low = low + ( range >> 1 );
     385             :     }
     386             :     else
     387             :     {
     388    29959191 :         high = low + ( range >> 1 ) - 1;
     389             :         /* low is unchanged */
     390             :     }
     391             :     /* end change when compared with ari_decode_14bits_s17_ext,
     392             :        ending with line: low += mul_sbc_14bits(range, cum_freq[symbol + 1]); */
     393             : 
     394             : 
     395             :     for ( ;; )
     396             :     {
     397   123406687 :         if ( high >= ari_q2new )
     398             :         {
     399   112405049 :             if ( low >= ari_q2new )
     400             :             {
     401    19999193 :                 value -= ari_q2new;
     402    19999193 :                 low -= ari_q2new;
     403    19999193 :                 high -= ari_q2new;
     404             :             }
     405             :             else
     406             :             {
     407    92405856 :                 if ( low >= ari_q1new && high < ari_q3new )
     408             :                 {
     409    31047968 :                     value -= ari_q1new;
     410    31047968 :                     low -= ari_q1new;
     411    31047968 :                     high -= ari_q1new;
     412             :                 }
     413             :                 else
     414             :                 {
     415             :                     break;
     416             :                 }
     417             :             }
     418             :         }
     419    62048799 :         low += low;
     420    62048799 :         high += high + 1;
     421             : 
     422    62048799 :         value = ( value << 1 ) | get_next_indice_1( st );
     423             :     }
     424             : 
     425    61357888 :     s->low = low;
     426    61357888 :     s->high = high;
     427    61357888 :     s->value = value;
     428             : 
     429    61357888 :     *res = symbol;
     430             : 
     431    61357888 :     return;
     432             : }
     433             : 
     434             : /*------------------------------------------------------------------------
     435             :  * Function: ari_decode_14bits_pow()
     436             :  *
     437             :  * Decode a symbol which follows the exponential distribution. That is,
     438             :  * symbols are in the following intervals
     439             :  *
     440             :  * p(x = 0) = 1 - exp(- 0.5 * base * 2)
     441             :  * p(x = q>0) = exp(- (q-0.5)*base* 2) - exp(- (q+0.5)*base*2 )
     442             :  *
     443             :  *-------------------------------------------------------------------------*/
     444             : 
     445   465849046 : int16_t ari_decode_14bits_pow(
     446             :     const int16_t *ptr,
     447             :     int16_t bp,
     448             :     int16_t bits,
     449             :     int16_t *res,
     450             :     Tastat *s,
     451             :     uint16_t base )
     452             : {
     453             :     uint16_t symbol;
     454             :     int32_t low, high;
     455             :     uint32_t range, value, cum;
     456             :     Word16 pows[12]; /* "base" to the power of 2, 4, 8,... 2^12 */
     457   465849046 :     Word16 lowlim, highlim = 0, testval;
     458             :     int16_t k;
     459             : 
     460   465849046 :     low = s->low;
     461   465849046 :     high = s->high + 1;
     462   465849046 :     value = s->value;
     463   465849046 :     lowlim = 0;
     464   465849046 :     symbol = 0;
     465             : 
     466   465849046 :     range = high - low;
     467             : 
     468             :     /* the value read from bitstream */
     469   465849046 :     assert( value >= (uint32_t) low );
     470   465849046 :     cum = ( ( ( (uint32_t) ( value - low ) ) << stat_bitsnew ) + ( 1 << stat_bitsnew ) - 1 );
     471             : 
     472             :     /* search for the interval where "cum" fits */
     473   465849046 :     if ( ( ( base >> 1 ) * range ) > cum ) /* below pow-1 */
     474             :     {
     475    23455503 :         pows[0] = testval = base;
     476             :         /* increase exponent until it is smaller than "cum" */
     477    38319762 :         for ( k = 1; k < 12; k++ )
     478             :         {
     479    38319762 :             highlim = testval;
     480    38319762 :             pows[k] = mult_r( pows[k - 1], pows[k - 1] );
     481    38319762 :             move16();
     482    38319762 :             testval = mult_r( pows[k], base );
     483    38319762 :             if ( ( ( testval >> 1 ) * range ) <= cum ) /* found! big range is [lowlim,testval], (now narrow it down) */
     484             :             {
     485    23455503 :                 lowlim = testval;
     486    23455503 :                 k--;
     487    23455503 :                 symbol = 1 << k;
     488    23455503 :                 break;
     489             :             }
     490             :         }
     491    23455503 :         assert( k < 12 ); /* maximum 2^10-1*/
     492             :         /* narrow the range down */
     493    30456490 :         for ( k--; k > 0; k-- )
     494             :         {
     495     7000987 :             testval = mult_r( highlim, pows[k] );
     496     7000987 :             if ( ( ( testval >> 1 ) * range ) <= cum )
     497             :             {
     498     4473162 :                 lowlim = testval;
     499     4473162 :                 symbol -= 1 << ( k - 1 );
     500             :             }
     501             :             else
     502             :             {
     503     2527825 :                 highlim = testval;
     504             :             }
     505             :         }
     506    23455503 :         highlim >>= 1;
     507    23455503 :         lowlim >>= 1;
     508             :     }
     509             :     else /* trivial case, above pow-1, that is, first symbol */
     510             :     {
     511   442393543 :         symbol = 0;
     512   442393543 :         lowlim = base >> 1;
     513   442393543 :         highlim = 16384;
     514             :     }
     515             : 
     516             : 
     517   465849046 :     high = low + mul_sbc_14bits( range, highlim );
     518             : 
     519   465849046 :     low += mul_sbc_14bits( range, lowlim );
     520             : 
     521             :     /*ptr init for ptr*/
     522   576362556 :     for ( ; bp < bits; )
     523             :     {
     524   301534708 :         if ( high > ari_q2new )
     525             :         {
     526   269745298 :             if ( low >= ari_q2new )
     527             :             {
     528    48834295 :                 value -= ari_q2new;
     529    48834295 :                 low -= ari_q2new;
     530    48834295 :                 high -= ari_q2new;
     531             :             }
     532             :             else
     533             :             {
     534   220911003 :                 if ( low >= ari_q1new && high <= ari_q3new )
     535             :                 {
     536    29889805 :                     value -= ari_q1new;
     537    29889805 :                     low -= ari_q1new;
     538    29889805 :                     high -= ari_q1new;
     539             :                 }
     540             :                 else
     541             :                 {
     542             :                     break;
     543             :                 }
     544             :             }
     545             :         }
     546   110513510 :         low += low;
     547   110513510 :         high += high;
     548             : 
     549   110513510 :         assert( abs( ptr[bp] ) <= 1 && "AC expects reading binary values!!!" );
     550             : 
     551   110513510 :         value = ( value << 1 ) | ptr[bp++];
     552             :     }
     553             : 
     554   465849046 :     if ( !( bp != bits || !( ( s->low == low ) && ( s->high == high ) && ( s->value == value ) ) ) )
     555             :     {
     556             :         /* This should not happen except of bit errors. */
     557           0 :         s->high = s->low = 0;
     558           0 :         *res = 0;
     559           0 :         return -1;
     560             :     }
     561             : 
     562   465849046 :     s->low = low;
     563   465849046 :     s->high = high - 1;
     564   465849046 :     s->value = value;
     565             : 
     566   465849046 :     *res = symbol;
     567             : 
     568   465849046 :     return bp;
     569             : }
     570             : 
     571             : 
     572             : /*------------------------------------------------------------------------
     573             :  * Function: ari_decode_14bits_sign()
     574             :  *
     575             :  * Decode a sign with equal probabilities.
     576             :  *-------------------------------------------------------------------------*/
     577             : 
     578    23455503 : int16_t ari_decode_14bits_sign(
     579             :     const int16_t *ptr,
     580             :     int16_t bp,
     581             :     int16_t bits,
     582             :     uint16_t *res,
     583             :     Tastat *s )
     584             : {
     585             :     uint16_t symbol;
     586             :     int32_t low, high;
     587             :     uint32_t range, value, cum;
     588             : 
     589    23455503 :     low = s->low;
     590    23455503 :     high = s->high + 1;
     591    23455503 :     value = s->value;
     592             : 
     593    23455503 :     range = high - low;
     594             : 
     595    23455503 :     if ( bp < bits )
     596             :     {
     597    22084326 :         assert( value >= (uint32_t) low );
     598    22084326 :         cum = ( ( ( (uint32_t) ( value - low ) ) << stat_bitsnew ) + ( 1 << stat_bitsnew ) - 1 );
     599    22084326 :         if ( 8192 * range > cum )
     600             :         {
     601    11032271 :             symbol = 2;
     602    11032271 :             high = low + ( range >> 1 );
     603             :         }
     604             :         else
     605             :         {
     606    11052055 :             symbol = 1;
     607    11052055 :             low += range >> 1;
     608             :         }
     609             : 
     610             :         /*ptr init for ptr*/
     611    44169843 :         for ( ; bp < bits; )
     612             :         {
     613    44070463 :             if ( high > ari_q2new )
     614             :             {
     615    38477887 :                 if ( low >= ari_q2new )
     616             :                 {
     617     5522134 :                     value -= ari_q2new;
     618     5522134 :                     low -= ari_q2new;
     619     5522134 :                     high -= ari_q2new;
     620             :                 }
     621             :                 else
     622             :                 {
     623    32955753 :                     if ( low >= ari_q1new && high <= ari_q3new )
     624             :                     {
     625    10970807 :                         value -= ari_q1new;
     626    10970807 :                         low -= ari_q1new;
     627    10970807 :                         high -= ari_q1new;
     628             :                     }
     629             :                     else
     630             :                     {
     631             :                         break;
     632             :                     }
     633             :                 }
     634             :             }
     635    22085517 :             low += low;
     636    22085517 :             high += high;
     637             : 
     638    22085517 :             assert( abs( ptr[bp] ) <= 1 && "AC expects reading binary values!!!" );
     639             : 
     640    22085517 :             value = ( value << 1 ) | ptr[bp++];
     641             :         }
     642             :     }
     643             :     else
     644             :     {
     645     1371177 :         cum = value - low;
     646     1371177 :         range >>= 1;
     647     1371177 :         if ( range > cum )
     648             :         {
     649      691882 :             symbol = 2;
     650      691882 :             high = low + range;
     651             :         }
     652             :         else
     653             :         {
     654      679295 :             symbol = 1;
     655      679295 :             low += range;
     656             :         }
     657             :     }
     658             : 
     659    23455503 :     s->low = low;
     660    23455503 :     s->high = high - 1;
     661    23455503 :     s->value = value;
     662             : 
     663    23455503 :     *res = symbol;
     664             : 
     665    23455503 :     return bp;
     666             : }

Generated by: LCOV version 1.14