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

            Bug ID: 96804
           Summary: Arguments are swapped in floating-point addition
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chfast at gmail dot com
  Target Milestone: ---

Created attachment 49132
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49132&action=edit
C source code

In the following function, when compiling without optimizations -O0 with GCC
10.2.0 (x86_64-linux-gnu) the arguments to the add instructions are swapped.

float fadd(const float* a, const float* b)
{
    return *a + *b;
}

Assembly snippet:

        movq    %rdi, -8(%rbp)   # a
        movq    %rsi, -16(%rbp)  # b
        movq    -8(%rbp), %rax   # a
        movss   (%rax), %xmm1    # *a
        movq    -16(%rbp), %rax  # b
        movss   (%rax), %xmm0    # *b
        addss   %xmm1, %xmm0     # = *b + *a

This is a problem because when both arguments are NaNs, the result may be
different than the one predicted by IEEE 754.

Reply via email to