Hello,
I face an issue with an ESP32S3 usage in ULP mode where I want the ULP co-processor to use some standard Math.h functions, like sqrt()
and atan()
.
Unfortunately, I get a compilation error where I want to do a sqrt(myvariable)
, but no compilation error when I do a sqrt(4)
, so working with constant and not with variable. I receive the error :
undefined reference to `sqrt’.
Apparently, the ESP32 support mentions that this is working properly in IDF, so it might be an issue with PlatformIO.
Would you have any solution for this ?
Unlike the older parts, the ULP is a RISC-V core. ULP RISC-V Coprocessor Programming - ESP32-S3 - — ESP-IDF Programming Guide v5.5 documentation says
The RISC-V processor is a 32-bit fixed point machine. Its instruction set is based on RV32IMC
Fixed point means not floating point. If it were floating point, it would be RV32IMCF where the ‘F’ means the obvious thing.
Computing square roots isn’t the kind of thing that low-power processors do. You can code around this with lookup tables or something or you can spin up the warp drive, do your heavy math, and then drop back down to impulse power.
Honestly, I"m surprised you even made it to the link stage. I’m surprised you had a prototype for sqrt in math.h at all, but maybe it’s newlib-based and they don’t go out of their way to customize it for super chopped-down parts since that same lib is used on Real Computers and it’s going to fail in a second or less anyway, as you’ve observed.
And, heck, even in full power mode, sqrt is a double precision version that’s done completely in software as opposed to sqrtf, the single precision version that’s provided in silicon, so you’re going to find it hundreds of times slower even then. But if you need all 52 significant bits instead of 23, you need 'em. That’s up to your software engineers to decide. (That’s something like 7 decimal places vs. 15, but It’s Complicated.™)