From 6492937c823602058f174f29aa3aa51d6a316cae Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Mon, 27 Oct 2025 15:51:15 +0100 Subject: [PATCH] prevent optimizations around trig functions to preserve BE for -O0/-O2 --- lib_com/options.h | 1 + lib_enc/ivas_stereo_dft_enc.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 4c31c1480c..c33b9eba21 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -185,6 +185,7 @@ #define NONBE_1412_AVOID_ROUNDING_AZ_ELEV /* FhG: Avoid rounding when passing azimuth and elevation to efap_determine_gains() */ #define NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG /* FhG: Fix MDCT-Stereo comfort noise for certain noise types */ +#define NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS /* FhG: fix non-BE in DFT stereo encoder between optimization levels */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 0ae36724d8..b583690cf3 100755 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -1316,12 +1316,24 @@ void stereo_dft_enc_process( if ( hStereoDft->hItd->deltaItd[k_offset] != 0 && hStereoDft->hConfig->dmx_active ) { +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS + /* Note: this variable is used as an in-between step when passing the angle to the trig functions. + * this keeps the compilter from applying optimizations at higher optimizaton levels which can break bit-exactness */ + volatile float alpha_tmp; +#endif /*time shift channels*/ alpha = -2.0f * EVS_PI * hStereoDft->hItd->deltaItd[k_offset] / hStereoDft->NFFT; c = 1.f; /*cos(0)*/ s = 0.f; /*sin(0)*/ +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS + + alpha_tmp = alpha; + c1 = cosf( alpha_tmp ); + s1 = sinf( alpha_tmp ); +#else c1 = cosf( alpha ); s1 = sinf( alpha ); +#endif if ( alpha >= 0 ) { -- GitLab