[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc
Subject:    Performance issues
From:       Andrew Haley <aph () redhat ! com>
Date:       2002-11-29 14:53:17
[Download RAW message or body]

ilya lomov writes:
 > There is following program:
 > 
 > ----------------
 > struct str{
 >    int f0;
 >    int f1;
 >    int f2;
 > };
 > 
 > main () {
 >    double d;
 >    double* pd=&d;
 >    str s;
 >    int* pf=&s.f0;
 >    s.f0=s.f1=s.f2=0;
 >    for (int i=0;i<1000000000;++i) {
 > #ifdef SLOW
 >       pd[s.f0+s.f1*s.f2]=1;
 > #else
 >       pd[pf[0]+pf[1]*pf[2]]=1;
 > #endif
 >    }
 > }
 > -------------------------------------------
 > after compilation with gcc-3.2 -O9 on Linux Mandrake 9.0 Athlon 900MHz,
 > 
 > time ./a.out of the SLOW version gives 10.40s
 > time ./a.out of the "!defined(SLOW)" version gives 3.50s
 > 
 > Logically this is almost the same... Can anyone give me insights what is going on and some advice

Have a look at the assembly code.

The difference is due to the fact that gcc 3.2 unrolls the loop in one
version of the program but not the other.  This doesn't help matters,
and the not-yet-released development gcc doesn't do this.

Andrew.

P.S.  Your program is not legal C; you can't take the address of a
struct member and use it as a pointer to access other fields of the
struct.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic