Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
extra GCC optimizations?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
brakits
n00b
n00b


Joined: 13 May 2002
Posts: 10
Location: San Francisco, CA

PostPosted: Mon May 13, 2002 6:13 pm    Post subject: extra GCC optimizations? Reply with quote

I have noticed a few programs adding some extra optimizations on top of the make.conf stuff. I was curious what if any negative effects it would have to keep them on all the time, would it optimize things faster typically?

The flags I am curious about are: -funroll-all-loops -fomit-frame-pointer -ffast-math

also are there any other flags that can optimize binaries to go a bit faster, even at the expense of longer compile times.

thanks
-stephen
Back to top
View user's profile Send private message
proxy
Apprentice
Apprentice


Joined: 20 Apr 2002
Posts: 253
Location: Chantilly, VA

PostPosted: Mon May 13, 2002 6:54 pm    Post subject: Reply with quote

ok lets take a look at these:

-funroll-all-loops: this should always be safe, basically it will take any loop of fixed length and output the code for each iteration, resulting in a potentially much larger (what if the loop ges from 1 to a 1000 or more), but also faster executable as it no longer has jumps/compares for each iteration.

-fomit-frame-pointer: this one is also usually safe, basically it opens up another register for the compiler to use, resulting in faster code as it will need to swap things from RAM <-> registers less often. The downside is that this "frame-pointer" tends to have useful debugging info, so omitting this can result in binaries that are IMPOSIBLE to debug in programs such as gdb, but since you asked what this is, chances are you are not doing any debugging :wink:

-ffast-math: i beleive (could be wrong) that this one allows the libraries to use non-ANSI standard code to perform certain expensive math operations faster. I am not too sure about the safty of this as doing so could possibly break certain pieces of code which rely on standards compliant code.

hope this helps

proxy
Back to top
View user's profile Send private message
Malakin
Veteran
Veteran


Joined: 14 Apr 2002
Posts: 1692
Location: Victoria BC Canada

PostPosted: Tue May 14, 2002 1:12 am    Post subject: Reply with quote

If a program uses it's own cflags/cxxflags they should be safe on that particular program.

I compiled everything after the bootstrap with -ffast-math, didn't have any problems.


Last edited by Malakin on Tue May 14, 2002 5:51 pm; edited 1 time in total
Back to top
View user's profile Send private message
proxy
Apprentice
Apprentice


Joined: 20 Apr 2002
Posts: 253
Location: Chantilly, VA

PostPosted: Tue May 14, 2002 1:29 am    Post subject: Reply with quote

yes, but the question was about the saftey of having them on all the time :P

proxy
Back to top
View user's profile Send private message
Guest






PostPosted: Tue May 14, 2002 9:48 pm    Post subject: Re: extra GCC optimizations? Reply with quote

brakits wrote:

The flags I am curious about are: -funroll-all-loops -fomit-frame-pointer -ffast-math


Well, if those flags would always produce faster/better/sexier/safer code, don't you think -O3 would activate them automatically?

-ffast-math generates faster math code but breaks the IEEE/ISO standard. Some software could break (i.e. software which expects various IEEE/ISO behaviour regarding fp math). My expierience is that it is safe to use most of the time.

-fomit-frame-pointer makes debugging impossible for some architectures.

-fomit-frame-pointer generates faster code for some software and slower code for other. It depends on the specific code. So to decide if you should compile some piece of software with or without those options do some benchmarking.

Regarding -funroll-all-loops I think there are some bug reports for GCC 3.x.y where this option gerenates false code (there was also something on kde-devel not long ago regarding this option).

BTW don't expect a super performance boost with say KDE when enabling some of those options. The gain (if any) is marginal.

Cheers,
Andreas
Back to top
Guest






PostPosted: Tue May 14, 2002 9:55 pm    Post subject: Reply with quote

proxy wrote:

-funroll-all-loops: this should always be safe, basically it will take any loop of fixed length and output the code for each iteration, resulting in a potentially much larger (what if the loop ges from 1 to a 1000 or more), but also faster executable as it no longer has jumps/compares for each iteration.


Modern CPUs have very sofisticated optimizations. If the loop's body could reside completly in the CPU's command cache and iteration variables can be held in registers it should be faster than fetching those 1000 or more bodys from memory. I don't think that this option always produces faster code. Of course I could be wrong ;-)

A.
Back to top
Malakin
Veteran
Veteran


Joined: 14 Apr 2002
Posts: 1692
Location: Victoria BC Canada

PostPosted: Tue May 14, 2002 11:03 pm    Post subject: Reply with quote

Quote:
-fomit-frame-pointer generates faster code for some software and slower code for other. It depends on the specific code.

How could -fomit-frame-pointer ever generate slower code?
Back to top
View user's profile Send private message
proxy
Apprentice
Apprentice


Joined: 20 Apr 2002
Posts: 253
Location: Chantilly, VA

PostPosted: Tue May 14, 2002 11:11 pm    Post subject: Reply with quote

the comment about some cpus runnign fater on unrolled loops because of caches is a VERY good point, this is good reason why this option may not always be a great idea. But like i said, it is always SAFE :P

for smaller loops it will generate faster code, for larger loops it could possibly actually be slightly slower because of cache misses.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum