Fortran 300 times faster than C for computing cosine
Chuck Musciano
chuck at trantor.harris-atd.com
Wed Apr 19 04:17:57 AEST 1989
Our moderator muses: "Interestingly enough, it [computing a function
involving four calls to cos()] still appears to be quicker [in FORTRAN]
than cosc.c [the C version]".
The answer is that in FORTRAN, cos() is an intrinsic function, and the
compiler uses the direct floating point opcode. In C, cos() is an
external function, and the compiler generates a call to an external named
"cos".
Compare the code generated for "sin(x) + cos(x)" in FORTRAN and C. In
FORTRAN (a5@(-0x7ffc) is x):
fcoss a5@(-0x7ffc),fp0
fsins a5@(-0x7ffc),fp1
faddx fp1,fp0
In C (a6@(-12) and a6@(-16) are x):
movl a6@(-12),sp at -
movl a6@(-16),sp at -
jbsr _sin
addqw #8,sp
movl d0,a6@(-24)
movl d1,a6@(-20)
movl a6@(-12),sp at -
movl a6@(-16),sp at -
jbsr _cos
addqw #8,sp
movl d1,sp at -
movl d0,sp at -
fmoved sp at +,fp0
faddd a6@(-24),fp0
Does anyone know of an optimizer which will convert calls to the standard
math routines to their 68881 instruction counterparts?
Chuck Musciano
Advanced Technology Department
Harris Corporation
(407) 727-6131
ARPA: chuck at trantor.harris-atd.com
More information about the Comp.sys.sun
mailing list