# How to (USUALLY) find the best CFLAGS

## discomfitor

Ever heard of acovea?  It's a program that uses "An Evolutionary Analysis of GNU C Optimizations" to find the best C(XX)FLAGS.  It is mainly designed for gcc 3.4 right now, but it can be changed to work with 3.3 by removing the 3.4 only options from the config files.

Try it out!

----------

## Crimson Rider

That sounds awesome.

I just checked it out and it is supra cool. I love GA, I use it for fun and profit myself.

"When the problem is complex I bring out the GA"

Gotta love that. Wonder how usefull it will be in getting the best flags.

----------

## discomfitor

I've used my results for a while and it does seem to have a large gain in speed.  The only problem is that some things don't compile with them because they're too aggressive.  That's when I go back to my old hand-picked ones.

----------

## Krigare

This is indeed something everyone wanted to know but couldn't find the answer for.

Great Shot Darckness!

----------

## discomfitor

 :Cool: 

Let me know if you have trouble configuring it or something.  I usually gave it about 50 generations and let it go overnight to make sure it got the most accurate results.  Then again, I did it a bunch of times.

----------

## TheEternalVortex

Which are the options that one would need to take out to get this to work with gcc 3.3?

BTW, there is an ebuild for acovea, apparently.

----------

## d99ma

Sounds good, but an initial look gave me the impression that -Os is not considered?

----------

## nephros

quickly hacked-together ebuild, please test:

EDIT: update: there is a fancier ebuild in the older thread too.

```

# Copyright 1999-2004 Gentoo Technologies, Inc.

# Distributed under the terms of the GNU General Public License v2

# $Header: $

DESCRIPTION="ACOVEA implements a genetic algorithm to find the \"best\" options for compiling programs with the GNU Compiler Collection (GCC)."

HOMEPAGE="http://www.coyotegulch.com/acovea/"

SRC_URI="http://www.coyotegulch.com/acovea/${P}.tar.bz2"

LICENSE=""

SLOT="0"

KEYWORDS="~x86"

DEPEND=""

RDEPEND=">=sys-devel/gcc-3.4"

S=${WORKDIR}/${P}

MY_EXAMPLES="/usr/share/acovea"

src_compile() {

   ./build.sh || die

}

src_install() {

   insinto ${MY_EXAMPLES}

   dodir ${INSDESTTREE}

   doins almabench.c fftbench.cpp huffbench.c lpbench.c manbench.c manbench.cpp treebench.c

   exeinto /usr/bin

   doexe gavg gccacovea

   dodoc README LICENSE.SVFL

}

pkg_postinst() {

   einfo ""

   einfo "example benchmark files have been installed to ${MY_EXAMPLES}"

   einfo ""

   ewarn "${P} comes with a special license, called the SVFL."

   ewarn "It has been copied to /usr/share/doc/${PF}/LICENSE.SVFL"

   ewarn "Please read it before using this."

   ewarn ""

}

```

----------

## viperlin

wow this looks nice, maybe it could be used in the automated gentoo install  :Smile: 

----------

## discomfitor

Probably not fit for automated install since you have to spend some time on it for it to be of any real value.  

As for options you need to take out for gcc 3.3, I looked at the config where all the options are listed, then went through the gcc man page and checked for them.  If I didn't see one (or didn't want it tested) I removed it.

Currently my CFLAGS (for the apps that compile with them) are:

```
CFLAGS="-march=pentium4 -O3 -pipe -fPIC -fmove-all-movables -ftracer -fnew-ra -ffinite-math-only -finline-functions -mfpmath=sse -finline-limit=662 -fomit-frame-pointer -momit-leaf-frame-pointer"
```

and CXXFLAGS:

```
CXXFLAGS="-march=pentium4 -O3 -pipe -fPIC -freduce-all-givs -momit-leaf-frame-pointer -mfpmath=sse -finline-limit=625 -finline-functions -ffinite-math-only -fno-trapping-math"
```

I'm on a P4 2.5ghz, and I've been using these flags for several months without stability issues.

----------

## discomfitor

Also, -fnew-ra will cause some compilings to crash.

----------

## TheEternalVortex

Could you post your updated config so as to save me the trouble?

----------

## MighMoS

 *Darckness wrote:*   

> Probably not fit for automated install since you have to spend some time on it for it to be of any real value.  
> 
> As for options you need to take out for gcc 3.3, I looked at the config where all the options are listed, then went through the gcc man page and checked for them.  If I didn't see one (or didn't want it tested) I removed it.
> 
> Currently my CFLAGS (for the apps that compile with them) are:
> ...

 

Why would you put -fPIC in your CFLAGS?  I thought it was just for libraries...

----------

## discomfitor

MighMoS:  There's a couple libs that don't put -fPIC in their flags for some reason, and this fixes that problem.  Doesn't cause any other issues.

TheEternalVortex:  I do not currently have acovea installed, so I can't post my config.  Just look for the options you've never seen before.  They are likely to not be in 3.3.

----------

## masseya

