Skip to content

Floating point number regression (LLVM-67) #20

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

Closed
lexxvir opened this issue Apr 23, 2020 · 3 comments
Closed

Floating point number regression (LLVM-67) #20

lexxvir opened this issue Apr 23, 2020 · 3 comments

Comments

@lexxvir
Copy link

lexxvir commented Apr 23, 2020

Hi,

I have encountered into the regression in the current xtensa_release_9.0.1 branch.
Previously I used GCC based branch and it works fine.
Worth noting that I also changed the Rust version, so it may be related.

To reproduce the issue I have prepared minimal version of Rust code:

#[no_mangle]
#[inline(never)]
fn test_float_cmp() {
    let mut f: f32 = 10.0;
    let mut p = Printf {};

    while f > 0.0 {
        // works fine
        // let _ = writeln!(p, "{:04x}", f.to_bits());

        // works bad
        let _ = writeln!(p, "{}", f);

        f -= 0.1;
    }
}
  • "works bad": loop produces only one value 10.0 and exits
  • "works fine": loop produces 100 values

Some comments for the code:

  • "bad" case formats f32 to human readable string
  • "good" case formats u32 to hexadecimal number
  • to_bits converts f32 to u32 as is at bits representation
  • Printf is thin wrapper around regular C's `printf:
struct Printf;
impl Write for Printf {
    fn write_str(&mut self, s: &str) -> Result {
        for c in s.as_bytes() {
            unsafe { printf("%c\0".as_ptr() as *const _, *c as i32) }
        }
        Ok(())
    }
}

I've attached archive with: Rust source code demo, disassembled code for "good" and "bad" cases, final binary and LLVM bitcode files:

float-issue.zip

P.S. Actually I use https://github.com/mabezdev/llvm-project fork, but now it contains only one commit ahead of this branch.

@github-actions github-actions bot changed the title Floating point number regression Floating point number regression (LLVM-67) Apr 23, 2020
@andreisfr
Copy link
Collaborator

andreisfr commented Dec 4, 2020

Hi, @lexxvir ! Could you check this example using new branch xtensa_release_11.0.0, please? We corrected some FP comparison operations

@lexxvir
Copy link
Author

lexxvir commented Dec 13, 2020

Hi @andreisfr

I've checked xtensa_release_11.0.0 branch and confirm that the issue is fixed! Thanks for the support!

@lexxvir lexxvir closed this as completed Dec 13, 2020
@andreisfr
Copy link
Collaborator

Hi, @lexxvir , thank you very much for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants