-
Notifications
You must be signed in to change notification settings - Fork 14
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
Compiler uses f64 literals by default; both float and double are 32 bits on AVR #76
Comments
I'm 💯 against this. We cannot effectively fork the entire Rust ecosystem because our float literals are different from the "real" compiler, causing havoc every single time a crate that wasn't explicitly designed for AVR is used. |
Again, I think I'm in the minority here, but I don't think we should forcibly adhere to what GCC does. Why not implement our our 64-bit floating point routines? I believe they will be terrible, but you don't want to really use them anyway.
There's no concept as "AVR C/C++". GCC's AVR C implementation is one implementation (which is valid in the C spec), but that doesn't mean it's the only possibility. |
Hmm, true enough! |
Absolutely. Note that most of this has been discussed elsewhere, where we already agree to supporting |
Hmm.. there's a pretty big difference between supporting i128 and it being the default size for a literal. I understand why you wouldn't want the default size of a float to be different from the upstream, but it will mean that everyone will always need to use the f32 typehint when working with avr. Not making the default f32 for avr-rust makes the right thing hard for users. That's rarely a Good Thing™ in my experience. Just some food for thought from something interested in the project. |
Hmm. Is it possible to find some other solution than the ones listed above? One possibility I just thought of is having f64 as default, but having a compiler flag/crate attribute to use f32 instead, and recommending AVR projects to use that. That would leave compatibility with existing crates, but make AVR-specific code more suited for such an environment. It's still not ideal, but neither is implementing f64 support and silently using that, or simply telling users to always type annotate. |
A compiler flag that changes ABI on a per-project basis? |
Hmm no, I don't think it would change the ABI... would it have to? What I mean is that the default type where none is specified and multiple are possible (e.g. println!("{}", 1.2) would be f32 rather than f64. |
I also believe that the fallback case is fairly rare in practice. AFAIK, it can only happen within a single method; once you pass that number to a function which accepts a Maybe this is basically not a real worry whatsoever, other than the fact that we need to implement the missing support library calls. |
Makes sense, literal types shouldn't affect ABI. |
Closing this, we all seem to be in agreement that |
The above code (and any other code that uses f64, implicitly or explicitly) fails linking:
__gtdf2
is used for 64-bit floats, which are not supported by avr-gcc/avr-libc.avr-gcc has sizeof(float) == sizeof(double) == 4, so there are no 64-bits floats in AVR C/C++.
If we tell the compiler to use f32, in whatever way we choose (explicit type annotation on
num
or using thef32
suffix on either integer literal, the code compiles successfully.Using f32 by default seems like the best course of action IMO, if that's a reasonable change.
Even then, though, the question about how to deal with f64 when used explicitly remains.
It could be entirely disallowed, support could be added (but that would likely involve hand-writing all the necessary 64-bit soft float code in assembly), or (ugh) f64 could be 32 bits wide.
The text was updated successfully, but these errors were encountered: