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.)
(In reply to comment #0) > (Notice the extra lines between the call to _sinf and the leave.) -O2 will remove these lines (as well as the lines above _sinf): BTW: Could you check if _sinf returns values in %xmm0 reg?
There is nothing wrong with the extra asm instructions.
This doesn't seems to be an error in gcc. The w64 crt currently does not implement some math functions proper. May somebody can assist to port the assemble coded function for this target.
Sorry for the wrong report, and thanks.