-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
MIPS: println! before return statement changes returned value #35673
Comments
Also, seems like I can make the problem go away by making my own floor(): fn baud(&mut self) -> u32 {
// baud is given by the following:
// baud = 65536*(1-(samples_per_bit)*(f_wanted/f_ref))
// samples_per_bit = 16, 8, or 3
// f_ref = 48e6
let wanted_f: f64 = self.baudrate as f64;
let baud: f64 = 65536f64 * (1f64 - (16f64 * (wanted_f / 48_000000f64)));
// https://github.com/rust-lang/rust/issues/35673
// floor(n) = n - (n % 1)
(baud - (baud % 1f64)) as u32
} .. computes the correct result. |
Hmm, might be a constant-folding issue. I made a C version of the code and it produces the same ASM as the Rust version on x86. A function that just supplies 9600 to Could you post the MIPS ASM of this please: #![crate_type="lib"]
pub fn baud(wanted: u32) -> u32 {
// baud is given by the following:
// baud = 65536*(1-(samples_per_bit)*(f_wanted/f_ref))
// samples_per_bit = 16, 8, or 3
// f_ref = 48e6
let wanted_f: f32 = wanted as f32;
let baud: f32 = 65536f32 * (1f32 - (16f32 * (wanted_f / 48_000000f32)));
baud.floor() as u32
}
pub fn baud2() -> u32 {
baud(9600)
} As setting up a MIPS toolchain is proving difficult. |
Are you sure the float ABI between Rust and system libc matches? If the floor intrinsic lowers down to a libc call and the ABI mismatches, then you’ll see weird results like these with any non-native float op. Things to try: |
I was checking the tessel-rust repository and saw this line:
The target system is running uclibc. In conclusion, you want to create and use a The other option is to run OpenWRT trunk, which is musl based, on the Tessel, then you can, instead, use the |
Hey all, thanks so much for all the investigation and deep dive into this. One of the Tessel developers also pointed me to #34906 with the same findings. Please feel free to resolve, I'll see about updating the target. Thanks again! |
These targets cover OpenWRT 15.05 devices, which use the soft float ABI and the uclibc library. None of the other built-in mips targets covered those devices (mips-gnu is hard float and glibc-based, mips-musl is musl-based). With this commit one can now build std for these devices using these commands: ``` $ configure --enable-rustbuild --target=mips-unknown-linux-uclibc $ make ``` cc rust-lang#35673
add mips-uclibc targets These targets cover OpenWRT 15.05 devices, which use the soft float ABI and the uclibc library. None of the other built-in mips targets covered those devices (mips-gnu is hard float and glibc-based, mips-musl is musl-based). With this commit one can now build std for these devices using these commands: ``` $ configure --enable-rustbuild --target=mips-unknown-linux-uclibc $ make ``` cc rust-lang#35673 --- r? @alexcrichton cc @felixalias This is the target the rust-tessel project should be using. Note that the libc crate doesn't support the uclibc library and will have to be updated. We are lucky that uclibc and glibc are somewhat similar and one can build std and even run the libc-test test suite with the current, unmodified libc. About that last part, I tried to run the libc-test and got a bunch of compile errors. I don't intend to fix them but I'll post some instruction about how to run libc-test in the rust-lang/libc issue tracker.
Appropriate targets for this use case (OpenWRT 15.05 on MIPS, e.g. Tessel 2) landed in #35734. Proper support for these targets in libc is being tracked in rust-lang/libc#361, which contains instructions about how to update libc and run its test suite. Once libc is updated perhaps we can start building binary releases of std for these targets. cc @alexcrichton |
rust-lang/libc#361 is still open. As I understand it, this specific issue isn't tracking more than "build binary releases of std" which isn't something we currently want to track as far as I know, so I'm going to close this issue. If people are interested, please ask on internals.rust-lang.org for instructions on how to add a platform to Rust's standard builds. |
Hi all,
Asked about this in rust-beginners and was advised it's probably a bug. On MIPS (specifically, on the Tessel 2, technical overview) I'm getting different (incorrect) results from a function that does a bit of math, depending on:
Here's a playground link with my ideal variation of the method; ideally, it should compute baud(9600) = 65326. On MIPS, depending on the various factors I've listed above, I've seen varying results including 0 and 4294967295.
From what I can tell, this is falling apart with the floor() call (which appears to be an intrinsic - something I've seen others have difficulty with on MIPS). Take this snippet:
Gives the output:
(where 5: should be 65326). If I add another intermediate local in between part4 and part5 (
let inter: f64 = part4.floor()
), bothinter
andpart5
have the 0.0002 value when printed.However, I can seemingly coerce it into working by putting a println! in the right place:
This returns the correct result, even on MIPS.
The text was updated successfully, but these errors were encountered: