Re: best Gcc compilzation flags

Ervin Németh <[email protected]>
Newsgroups gmane.linux.gentoo.performance
Message-ID <[email protected]>
Uwe Thiem wrote:
> -funroll-loops isn't that good an idea because an unrolled loop might the 
> cache.

All this started with Artur Grabowski's mail. And now everybody is 
repeating his idea.

No, loop unrolling is not evil. Neither are inline functions.

The following loop:

do i=1,n
  sum=a(i)
enddo

is unrolled like

do i=1,n,4
  sum0=a(i)
  sum1=a(i+1)
  sum2=a(i+2)
  sum3=a(i+3)
enddo
sum=sum0+sum1+sum2+sum3

Some modulo logic must be added and I also omitted the after-loop cleanup.

The gain is less frequent loop index variable comparison (and so a 
conditional jump), more register usage, less memory operations in more 
complex, nested loops, and a code which allows the scheduler to make 
more aggressive optimization in the code structure. And it also opens 
possibilities to other optimizations.

All this compared to the increased instruction cache usage. And keep in 
mind that every program spends most of its runtime in loops.

This was the theory. Practice shows that the optimizer in gcc was very 
weak before 3.4, and sill depends the efficiency of the scheduler.

But remember: however good all this sounds, there are always programs 
where one or more optimization fails - there is no magic switch for a 
general, best performance.


/Ervin

--
[email protected] mailing list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.