I have had a bug report from people who tested my gfortran binaries for
mingw-w64 that the float variants of math functions aren't working properly.
The proper report that was sent to me has this example:

C:\gfortran\test\single_bug>type table.f90
program table
  real x
  integer i
  write(*,*) '   x     sin(x)    cos(x)   tan(x)'
  do i = 0, 10
     x = i
     write(*,*) x, sin(x), cos(x), tan(x)
  end do
end program table

C:\gfortran\test\single_bug>c:\gfortran\win64\bin\x86_64-pc-mingw32-gfortran
table.f90 -o table

C:\gfortran\test\single_bug>table
   x     sin(x)    cos(x)   tan(x)
  0.000000       0.000000       0.000000       0.000000
  1.000000       1.000000       1.000000       1.000000
  2.000000         2.0000         2.0000         2.0000
  3.000000         3.0000         3.0000         3.0000
  4.000000         4.0000         4.0000         4.0000
  5.000000         5.0000         5.0000         5.0000
  6.000000         6.0000         6.0000         6.0000
  7.000000         7.0000         7.0000         7.0000
  8.000000         8.0000         8.0000         8.0000
  9.000000         9.0000         9.0000         9.0000
  10.00000        10.0000        10.0000        10.0000


Indeed, there is a difference between a C function that calls sinf():

#include <math.h>
float foo(float *x) { return sinf(*x); }

which is compiled into:

_foo:
LFB47:
        pushq   %rbp
LCFI0:
        movq    %rsp, %rbp
LCFI1:
        subq    $32, %rsp
LCFI2:
        movq    %rcx, 16(%rbp)
        movq    16(%rbp), %rax
        movss   (%rax), %xmm0
        call    _sinf
        leave
        ret

and the equivalent Fortran function:

  real function foo(x)
    real x
    foo = sin(x)
  end function foo

that is compiled into:


_foo_:
LFB2:
        pushq   %rbp
LCFI0:
        movq    %rsp, %rbp
LCFI1:
        subq    $64, %rsp
LCFI2:
        movq    %rcx, 16(%rbp)
        movq    16(%rbp), %rax
        movss   (%rax), %xmm0
        call    _sinf
        movss   %xmm0, -4(%rbp)
        movl    -4(%rbp), %eax
        movl    %eax, -20(%rbp)
        movss   -20(%rbp), %xmm0
        leave
        ret

(Notice the extra lines between the call to _sinf and the leave.)


-- 
           Summary: Wrong code for single precision math functions on
                    x86_64-pc-mingw32
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fxcoudert at gcc dot gnu dot org
 GCC build triplet: i386-pc-mingw32
  GCC host triplet: i386-pc-mingw32
GCC target triplet: x86_64-pc-mingw32


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33561

Reply via email to