espressif / esp-dsp

DSP library for ESP-IDF
Apache License 2.0
442 stars 87 forks source link

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

Closed davidallenmann closed 11 months ago

davidallenmann commented 1 year ago

Environment

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);
dmitry1945 commented 1 year ago

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

Thanks, Dmitry

dmitry1945 commented 1 year ago

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

Barabas5532 commented 1 year ago

This is fixed in https://github.com/espressif/esp-dsp/commit/7a13333127f29a24a2c49d785cdbbe772bdd036b