Skip to content

Floating point number regression (LLVM-67) #20

Closed
@lexxvir

Description

@lexxvir

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions