Fortran 300 times faster than C for computing cosine

Ian Phillipps igp at cambridge-consultants.co.uk
Thu May 11 13:02:32 AEST 1989


chuck at trantor.harris-atd.com (Chuck Musciano) writes:

>Compare the code generated for "sin(x) + cos(x)" in FORTRAN and C.  In
>FORTRAN (a5@(-0x7ffc) is x):

[ 3 x 68881 instructions ]

>In C (a6@(-12) and a6@(-16) are x):

[ 13 x 68020 + 1 x 68881 instructions]

>Does anyone know of an optimizer which will convert calls to the standard
>math routines to their 68881 instruction counterparts?

Sun provide one! (/usr/lib/inline)

Using
	cc -S -O -f68881 trig.c /usr/lib/f68881.il

We get:

	movl    a6@(12),sp at -	; x
	movl    a6@(8),sp at -
	fcosd   sp@,fp0
	fmoved  fp0,sp@
	movl    sp at +,a6@(-8)
	movl    sp at +,a6@(-4)
	movl    a6@(12),sp at -
	movl    a6@(8),sp at -
	fsind   sp@,fp0
	fmoved  fp0,sp@
	movl    sp at +,d0
	movl    sp@,d1
	movl    d0,sp at -
	fmoved  sp at +,fp0
	faddd   a6@(-8),fp0
	fmoved  fp0,a6@(16)	; assign result

Not very optimised, but at least it does fcosd!
[Note - C gives you DCOS by default]
-- 
UUCP:  igp at camcon.co.uk   | Cambridge Consultants Ltd  |  Ian Phillipps
or:    igp at camcon.uucp    | Science Park, Milton Road  |-----------------
Phone: +44 223 420024     | Cambridge CB4 4DW, England |



More information about the Comp.sys.sun mailing list