Fortran 300 times faster than C for computing cosine

Keith Bierman - SPD Languages Marketing -- MTS khb at sun.com
Wed May 10 07:50:08 AEST 1989


I'm sorry for the very tardy reply, but I was out of town, my machine (and
office) were moved, and my dog ate my transmittal :>

chuck at trantor.harris-atd.com (Chuck Musciano) writes:
>X-Sun-Spots-Digest: Volume 7, Issue 230, message 1 of 16
>
>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
>

One can do better. Here is some source:

      real x
      x = 10.0
      y = sin(x)+cos(x)
      print*,y
      end

and we compile (f77v1.2)

f77 -O3 -f68881 -S

.... stuff removed

|#PROLOGUE# 1
	fmoves	L1D20,fp7
	fsincosx	fp7,fp1:fp0
	faddx	fp1,fp0
	fmoves	fp0,VAR_SEG1+4
	pea	v.16
	jbsr	_s_wsle


since we can compute sin and cos together with a big savings.


Don't forget to use the inline library

	/usr/lib/f77/f68881/libm.il

for your floating point needs.


Cheers.
-- 
Keith H. Bierman          |*My thoughts are my own. Only my work belongs to Sun*
It's Not My Fault         |	Marketing Technical Specialist 
-- I Voted for Bill & Opus|   Languages and Performance Tools. 
(* strange as it may seem, I do more engineering now     *)



More information about the Comp.sys.sun mailing list