LCOV - code coverage report
Current view: top level - lib_enc - range_enc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 205 214 95.8 %
Date: 2025-05-03 01:55:50 Functions: 13 13 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdint.h>
       6             : #include <limits.h>
       7             : #include "options.h"    /* Compilation switches                   */
       8             : #include "cnst.h"       /* Common constants                       */
       9             : #include "rom_com_fx.h" /* Static table prototypes                */
      10             : #include "rom_com.h"    /* Static table prototypes                */
      11             : //#include "prot_fx.h"       /* Function prototypes                    */
      12             : #include "prot_fx.h"     /* Function prototypes                    */
      13             : #include "prot_fx_enc.h" /* Function prototypes                    */
      14             : 
      15             : 
      16             : static void rc_enc_shift_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ );
      17             : static void rc_enc_write_fx( BSTR_ENC_HANDLE hBstr, Word16 byte, Word16 bits );
      18             : static void rc_enc_shift_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ );
      19             : static void rc_enc_write_ivas_fx( BSTR_ENC_HANDLE hBstr, Word16 byte, Word16 bits );
      20             : /*-------------------------------------------------------------------*
      21             :  * rc_enc_init()
      22             :  *
      23             :  *  Initalize range coder
      24             :  *-------------------------------------------------------------------*/
      25             : 
      26       30888 : void rc_enc_init_fx(
      27             :     PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle     */
      28             :     Word16 tot_bits      /* i  : Total bit budget               Q0*/
      29             : )
      30             : {
      31       30888 :     hPVQ->rc_low = L_deposit_l( 0 );
      32       30888 :     hPVQ->rc_range = 0xffffffff;
      33       30888 :     move32();
      34       30888 :     hPVQ->rc_cache = -1;
      35       30888 :     move16();
      36       30888 :     hPVQ->rc_carry = 0;
      37       30888 :     move16();
      38       30888 :     hPVQ->rc_carry_count = 0;
      39       30888 :     move16();
      40       30888 :     hPVQ->rc_num_bits = 0;
      41       30888 :     move16();
      42       30888 :     hPVQ->rc_tot_bits = tot_bits; // Q0
      43       30888 :     move16();
      44       30888 :     hPVQ->rc_offset = 0;
      45       30888 :     move16();
      46             : 
      47       30888 :     return;
      48             : }
      49             : 
      50             : /*-------------------------------------------------------------------*
      51             :  * rc_encode()
      52             :  *
      53             :  *  Encode symbol with range coder
      54             :  *-------------------------------------------------------------------*/
      55      304850 : void rc_encode_ivas_fx(
      56             :     BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                             */
      57             :     PVQ_ENC_HANDLE hPVQ,   /* i/o: PVQ encoder handle                                   */
      58             :     UWord32 cum_freq,      /* i  : Cumulative frequency up to symbol    Q0*/
      59             :     UWord32 sym_freq,      /* i  : Symbol probability                                   Q0*/
      60             :     UWord32 tot            /* i  : Total cumulative frequency                   Q0*/
      61             : )
      62             : {
      63             :     UWord32 r, tmp, inv_tot, lsb;
      64             :     Word16 exp;
      65             :     UWord16 carry;
      66             : 
      67      304850 :     inv_tot = UL_inverse( tot, &exp );                   // Q0
      68      304850 :     Mpy_32_32_uu( hPVQ->rc_range, inv_tot, &tmp, &lsb ); /*0+exp-32 */
      69      304850 :     r = UL_lshr( tmp, sub( exp, 32 ) );                  /* exp-32-exp3+32 = 0 */
      70      304850 :     tmp = UL_Mpy_32_32( r, cum_freq );
      71             : 
      72      304850 :     hPVQ->rc_low = UL_addNs( hPVQ->rc_low, tmp, &carry ); // Q0
      73      304850 :     move32();
      74      304850 :     if ( carry != 0 )
      75             :     {
      76       40078 :         hPVQ->rc_carry = carry; // Q0
      77       40078 :         move16();
      78             :     }
      79             : 
      80      304850 :     hPVQ->rc_range = UL_Mpy_32_32( r, sym_freq ); // Q0
      81      304850 :     move32();
      82      550127 :     WHILE( LT_64( hPVQ->rc_range, 1 << 24 ) )
      83             :     {
      84      245277 :         hPVQ->rc_range = UL_lshl( hPVQ->rc_range, 8 ); // Q0
      85      245277 :         move32();
      86      245277 :         hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, 8 ); // Q0
      87      245277 :         move16();
      88      245277 :         rc_enc_shift_ivas_fx( hBstr, hPVQ );
      89             :     }
      90             : 
      91      304850 :     return;
      92             : }
      93       20213 : void rc_encode_fx(
      94             :     BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                             */
      95             :     PVQ_ENC_HANDLE hPVQ,   /* i/o: PVQ encoder handle                                   */
      96             :     UWord32 cum_freq,      /* i  : Cumulative frequency up to symbol    Q0*/
      97             :     UWord32 sym_freq,      /* i  : Symbol probability                                   Q0*/
      98             :     UWord32 tot            /* i  : Total cumulative frequency                   Q0*/
      99             : )
     100             : {
     101             :     UWord32 r, tmp, inv_tot, lsb;
     102             :     Word16 exp;
     103             :     UWord16 carry;
     104             : 
     105       20213 :     inv_tot = UL_inverse( tot, &exp );                   // Q0
     106       20213 :     Mpy_32_32_uu( hPVQ->rc_range, inv_tot, &tmp, &lsb ); /*0+exp-32 */
     107       20213 :     r = UL_lshr( tmp, sub( exp, 32 ) );                  /* exp-32-exp3+32 = 0 */
     108       20213 :     tmp = UL_Mpy_32_32( r, cum_freq );
     109             : 
     110       20213 :     hPVQ->rc_low = UL_addNs( hPVQ->rc_low, tmp, &carry ); // Q0
     111       20213 :     if ( carry != 0 )
     112             :     {
     113        1559 :         hPVQ->rc_carry = carry; // Q0
     114        1559 :         move16();
     115             :     }
     116             : 
     117       20213 :     hPVQ->rc_range = UL_Mpy_32_32( r, sym_freq ); // Q0
     118             : 
     119       37664 :     WHILE( hPVQ->rc_range < 1 << 24 )
     120             :     {
     121       17451 :         L_sub( 0, 0 );                                   /* Comparison in while */
     122       17451 :         hPVQ->rc_range = UL_lshl( hPVQ->rc_range, 8 );   // Q0
     123       17451 :         hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, 8 ); // Q0
     124       17451 :         rc_enc_shift_fx( hBstr, hPVQ );
     125             :     }
     126             : 
     127       20213 :     return;
     128             : }
     129             : 
     130             : /*-------------------------------------------------------------------*
     131             :  * rc_enc_finish()
     132             :  *
     133             :  *  Finalize range coder
     134             :  *-------------------------------------------------------------------*/
     135       30511 : void rc_enc_finish_ivas_fx(
     136             :     BSTR_ENC_HANDLE hBstr,
     137             :     PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle     */
     138             : 
     139             : )
     140             : {
     141             :     UWord32 val, mask, high;
     142             :     Word16 bits;
     143             :     UWord16 over1, over2;
     144             : 
     145       30511 :     bits = add( norm_ul( hPVQ->rc_range ), 1 );
     146       30511 :     mask = UL_lshr( 0xffffffff, bits );
     147             : 
     148       30511 :     val = UL_addNs( hPVQ->rc_low, mask, &over1 );            // Q0
     149       30511 :     high = UL_addNs( hPVQ->rc_low, hPVQ->rc_range, &over2 ); // Q0
     150             : 
     151       30511 :     val = L_and( val, ~mask );
     152       30511 :     L_xor( 0, 0 ); /* For bit not */
     153             : 
     154       30511 :     IF( ( L_xor( over1, over2 ) ) == 0 )
     155             :     {
     156       29014 :         L_sub( 0, 0 ); /* For comparision in if */
     157       29014 :         IF( UL_addNsD( val, mask ) >= high )
     158             :         {
     159       11171 :             bits = add( bits, 1 );                                  // Q0
     160       11171 :             mask = UL_lshr( mask, 1 );                              // Q0
     161       11171 :             val = UL_and( UL_addNsD( hPVQ->rc_low, mask ), ~mask ); // Q0
     162       11171 :             L_xor( 0, 0 );                                          /* For bit not */
     163             :         }
     164             : 
     165       29014 :         if ( LT_64( val, hPVQ->rc_low ) )
     166             :         {
     167        2263 :             hPVQ->rc_carry = 1;
     168        2263 :             move16();
     169             :         }
     170             :     }
     171             : 
     172       30511 :     hPVQ->rc_low = val;
     173       30511 :     move32();
     174             : 
     175       30511 :     IF( GT_16( bits, sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ) ) )
     176             :     {
     177           0 :         bits = sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ); // Q0
     178             :     }
     179             : 
     180       30511 :     hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); // Q0
     181       30511 :     move16();
     182       62734 :     FOR( ; bits > 0; bits -= 8 )
     183             :     {
     184       32223 :         rc_enc_shift_ivas_fx( hBstr, hPVQ );
     185             :     }
     186       30511 :     bits = add( bits, 8 );
     187             : 
     188       30511 :     IF( hPVQ->rc_carry_count > 0 )
     189             :     {
     190          12 :         rc_enc_write_ivas_fx( hBstr, add( hPVQ->rc_cache, hPVQ->rc_carry ), 8 );
     191             : 
     192          12 :         FOR( ; hPVQ->rc_carry_count > 1; hPVQ->rc_carry_count-- )
     193             :         {
     194           0 :             rc_enc_write_ivas_fx( hBstr, add( hPVQ->rc_carry, 0xff ), 8 );
     195             :         }
     196          12 :         rc_enc_write_ivas_fx( hBstr, s_and( add( hPVQ->rc_carry, 0xff ), sub( lshl( 1, bits ), 1 ) ), bits );
     197             :     }
     198             :     ELSE
     199             :     {
     200       30499 :         rc_enc_write_ivas_fx( hBstr, lshr( add( hPVQ->rc_cache, hPVQ->rc_carry ), sub( 8, bits ) ), bits );
     201             :     }
     202             : 
     203       30511 :     bits = hPVQ->rc_num_bits; // Q0
     204       30511 :     move16();
     205       30963 :     WHILE( LT_16( bits, sub( hPVQ->rc_tot_bits, 16 ) ) )
     206             :     {
     207         452 :         rc_enc_write_ivas_fx( hBstr, 0, 16 );
     208         452 :         bits = add( bits, 16 );
     209             :     }
     210             : 
     211       30511 :     bits = sub( hPVQ->rc_tot_bits, bits ); // Q0
     212       30511 :     IF( bits > 0 )
     213             :     {
     214       30486 :         rc_enc_write_ivas_fx( hBstr, 0, bits );
     215             :     }
     216             : 
     217       30511 :     return;
     218             : }
     219         377 : void rc_enc_finish_fx(
     220             :     BSTR_ENC_HANDLE hBstr,
     221             :     PVQ_ENC_HANDLE hPVQ /* i/o: PVQ encoder handle     */
     222             : 
     223             : )
     224             : {
     225             :     UWord32 val, mask, high;
     226             :     Word16 bits;
     227             :     UWord16 over1, over2;
     228             : 
     229         377 :     bits = add( norm_ul( hPVQ->rc_range ), 1 ); // Q0
     230         377 :     mask = UL_lshr( 0xffffffff, bits );
     231             : 
     232         377 :     val = UL_addNs( hPVQ->rc_low, mask, &over1 );            // Q0
     233         377 :     high = UL_addNs( hPVQ->rc_low, hPVQ->rc_range, &over2 ); // Q0
     234             : 
     235         377 :     val = L_and( val, ~mask );
     236         377 :     L_xor( 0, 0 ); /* For bit not */
     237             : 
     238         377 :     IF( ( L_xor( over1, over2 ) ) == 0 )
     239             :     {
     240         352 :         L_sub( 0, 0 ); /* For comparision in if */
     241         352 :         IF( UL_addNsD( val, mask ) >= high )
     242             :         {
     243         216 :             bits = add( bits, 1 );                                  // Q0
     244         216 :             mask = UL_lshr( mask, 1 );                              // Q0
     245         216 :             val = UL_and( UL_addNsD( hPVQ->rc_low, mask ), ~mask ); // Q0
     246         216 :             L_xor( 0, 0 );                                          /* For bit not */
     247             :         }
     248             : 
     249         352 :         if ( val < hPVQ->rc_low )
     250             :         {
     251          34 :             hPVQ->rc_carry = 1;
     252          34 :             move16();
     253             :         }
     254             :     }
     255             : 
     256         377 :     hPVQ->rc_low = val;
     257         377 :     move32();
     258             : 
     259         377 :     IF( GT_16( bits, sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ) ) )
     260             :     {
     261           0 :         bits = sub( hPVQ->rc_tot_bits, hPVQ->rc_num_bits ); // Q0
     262             :     }
     263             : 
     264         377 :     hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); // Q0
     265         768 :     FOR( ; bits > 0; bits -= 8 )
     266             :     {
     267         391 :         rc_enc_shift_fx( hBstr, hPVQ );
     268             :     }
     269         377 :     bits = add( bits, 8 );
     270             : 
     271         377 :     IF( hPVQ->rc_carry_count > 0 )
     272             :     {
     273           0 :         rc_enc_write_fx( hBstr, add( hPVQ->rc_cache, hPVQ->rc_carry ), 8 );
     274             : 
     275           0 :         FOR( ; hPVQ->rc_carry_count > 1; hPVQ->rc_carry_count-- )
     276             :         {
     277           0 :             rc_enc_write_fx( hBstr, ( hPVQ->rc_carry + 0xff ), 8 );
     278             :         }
     279           0 :         rc_enc_write_fx( hBstr, s_and( add( hPVQ->rc_carry, 0xff ), sub( lshl( 1, bits ), 1 ) ), bits );
     280             :     }
     281             :     ELSE
     282             :     {
     283         377 :         rc_enc_write_fx( hBstr, lshr( add( hPVQ->rc_cache, hPVQ->rc_carry ), sub( 8, bits ) ), bits );
     284             :     }
     285             : 
     286         377 :     bits = hPVQ->rc_num_bits; // Q0
     287         377 :     move16();
     288         377 :     WHILE( LT_16( bits, sub( hPVQ->rc_tot_bits, 16 ) ) )
     289             :     {
     290           0 :         rc_enc_write_fx( hBstr, 0, 16 );
     291           0 :         bits = add( bits, 16 );
     292             :     }
     293             : 
     294         377 :     bits = sub( hPVQ->rc_tot_bits, bits );
     295         377 :     IF( bits > 0 )
     296             :     {
     297         377 :         rc_enc_write_fx( hBstr, 0, bits );
     298             :     }
     299             : 
     300         377 :     return;
     301             : }
     302             : 
     303             : /*-------------------------------------------------------------------*
     304             :  * rc_enc_shift()
     305             :  *
     306             :  *  Shift a byte out to bitstream
     307             :  *-------------------------------------------------------------------*/
     308      277500 : static void rc_enc_shift_ivas_fx(
     309             :     BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle       */
     310             :     PVQ_ENC_HANDLE hPVQ    /* i/o: PVQ encoder handle     */
     311             : )
     312             : {
     313      277500 :     test();
     314      277500 :     L_sub( 0, 0 ); /* For comparision in if */
     315      277500 :     IF( LT_64( hPVQ->rc_low, 0xff000000UL ) || EQ_16( hPVQ->rc_carry, 1 ) )
     316             :     {
     317      276353 :         IF( hPVQ->rc_cache >= 0 )
     318             :         {
     319      245842 :             rc_enc_write_ivas_fx( hBstr, add( hPVQ->rc_cache, hPVQ->rc_carry ), 8 );
     320             :         }
     321             : 
     322      277488 :         WHILE( hPVQ->rc_carry_count > 0 )
     323             :         {
     324        1135 :             rc_enc_write_ivas_fx( hBstr, s_and( add( hPVQ->rc_carry, 0xff ), 255 ), 8 );
     325        1135 :             hPVQ->rc_carry_count = sub( hPVQ->rc_carry_count, 1 ); // Q0
     326        1135 :             move16();
     327             :         }
     328             : 
     329      276353 :         hPVQ->rc_cache = u_extract_l( UL_lshr( hPVQ->rc_low, 24 ) );
     330      276353 :         hPVQ->rc_carry = 0;
     331      276353 :         move16();
     332             :     }
     333             :     ELSE
     334             :     {
     335        1147 :         hPVQ->rc_carry_count = add( hPVQ->rc_carry_count, 1 ); // Q0
     336        1147 :         move16();
     337             :     }
     338      277500 :     hPVQ->rc_low = UL_lshl( hPVQ->rc_low, 8 );
     339      277500 :     move32();
     340      277500 :     return;
     341             : }
     342       17842 : static void rc_enc_shift_fx(
     343             :     BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle       */
     344             :     PVQ_ENC_HANDLE hPVQ    /* i/o: PVQ encoder handle     */
     345             : )
     346             : {
     347       17842 :     test();
     348       17842 :     L_sub( 0, 0 ); /* For comparision in if */
     349       17842 :     IF( hPVQ->rc_low < ( 0xff000000UL ) || EQ_16( hPVQ->rc_carry, 1 ) )
     350             :     {
     351       17770 :         IF( hPVQ->rc_cache >= 0 )
     352             :         {
     353       17393 :             rc_enc_write_fx( hBstr, add( hPVQ->rc_cache, hPVQ->rc_carry ), 8 );
     354             :         }
     355             : 
     356       17842 :         WHILE( hPVQ->rc_carry_count > 0 )
     357             :         {
     358          72 :             rc_enc_write_fx( hBstr, s_and( add( hPVQ->rc_carry, 0xff ), 255 ), 8 );
     359          72 :             hPVQ->rc_carry_count = sub( hPVQ->rc_carry_count, 1 ); // Q0
     360             :         }
     361             : 
     362       17770 :         hPVQ->rc_cache = u_extract_l( UL_lshr( hPVQ->rc_low, 24 ) );
     363       17770 :         hPVQ->rc_carry = 0;
     364       17770 :         move16();
     365             :     }
     366             :     ELSE
     367             :     {
     368          72 :         hPVQ->rc_carry_count = add( hPVQ->rc_carry_count, 1 ); // Q0
     369             :     }
     370       17842 :     hPVQ->rc_low = UL_lshl( hPVQ->rc_low, 8 ); // Q0
     371             : 
     372       17842 :     return;
     373             : }
     374             : 
     375             : /*-------------------------------------------------------------------*
     376             :  * rc_enc_bits()
     377             :  *
     378             :  *
     379             :  *-------------------------------------------------------------------*/
     380      483476 : void rc_enc_bits_ivas_fx(
     381             :     BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                     */
     382             :     PVQ_ENC_HANDLE hPVQ,   /* i/o: PVQ encoder handle                           */
     383             :     UWord32 value,         /* i  : Value to encode                                      Q0*/
     384             :     Word16 bits            /* i  : Number of bits used                          Q0*/
     385             : )
     386             : {
     387      483476 :     IF( LE_16( add( rc_get_bits2_fx( hPVQ->rc_num_bits, hPVQ->rc_range ), bits ), hPVQ->rc_tot_bits ) )
     388             :     {
     389      483476 :         hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); // Q0
     390      483476 :         move16();
     391      483476 :         IF( GT_16( bits, 16 ) )
     392             :         {
     393       42532 :             push_indice( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( UL_lshr( value, 16 ) ), sub( bits, 16 ) );
     394       42532 :             hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0
     395       42532 :             move16();
     396       42532 :             push_indice( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( UL_and( value, 0x0000ffff ) ), 16 );
     397       42532 :             hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0
     398       42532 :             move16();
     399             :         }
     400             :         ELSE
     401             :         {
     402      440944 :             push_indice( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( value ), bits );
     403      440944 :             hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0
     404      440944 :             move16();
     405             :         }
     406             :     }
     407             :     ELSE
     408             :     {
     409             :     }
     410             : 
     411      483476 :     return;
     412             : }
     413       31837 : void rc_enc_bits_fx(
     414             :     BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                     */
     415             :     PVQ_ENC_HANDLE hPVQ,   /* i/o: PVQ encoder handle                           */
     416             :     UWord32 value,         /* i  : Value to encode                                      Q0*/
     417             :     Word16 bits            /* i  : Number of bits used                          Q0*/
     418             : )
     419             : {
     420       31837 :     IF( LE_16( add( rc_get_bits2_fx( hPVQ->rc_num_bits, hPVQ->rc_range ), bits ), hPVQ->rc_tot_bits ) )
     421             :     {
     422       31837 :         hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); // Q0
     423             : 
     424       31837 :         IF( GT_16( bits, 16 ) )
     425             :         {
     426        4030 :             push_indice( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( UL_lshr( value, 16 ) ), sub( bits, 16 ) );
     427        4030 :             hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0
     428        4030 :             push_indice( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( UL_and( value, 0x0000ffff ) ), 16 );
     429        4030 :             hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0
     430             :         }
     431             :         ELSE
     432             :         {
     433       27807 :             push_indice( hBstr, sub( IND_RC_END, hPVQ->rc_offset ), u_extract_l( value ), bits );
     434       27807 :             hPVQ->rc_offset = add( hPVQ->rc_offset, 1 ); // Q0
     435             :         }
     436             :     }
     437             :     ELSE
     438             :     {
     439             :     }
     440             : 
     441       31837 :     return;
     442             : }
     443             : 
     444             : /*-------------------------------------------------------------------*
     445             :  * rc_enc_uniform()
     446             :  *
     447             :  * Encode with uniform distribution
     448             :  *-------------------------------------------------------------------*/
     449      277318 : void rc_enc_uniform_ivas_fx(
     450             :     BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                     */
     451             :     PVQ_ENC_HANDLE hPVQ,   /* i/o: PVQ encoder handle                           */
     452             :     UWord32 value,         /* i  : Value to encode                                      Q0*/
     453             :     UWord32 tot            /* i  : Maximum value                                        Q0*/
     454             : )
     455             : {
     456             :     Word16 n;
     457             : 
     458      277318 :     n = sub( 32, norm_ul( UL_subNsD( tot, 1 ) ) );
     459             : 
     460      277318 :     IF( LE_16( n, 8 ) )
     461             :     {
     462       71183 :         rc_encode_ivas_fx( hBstr, hPVQ, value, 1, tot );
     463             :     }
     464             :     ELSE
     465             :     {
     466      206135 :         n = sub( n, 8 );
     467      206135 :         rc_encode_ivas_fx( hBstr, hPVQ, UL_lshr( value, n ), 1, UL_addNsD( UL_lshr( tot, n ), 1 ) );
     468      206135 :         rc_enc_bits_ivas_fx( hBstr, hPVQ, UL_and( value, UL_subNsD( UL_lshl( 1, n ), 1 ) ), n );
     469             :     }
     470             : 
     471      277318 :     return;
     472             : }
     473       16357 : void rc_enc_uniform_fx(
     474             :     BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                     */
     475             :     PVQ_ENC_HANDLE hPVQ,   /* i/o: PVQ encoder handle                           */
     476             :     UWord32 value,         /* i  : Value to encode                                      Q0*/
     477             :     UWord32 tot            /* i  : Maximum value                                        Q0*/
     478             : )
     479             : {
     480             :     Word16 n;
     481             : 
     482       16357 :     n = sub( 32, norm_ul( UL_subNsD( tot, 1 ) ) ); // Q0
     483             : 
     484       16357 :     IF( LE_16( n, 8 ) )
     485             :     {
     486         877 :         rc_encode_fx( hBstr, hPVQ, value, 1, tot );
     487             :     }
     488             :     ELSE
     489             :     {
     490       15480 :         n = sub( n, 8 ); // Q0
     491       15480 :         rc_encode_fx( hBstr, hPVQ, UL_lshr( value, n ), 1, UL_addNsD( UL_lshr( tot, n ), 1 ) );
     492       15480 :         rc_enc_bits_fx( hBstr, hPVQ, UL_and( value, UL_subNsD( UL_lshl( 1, n ), 1 ) ), n );
     493             :     }
     494             : 
     495       16357 :     return;
     496             : }
     497             : 
     498             : /*-------------------------------------------------------------------*
     499             :  * rc_enc_write()
     500             :  *
     501             :  *  Write a byte to bitstream
     502             :  *-------------------------------------------------------------------*/
     503      308438 : static void rc_enc_write_ivas_fx(
     504             :     BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                     */
     505             :     Word16 byte,           /* i  : Byte to write                                        Q0*/
     506             :     Word16 bits            /* i  : Number of bits                                       Q0*/
     507             : )
     508             : {
     509      308438 :     push_indice( hBstr, IND_RC_START, byte, bits );
     510             : 
     511      308438 :     return;
     512             : }
     513       18219 : static void rc_enc_write_fx(
     514             :     BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                     */
     515             :     Word16 byte,           /* i  : Byte to write                                        Q0*/
     516             :     Word16 bits            /* i  : Number of bits                                       Q0*/
     517             : )
     518             : {
     519       18219 :     push_indice( hBstr, IND_RC_START, byte, bits );
     520             : 
     521       18219 :     return;
     522             : }

Generated by: LCOV version 1.14