-
Notifications
You must be signed in to change notification settings - Fork 152
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
as it is, SCB::set_fpu_access_mode() is a footgun #44
Comments
The TI Tiva ROM enables FPU before entering main(). This seems like an awkward choice but maybe the cortex-m-rt crate should do the same; the FPU is not a massive power hog and power-conscious users will surely discover the option of turning it off on their own with no effort. |
Is there any reason that enabling the FPU before entering |
It would be a really confusing feature flag. |
cc @oli-obk |
I don't think there can be any workarounds other than moving it before main, because the floating types are available everywhere and the moment they are used this issue occurs. A quick solution would be a lint that detects such situations, but it won't help much in the presence of optimizations. A feature flag would not really work, since any crate also depending on the crate can forget the feature flag, thus breaking your code. This means that there's no way to write the feature in an additive way. |
Thanks, you've articulated my concern far better than myself. |
That makes sense. Is there some kind of |
Not sure. See rust-lang/rust#32651. |
Seems fine to make it a conditional feature of the cortex-m-rt crate. As per the cortex-m-quickstart model the rt crate is always a direct dependency of the application / top crate and doesn't appear anywhere else in the dependency graph (*) so the application writer always has full control over which Cargo feature of the rt is enabled / disabled. (*) not that I can actually stop anyone from making a library depend on the rt crate but it doesn't make sense to do so since that crate has no API.
Note that there are use cases where the target has a FPU but one would prefer to keep the FPU disabled if they are not using it in the application. Always enabling the FPU if the target has a FPU would prevent that use case. |
I strongly feel that the FPU should be always enabled if any f32/f64 parameters are passed in FP registers in the Rust ABI, because having to debug this is a horrible thing to do to your users. I also feel that a feature of cortex-m-rt crate is not the right solution here because, so long as it's additive, it is easy to accidentally forget to activate it when setting I think that disabling the FPU right away in |
|
@a-shafir That's a subtractive feature and is not a correct use of the system. |
In that case, maybe they can disable it when entering |
I wasn't thinking of making the "fpu" feature enabled by default so would always have to enable it (regardless of whether you set default-features to true or false) if you need it. "Pay for what you use".
Hmm, that sounds reasonable. I suppose if you are not going to use the FPU at all in your application you could just use the That also made me realize that probably the whole |
Agreed on both counts. |
cortex-m-rt v0.3.0 has been released and it enables the FPU before main (on targets that have a FPU). That doesn't change the fact that |
|
Let's say FPU is disabled at entry in
main()
as it usually is, and you want to do some FP operations. Presto!... or something like that. Well, not so easy. Since the code below
enable_fpu
changes callee-save FP registers, LLVM will try to stack those at the top of main... using thevpush
instruction. Which is not available until FPU is enabled. Oops.I don't know how to fix this.
The text was updated successfully, but these errors were encountered: