-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
libm/libm: Do not force floating point type size evaluation. #14456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #14456 +/- ##
=======================================
Coverage 98.39% 98.39%
=======================================
Files 161 161
Lines 21204 21204
=======================================
Hits 20864 20864
Misses 340 340 ☔ View full report in Codecov by Sentry. |
Code size report:
|
As I understand it, the maybe-tricky part here is that MicroPython libm provides a bunch of optimised math routines that rely on a particular binary representation of floats. So if To keep a check for this, I think it might be enough to insert this into both libm headers where the define previously was: // These lines verify that FLT_EVAL_METHOD==0, MicroPython's libm requires this.
// If compilation fails here then check the host compiler's FLT_EVAL_METHOD.
typedef float float_t;
typedef double double_t; Redundant (compatible) typedef declarations are allowed, so provided math.h makes matching definitions then this should compile. If a particular platform is configured differently, math.h should have defined float_t or double_t to something else so a compiler error should appear at this point. I think it's preferable to (maybe) compiling and producing garbage results That said, I don't know if MicroPython supports any build configurations where this would fail. |
@projectgus, I've looked a bit into it as well. On RISC-V I believe That alone makes your point valid, I guess. I haven't looked much into how Arm handles this, but for example what happens if you use That said, I'll update the patch following your suggestion, thanks! |
@agatti These are good questions that I don't know the answers to! At minimum, I think these changes won't make anything not work that previously would have worked... |
Since C99, `FLT_EVAL_METHOD` should be left for the compiler/libc to define. Its redefinition breaks compilation with picolibc as the target's libc, since it defines said symbol in math.h before the libm define is evaluated by the compiler. In its place, there is a check to make sure floating point type sizes are what are expected to be, triggering a compilation error if those assumptions are no longer valid. Co-authored-by: Angus Gratton <angus@redyak.com.au> Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
MicroPython's vendored
libm
andlibm_dbl
definition ofFLT_EVAL_METHOD
break compilation on embedded targets that use picolibc as their libc provider (see discussion: #12853 (comment)).One case where this is needed is the RISC-V toolchain available on the CI image. Going forward, other toolchains may prefer to use picolibc instead of newlib, and users may want to be able to use said library with MicroPython.
Starting from C99
FLT_EVAL_METHOD
should be left to the compiler/libc to define, according to the appropriate floating point types' representation for the platform. Choosing floating point types representations should be done via compiler options rather than with#define
s.Tests pass on both
qemu-arm
andqemu-riscv
with this change applied. Though I saw no build breakages for ports/boards that used eitherlibm
orlibm_dbl
, I cannot tell whether this PR breaks code on hardware platforms I have no access to.