Skip to content

division and modulus operator usage

We have profiled code for various decoder paths and observed that fixed-point division and mod operations are used in many places. For instance, following stream has 50 frames :

Encoder : IVAS_cod -sba 3 512000 48 scripts/testv/spectral_test_16ch_48kHz.wav bit

Decoder : IVAS_dec MONO 48 bit bit_mono.out

During execution of 50 frames, number of calls to div and mod library functions are listed below. Please note following number only shows emulation due to "/" or "%" operators and not calls from any BASOPs.

  • get_next_indice_1 : 36240 div calls
  • get_next_indice : 1604 div calls
  • ivas_calculate_abs_fr_fx : 1279 div calls
  • sr2fscale : 400 div calls
  • ivas_calculate_abs_fr_fx : 8056 mod calls

Similarly, when same encoded bitstream is decoded using 5_1 multi-channel decoder, following are the observations -

  • ivas_dirac_dec_get_response_fx : 120070 mod calls
  • ivas_jbm_dec_get_md_map - 2500 div calls

Both "%" and "/" operations are costly on hardware hence should be avoided if possible. Those strictly should not be used in loops. Most of the instances of div are seen around constants (i.e. FRAMES_PER_SEC in the denominator). Those can be replaced with ONE_BY_FRAMES_PER_SEC_Q31. It is already used in functions like get_next_indice_1_fx().

Also, significant contribution of modulus operation is observed in ISM4 enc -> Binaural room IR decode path.

It is coming from ivas_rend_crendConvolver() function. This is the top contributor function in above decoder path (takes to more than 60% of total decoder cycles).

Encoder : IVAS_cod -ism 4 scripts/testv/stvISM1.csv scripts/testv/stvISM2.csv scripts/testv/stvISM3.csv scripts/testv/stvISM4.csv 512000 48 scripts/testv/spectral_test_4ch_48kHz.wav bit

Decoder : IVAS_dec BINAURAL_ROOM_IR 48 bit bit_binaural_room_ir.out

Some of the instances of mod operator can be replaced with bitwise operators i.e. conditional check in ivas_dirac_dec_get_response_fx() can be updated as suggested below :

"IF( EQ_16( ( l % 2 ), 1 ) )" => can be replaced with "IF( l & 0x1 )"

We should carefully review the use of div/mod operations in critical functions in the fixed point code.