[J3] C TS 18661
Bill Long
longb at cray.com
Wed Jan 30 13:03:25 EST 2019
> On Jan 30, 2019, at 11:29 AM, Steven G. Kargl via J3 <j3 at mailman.j3-fortran.org> wrote:
>
> In time harmonic analysis, one often computes exp(cmplx(0.,tau)).
> Many people, including me, do cmplx(cos(tau),sin(tau)). Thus,
> cos() and sin() are computed in pairs, and the argument reduction
> for large arguments (tau > pi/4) is performed twice. With
> sincos() argument reduction is done once and the number of function
> calls is cut in half. As I happen to be the person who wrote the
> sincos() implementation that appears in FreeBSD's libm, I have timing
> codes
Compilers can see that sin(x) and cos(x) with the same value of x are both computed, and replace it with an internal sincos(x) call that does exactly what you describe. This problem was solved long ago.
Fro this example:
subroutine sub (x, z)
real(8),intent(in) :: x
complex(8),intent(out) :: z
z = cmplx(cos(x), sin(x), 8)
end subroutine sub
the internal dump of the compiled code is (Cray compiler, default options) is
1. subroutine sub( x, z )
5. 0[loc( z ),0].L = coss( 0[loc( x ),0].L )
7. return
where coss is the internal name for what you call sincos.
I assume other compilers do this obvious optimization as well.
Cheers,
Bill
Bill Long longb at cray.com
Principal Engineer, Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9143
Cray Inc./ 2131 Lindau Lane/ Suite 1000/ Bloomington, MN 55425
More information about the J3
mailing list