Skip to content
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

dtoa compiled with -Os has incorrect result #80

Open
tclin914 opened this issue Jun 29, 2023 · 0 comments
Open

dtoa compiled with -Os has incorrect result #80

tclin914 opened this issue Jun 29, 2023 · 0 comments

Comments

@tclin914
Copy link

I let sum result printed on each iteration. And adjust REPEAT_FACTOR to 5.

Run dtoa.elf (compiled with -O2)
$ ./dtoa.elf
262390.355982 <= not expected result
262390.355982 <= not expected result
267945.911538
267945.911538
267945.911538

And its final result is correct.

Run dtoa.elf (compiled with -Os)
$ ./dtoa.elf
262390.355982 <= not expected result
262390.355982 <= not expected result
262390.355982 <= not expected result
262390.355982 <= not expected result
262390.355982 <= not expected result

And its final result is wrong. (the result got from every repeat are all wrong)

The main cause is "5555.5555555555555555" transfered to 0.0 on first and second repeat in compiled with -O2.
And always are 0.0 on every repeat in compiled with -Os.

In src/dtoa/libdtoa.c. local variable word0(&rv) in function strtod doesn't be initilized well. It make getting different result on each repeat. If we add word0(&rv) = 0; to intilize word0(&rv) to 0. "5555.5555555555555555" are always transfererd to 0.0. So the result are not expected (compiled with Os or O2).

I am not sure the intilization for word0(&rv) should be added. and "5555.5555555555555555" -> 0.0 is a reasonable value.
Or other issue made...

My gcc version:
Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-host-pie --enable-host-bind-now --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.rockylinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --without-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_64=x86-64-v2 --with-arch_32=x86-64 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.3.1 20220421 (Red Hat 11.3.1-2) (GCC)

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

1 participant