Just wanted to point out the older discussion on this topic that nephros brought to my attention.

finding the best optimization flags via genetic algorithm

----------

## discomfitor

Yeah, I saw that, but it was in the wrong forum, so I decided to get something going here in the hopes that more people would see it.

----------

## Crimson Rider

Hmm, it doesn't seem to have support for Athlon yet.

----------

## Krigare

I'm getting really crazy now, i've tried to figure it out how to use this correctly but i've failed all those times. I'm getting COMPILE FAILED errors all over the place, here is an example of those errors:

```
COMPILE FAILED:

gcc -lrt -std=gnu99 -Dacovea_generic -O1 -o ACOVEA57F61D1D -fno-merge-constants -fno-thread-jumps -fno-omit-frame-pointer -fno-guess-branch-probability -fno-delayed-branch -fno-loop-optimize -fno-crossjumping -foptimize-sibling-calls -fcse-follow-jumps -fgcse -fexpensive-optimizations -fstrength-reduce -frerun-cse-after-loop -frerun-loop-opt -fcaller-saves -fstrict-aliasing -freorder-blocks -falign-loops -falign-jumps -funit-at-a-time -frename-registers -fweb -fmove-all-movables -freduce-all-givs -fpeel-loops -ftracer -funswitch-loops -fbranch-target-load-optimize /usr/share/acovea/almabench.c

cc1: unrecognized option `-fno-if-conversion'

cc1: unrecognized option `-fno-if-conversion2'

cc1: unrecognized option `-fno-crossjumping'

cc1: unrecognized option `-fweb'
```

The command i've used is 

```
# gccacovea -app /usr/share/acovea/almabench
```

My gcc-version

```
*  sys-devel/gcc

      Latest version available: 3.2.3-r3

      Latest version installed: 3.2.3-r3

      Size of downloaded files: 20,716 kB

      Homepage:    http://www.gnu.org/software/gcc/gcc.html

      Description: The GNU Compiler Collection. Includes C/C++ and java compilers
```

However, at the bottom of this, after it shows me the statistics, i get segfault, this occur at the very end of the termination after all the zeroes i got on the statistics (those after "Option counts:"). I'm using an Intel P4 2ghz.

Greatful for every help i can get.

----------

## jkalderash

Anyone know what's up with the website for acovea?  I haven't been able to access it since I found this thread yesterday...

----------

## discomfitor

Krigare: those options are not supported by gcc 3.2, you need to edit the config file to remove them

----------

## Birnenpfluecker

@ Darckness: The link is down, can you please fix it?

----------

## charlieg

 *Krigare wrote:*   

> I'm getting really crazy now, i've tried to figure it out how to use this correctly but i've failed all those times.

 

I think it's aimed at GCC 3.4 / 3.5 so that might be the reason.

----------

## nevynxxx

The website is still down, I get "he requested URL /acovea/ was not found on this server." does anyone know of a mirror of the bz2 so I can grab and install it?

----------

## TenPin

I'd be very interested to know the optimal CFLAGS for compiling mozilla-firebird because I have quite a slow machine and firebird is the only thing that could do to be more snappy.

----------

## jrz

for great justice! someone who has the source file plz put it up or send it to someone who can  host!

 :Cool: 

----------

## mmilhome

Hi,

    The Site of acovea is broken, did someone knows where to get it? Can I emerge acovea? How to browse/know every pacage in portage?

 :Laughing: 

Obrigado

Marcus Renaud Milhomem

----------

## GenKiller

I'm hosting the tarball while the site is down for you guys who haven't gotten it yet:

http://www.digital-drip.com/~jon/downloads/acovea-3.3.0.tar.gz

----------

## Birnenpfluecker

@mmilhome: emerge search is your friend! But it is not in portagee, at least not yet.

----------

## CybeRDukE

@GenKiller: thx a lot for the link!

i've got serious problems using acovea with gcc-3.3.2. 

acovea-3.3 uses flags that are not available in gcc 3.3 but in 3.4. i already modified the gccacovea.cpp file but i still dos not work. can anybody help me? 

afaik version 3.0.0 of acovea should work (even if acovea-3.3's README mentions gcc-3.3 as well) but as long as the page does not work i can't try it. maybe it's still on someone's harddisk and could post a link or send me the file...

thx

----------

## Becks

Also have saved the file here, for those who need it:

http://jeannie.chemie.uni-konstanz.de/~becks/files/acovea-3.3.0.tar.gz

Alex

----------

## seppe

So how do I get this working with gcc 3.3.3? I get always compilation failed messages and a segmentation fault when I should get my best CFLAGS.

----------

## asimon

 *TenPin wrote:*   

> I'd be very interested to know the optimal CFLAGS for compiling mozilla-firebird because I have quite a slow machine and firebird is the only thing that could do to be more snappy.

 

I suppose the time to find this optimal set of optimizations for such a large piece of code like Firebird would take so long that you have to use mozilla at least ten-thousand years to ultimately save some time.   :Wink: 

----------

