Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Przemek Klosowski <przemek@rrdjazz.nist.gov>
Subject: Re: compiler efficency
Date: Mon, 27 Jan 1997 17:15:38 -0500	[thread overview]
Message-ID: <328f1c805a4d229909229d0280ffa225.axp-list@archive.invalid> (raw)

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 <przemek@nist.gov>  (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

             reply	other threads:[~1997-01-27 22:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-27 22:15 Przemek Klosowski [this message]
     [not found] <9701282002.AA15294@moene.indiv.nluug.nl>
1997-01-29  0:10 ` compiler efficency Michal Jaegermann
  -- strict thread matches above, loose matches on Subject: below --
1997-01-28 23:23 Huw Davies
1997-01-28 20:02 Toon Moene
1997-01-28 11:22 Claus Denk
1997-01-27 22:41 Craig Burley
1997-01-27 21:48 Toon Moene
1997-01-27 20:51 Robert Williams
1997-01-27 20:37 Claus Denk
1997-01-27 20:35 ` Brett McCormick
1997-01-27 20:37 ` Lev D Gelb
1997-01-27 21:15 ` Jim Nance
1997-01-27 22:13 ` Scott Locklin
1997-01-27 22:41 ` Michal Jaegermann
1997-01-27 23:35 ` Richard Henderson
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox