espressif/esp-dsp

modules/math/sqrt/float/dsps_sqrt_f2_ansi.c build error (DSP-89)

davidallenmann opened this issue · 3 comments

Environment

  • Development Kit: ESP32-S3-DevKitC
  • IDF version: v5.0-dev-4303-g075e0729de
  • Build System: CMake
  • Compiler version: xtensa-esp32-elf-gcc (crosstool-NG esp-2022r1-RC1) 11.2.0
  • Operating System: macOS
  • Power Supply: USB

Problem Description

Build doesn't error if build with compiler debug mode, but when build with compiler optimization 'Optimize for performance (-O2)' get build error as below.

Should it be as follows to return a float instead of a pointer to a float?

inline float dsps_sqrtf_f32_ansi(float f)
{
    int* f_ptr = (int*)&f;
    const int result = 0x1fbb4000 + (*f_ptr >> 1);
    float* f_result = (float*)&result;
    return f_result;   
}

Debug Logs

/Users/davidmann/w/Haikubox2-firmware/modules/math/sqrt/float/dsps_sqrt_f32_ansi.c:24:12: error: 'result' is used uninitialized [-Werror=uninitialized]
   24 |     return *f_result;
      |            ^~~~~~~~~
/Users/davidmann/w/Haikubox2-firmware/modules/math/sqrt/float/dsps_sqrt_f32_ansi.c:22:15: note: 'result' declared here
   22 |     const int result = 0x1fbb4000 + (*f_ptr >> 1);

Hi @davidallenmann ,
Yes, this is the problem with latest GCC. We will fix it soon.

Thanks,
Dmitry

Hi @davidallenmann
The update will be soon.
Right now please change dsps_sqrtf_f32_ansi to

inline float dsps_sqrtf_f32_ansi(float f)
{
    int result;
    int* f_ptr = (int*)&f;
    result = 0x1fbb4000 + (*f_ptr >> 1);
    const int *p = &result;
    float* f_result = (float*)p;
    return *f_result;   
}

Regards,
Dmitry

This is fixed in 7a13333