From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <328f1c805a4d229909229d0280ffa225.axp-list@archive.invalid> X-Archive-Original-Message-ID: <199701272215.RAA01003@rrdjazz.nist.gov> Date: Mon, 27 Jan 1997 17:15:38 -0500 From: Przemek Klosowski Subject: Re: compiler efficency Claus wrote: for (i = 2; i <= i__1; ++i) { gam += 1. / (doublereal) i; } Now, the Fortran-program compiled with the Digital Unix (f77) compiler executes TWICE as fast as the gcc executable (I found this factor also in other I took a look at machine code from gcc and DEC cc. I had a good laugh when GCC optimized away the loop entirely with -O2 (initially I didn't use the computed value of gam). Here is a test case: typedef double doublereal; double x () { int i, i__1 = 9999; double gam = 0; for (i = 2; i <= i__1; ++i) { gam += 1. / (doublereal) i; } return gam; } and here is DEC cc -O2 code and GCC -O2 code # 5 double gam = 0; cpys $f31,$f31,$f0 cpys $f31, $f31, $f1 bis $31,2,$2 .loc 2 6 ldt $f10,0($1) # 6 for (i = 2; i <= i__1; ++i) { .align 5 ldil $16, 2 $43: ldit $f0, 1. stq $2,0($30) .align 3 ldt $f11,0($30) $32: cvtqt $f11,$f1 .loc 2 6 divt $f10,$f1,$f1 addl $2,1,$2 .loc 2 7 cmple $2,$3,$1 # 7 gam += 1. / (doublereal) i; addt $f0,$f1,$f0 stq $16, 0($sp) bne $1,$43 ldt $f10, 0($sp) addq $30,16,$30 cvtqt $f10, $f11 ret $31,($26),1 divt $f0, $f11, $f12 .end x addt $f1, $f12, $f1 addl $16, 1, $16 cmplt $0, $16, $1 beq $1, $32 # 8 } cpys $f1, $f1, $f0 lda $sp, 16($sp) ret $31, ($26), 1 .end x As you can see, not much difference, except that DEC cc probably does better scheduling so that 21164 can multiple-issue, but still, a 2x difference is more than I expected. I would guess that most of the difference comes from naive translation by f2c, in which case g77 should do better. Also, are you sure you compiled with optimizations turned on? przemek klosowski (301) 975-6249 Reactor Division (bldg. 235), E111 National Institute of Standards and Technology Gaithersburg, MD 20899, USA -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com