[Bug c++/92597] New: std::fma gives nan using -march=sandybridge+ with asm volatile

leppkes at stce dot rwth-aachen.de gcc-bugzilla@gcc.gnu.org
Wed Nov 20 14:37:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92597

            Bug ID: 92597
           Summary: std::fma gives nan using -march=sandybridge+ with asm
                    volatile
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: leppkes at stce dot rwth-aachen.de
  Target Milestone: ---

Created attachment 47307
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47307&action=edit
tiny example with makefile to reproduce.

I attached a small example to illustrate my problem.

Short: -O1+ -march=sandybridge+ gives wrong values when using asm volatile
(which is taken from google benchmark).

To reproduce:

$>make
g++ -O1 test.cpp -o gcc.exe
./gcc.exe > gcc.txt
g++ -O1 -march=sandybridge test.cpp -o gcc_march.exe
./gcc_march.exe > gcc_march.txt
diff gcc.txt gcc_march.txt
6,7c6,7
< FMA: 0; TYPE: double; ASM Volatile: 1 => y=0
< FMA: 1; TYPE: long double; ASM Volatile: 1 => y=0
---
> FMA: 0; TYPE: double; ASM Volatile: 1 => y=6.95302e-305
> FMA: 1; TYPE: long double; ASM Volatile: 1 => y=-nan
make: *** [makefile:14: diff_gcc] Error 1

So not using asm volatile gives the correct values.

In the makefile, clang is also possible to test, which seems to work propper
(as well as Intel C++). To check clang, just type
$>make diff_clang 
clang++ -O1 test.cpp -o clang.exe
./clang.exe > clang.txt
clang++ -O1 -march=sandybridge test.cpp -o clang_march.exe
./clang_march.exe > clang_march.txt
diff clang.txt clang_march.txt

Using -O0 gives correct values btw, so it seems inside an optimizer.

Cheers,
Klaus


More information about the Gcc-bugs mailing list