Commit fd47d26e authored by Jonas Svedberg's avatar Jonas Svedberg
Browse files

revert to a lower complexity likely BE(IVAS and EVS-Mono) version without rounding

parent cf0bb74d
Loading
Loading
Loading
Loading
Loading
+68 −37
Original line number Diff line number Diff line
@@ -1096,23 +1096,56 @@ static void subst_spec(

        Xph = corr_phase[m];
#ifdef FIX_1002_DEC_PHASE_ECU_USAN_OF_PHASE
        if ( element_mode != EVS_MONO )
        {
        /* BE , but with maintained dual mult of a constant,  bnut mask the  10 bits in Word32, truncation  */
#define WMC_TOOL_SKIP
        Xph_short = ( int16_t )( 0x000003ff & ( int32_t )( ( Xph * 512 ) / EVS_PI ) );
        MULT( 2 );  /* mult with constant, twice due to legacy precedence use */
        LOGIC( 1 ); /* L_and        */
        MISC( 1 );  /* extract_l   */
#undef WMC_TOOL_SKIP
#if 1
        int16_t Xph_short_orig = ( int16_t )( ( ( int32_t )( Xph * 512 / EVS_PI ) ) % 32768 ) & 0x03ff; /* BE: 2 mults, 1 modulo */     /* bad line(for WMC):  WMC-costly modulo % in use,  no rounding   */
        int16_t Xph_short_1mult_nonbe = ( int16_t )( 0x000003ff & ( int32_t )( ( Xph * ( 512.0 / EVS_PI ) ) ) );                        /* nonBE:  single mult, mask the  10 bits in Word32 ,  still no rounding */
        int16_t Xph_short_1mult_rnd_nonbe = ( int16_t )( 0x000003ff & ( ( 1L + ( ( int32_t )( Xph * ( 1024.0 / EVS_PI ) ) ) ) >> 1 ) ); /* nonBE:  single mult, add 1(round) shift1,  mask the  10 bits in Word32 , i.e. with rounding */

        assert( Xph_short == Xph_short_orig && "Xph_short == Xph_short_orig" );
#endif

#ifdef DEBUGGING

        int32_t Xph_long_new = ( int32_t )( Xph * ( 512 / EVS_PI ) ); /* mult by a single constant and float cast to int32_t */
        int32_t Xph_long_old = ( int32_t )( ( Xph * 512 ) / EVS_PI ); /* mult by 2 constants ! and float cast to int32_t , (Xph<<9) / pi */
        int32_t Xph_long = Xph_long_old;

        //assert( Xph_long_new == Xph_long_old && __func__ && " Xph_long_new != Xph_long_old" ); // mat differ due to order of division

        int32_t L_tmp1 = Xph_long % 32768;      /* counts as division:  6-25 cycles */
        int32_t L_tmp2 = Xph_long & 0x00007fff; /* L_and mask : 1 cycle */
       // assert( L_tmp1 == L_tmp2 && __func__ && " L_tmp1 != L_tmp2 " );


        Xph_long = ( Xph_long & 0x00007fff ); /*  L_and()  equivalent to  % 32768 */
        int16_t Xph_short_new1 = ( (int16_t) Xph_long ) & 0x03ff;
        int16_t Xph_short_new2 = ( int16_t )( Xph_long_old & 0x000003ff );

        //assert( Xph_short == Xph_short_new1 && __func__ && " Xph_short != Xph_short_new1" );
        //assert( Xph_short == Xph_short_new2 && __func__ && " Xph_short != Xph_short_new2" );

#if 0
            /* guarantee no wrap around to negative side of 32 bit signed integer value  */
#define WMC_TOOL_SKIP
            tmpf = Xph * ( 1.0f / PI2 );                           /* normalize         :  mult() with a constant                           */
            tmpf = ( 1024.0f * ( tmpf - floorf( tmpf ) ) ) + 0.5f; /* obtain fraction  :  floor(), sub(), mult(), rnd(), out:  [0...1024.5[ */
            Xph_short = ( (int16_t) tmpf ) & 0x03ff;               /* mask to [0..1023]:  s_and()                      , out:  [0...1023]   */
            int16_t Xph_short_flt_correct = ( (int16_t) tmpf ) & 0x03ff;               /* mask to [0..1023]:  s_and()                      , out:  [0...1023]   */

            MULT( 2 );
            MISC( 1 );  /* floor    */
            ADD( 2 );   /* sub, rnd */
            LOGIC( 1 ); /* s_and    */
#undef WMC_TOOL_SKIP
        }
        else
        {
            Xph_short = (int16_t) ( ( (int32_t) ( Xph * 512 / EVS_PI ) ) % 32768 ) & 0x03ff; /* WMC-costly % in use, no rounding  */
        }
#endif 
#endif

#else
        Xph_short = ( int16_t )( ( ( int32_t )( Xph * 512 / EVS_PI ) ) % 32768 ) & 0x03ff;
#endif
@@ -1162,25 +1195,23 @@ static void subst_spec(
                }

#ifdef FIX_1002_DEC_PHASE_ECU_USAN_OF_PHASE
                if ( element_mode != EVS_MONO )
                {
                    /* fractional phase of Xph converted to an integer in the range [0..1023] */
                    /* in BASOP this is simply a truncation (through extract_l(Word32)) of a 32bit value at the Q16 bimal point + shifting to a 10 bit index  */
#define WMC_TOOL_SKIP
                    tmpf = Xph * ( 1.0f / PI2 );                           /* normalize        :  mult() with a constant       */
                    tmpf = ( 1024.0f * ( tmpf - floorf( tmpf ) ) ) + 0.5f; /* obtain fraction  :  floor(), sub(), mult(), rnd(), out:  [0...1024.5[ */
                    Xph_short = ( (int16_t) tmpf ) & 0x03ff;               /* mask to [0..1023]:  s_and()                      , out:  [0...1023]   */

                    MULT( 2 );
                    MISC( 1 );  /* floor    */
                    ADD( 2 );   /* sub, rnd */
                    LOGIC( 1 ); /* s_and    */
                Xph_short = ( int16_t )( ( ( int32_t )( ( Xph * 512 ) / EVS_PI ) ) & 0x000003ff );
                MULT( 2 );  /* mult with constant, twice due to legacy precedence  */
                LOGIC( 1 ); /* L_and        */
                MISC( 1 );  /* extract_l   */
#undef WMC_TOOL_SKIP
                }
                else
                {
                    Xph_short = (int16_t) ( Xph * 512 / EVS_PI ) & 0x03ff; /* NB! USAN warning for cast from float  to int16_t,  no rounding  */
                }
#if 1
                int16_t Xph_short_orig_ph_dith = ( int16_t )( Xph * 512 / EVS_PI ) & 0x03ff; /* USAN bad cast,  bad dual mults */
                assert( Xph_short == Xph_short_orig_ph_dith ); 
#endif

#ifdef DEBUGGING
                /* NB! USAN undefined behaviour warning for float-> short cast adressed, no rounding required here as phase is scrambled anyway */
                /* applied also  EVS_MONO */
#endif


#else
                Xph_short = ( int16_t )( Xph * 512 / EVS_PI ) & 0x03ff;
#endif