# CFLAGS determination script

## s3ntient

Don;t know if this was posted before but here's a script that determines which CFLAGS are compatible with your PC:

```

#!/bin/sh

# Author: pixelbeat

#This script is Linux specific

#It should work on any gcc >= 2.95 at least

#these apply to any arch (just here for reference)

unsafe_math_opts="-ffast-math -fno-math-errno -funsafe-math-optimizations -fno-trapping-math"

gcc_version=`gcc -dumpversion | sed 's/\([0-9]\{1,\}\.[0-9]\{1,\}\)\.*\([0-9]\{1,\}\)\{0,1\}/\1\2/'`

IFS=":"

while read name value; do

    unset IFS

    name=`echo $name`

    value=`echo $value`

    IFS=":"

    if [ "$name" == "vendor_id" ]; then

        vendor_id="$value"

    elif [ "$name" == "cpu family" ]; then

        cpu_family="$value"

    elif [ "$name" == "model" ]; then

        cpu_model="$value"

    elif [ "$name" == "flags" ]; then

        flags="$value"

    fi

done < /proc/cpuinfo

unset IFS

if [ "$vendor_id" == "AuthenticAMD" ]; then

    if [ "$cpu_family" == "4" ]; then

        _CFLAGS="$_CFLAGS -march=i486"

    elif [ "$cpu_family" == "5" ]; then

        if [ "$cpu_model" -lt "4" ]; then

            _CFLAGS="$_CFLAGS -march=pentium"

        elif [ "$cpu_model" == "6" ] || [ "$cpu_model" == "7" ]; then

            _CFLAGS="$_CFLAGS -march=k6"

        elif [ "$cpu_model" == "8" ] || [ "$cpu_model" == "12" ]; then

            if expr $gcc_version '>=' 3.1 >/dev/null; then

                _CFLAGS="$_CFLAGS -march=k6-2"

            else

                _CFLAGS="$_CFLAGS -march=k6"

            fi

        elif [ "$cpu_model" == "9" ] || [ "$cpu_model" == "13" ]; then

            if expr $gcc_version '>=' 3.1 >/dev/null; then

                _CFLAGS="$_CFLAGS -march=k6-3"

            else

                _CFLAGS="$_CFLAGS -march=k6"

            fi

        fi

    elif [ "$cpu_family" == "6" ]; then

        if [ "$cpu_model" -le "3" ]; then

            if expr $gcc_version '>=' 3.0 >/dev/null; then

                _CFLAGS="$_CFLAGS -march=athlon"

            else

                _CFLAGS="$_CFLAGS -march=k6"

            fi

        elif [ "$cpu_model" == "4" ]; then

            if expr $gcc_version '>=' 3.1 >/dev/null; then

                _CFLAGS="$_CFLAGS -march=athlon-tbird"

            elif expr $gcc_version '>=' 3.0 >/dev/null; then

                _CFLAGS="$_CFLAGS -march=athlon"

            else

                _CFLAGS="$_CFLAGS -march=k6"

            fi

        elif [ "$cpu_model" -ge "6" ]; then #athlon-{4,xp,mp}

            if expr $gcc_version '>=' 3.1 >/dev/null; then

                _CFLAGS="$_CFLAGS -march=athlon-xp"

            elif expr $gcc_version '>=' 3.0 >/dev/null; then

                _CFLAGS="$_CFLAGS -march=athlon"

            else

                _CFLAGS="$_CFLAGS -march=k6"

            fi

        fi

    fi

else #everything else "GenuineIntel"

    if [ "$cpu_family" == "3" ]; then

        _CFLAGS="$_CFLAGS -march=i386"

    elif [ "$cpu_family" == "4" ]; then

        _CFLAGS="$_CFLAGS -march=i486"

    elif [ "$cpu_family" == "5" ] && expr $gcc_version '<' 3.1 >/dev/null; then

        _CFLAGS="$_CFLAGS -march=pentium"

    elif [ "$cpu_family" -ge "6" ] && expr $gcc_version '<' 3.1 >/dev/null; then

        _CFLAGS="$_CFLAGS -march=pentiumpro"

    elif [ "$cpu_family" == "5" ]; then

        if [ "$cpu_model" != "4" ]; then

            _CFLAGS="$_CFLAGS -march=pentium"

        else

            _CFLAGS="$_CFLAGS -march=pentium-mmx" #No overlap with other vendors

        fi

    elif [ "$cpu_family" == "6" ]; then

        if echo "$flags" | grep -vq cmov; then #gcc incorrectly assumes i686 always has cmov

            _CFLAGS="$_CFLAGS -march=pentium -mcpu=pentiumpro" #VIA CPUs exhibit this

        else

            if [ "$cpu_model" == "0" ] || [ "$cpu_model" == "1" ]; then

                _CFLAGS="$_CFLAGS -march=pentiumpro"

            elif [ "$cpu_model" -ge "3" ] && [ "$cpu_model" -le "6" ]; then #4=TM5600 at least 

                _CFLAGS="$_CFLAGS -march=pentium2"

            elif [ "$cpu_model" -ge "7" ] && [ "$cpu_model" -le "11" ]; then #9 invalid

                _CFLAGS="$_CFLAGS -march=pentium3"

            fi

        fi

    elif [ "$cpu_family" == "15" ]; then

        _CFLAGS="$_CFLAGS -march=pentium4"

    fi

fi

if expr $gcc_version '>=' 3.1 >/dev/null; then

    if echo "$flags" | grep -q sse2; then

        _CFLAGS="$_CFLAGS -mfpmath=sse -msse2"

    elif echo "$flags" | grep -q sse; then

        _CFLAGS="$_CFLAGS -mfpmath=sse -msse"

    fi

    if echo "$flags" | grep -q mmx; then

        _CFLAGS="$_CFLAGS -mmmx"

    fi

    if echo "$flags" | grep -q 3dnow; then

        _CFLAGS="$_CFLAGS -m3dnow"

    fi

fi

echo "$_CFLAGS"

```

----------

## genneth

On my Celeron(Coppermine) at least, it is greatly beneficial to have -mfpmath=sse,387 instead of just sse.

Great work!

----------

## lurid

My Duron reports that I should be using -march=athlon-xp    :Shocked:   I know it has the Morgan core, but I thought that ment it was basically just a tbird with less cache. Right now I'm using -march=athlon-tbird.

----------

## floam

why would you use athlon-tbird for a morgan? didn't you know you have an athlon xp with less chache?

----------

## ixion

very cool stuff!! nice work! :Very Happy: 

----------

## lurid

 *floam wrote:*   

> why would you use athlon-tbird for a morgan? didn't you know you have an athlon xp with less chache?

 

Uh..

 *lurid wrote:*   

> I thought that ment it was basically just a tbird with less cache.

 

I guess not.    :Embarassed:   I thought Durons were Athlons and Duron Morgans were Tbirds.  Maybe I need to do some reading over at AMD and get this all straightened out in my head.    :Wink: 

EDIT:

 *Quote:*   

> Some may be wondering, if the Palomino is also know as the AthlonMP, AMD's multiprocessor certified CPU, and the Morgan core is the Duron equivilent of a Palomino core on an Athlon, is this the DuronMP? The answer here is yes and no -- these Durons are not the "MP certified" DuronMPs, but they have all the features and specifications of ones, simply without the name and testing AMD does on its MP CPUs

 

In the immortal words of Cartman:  Kick ass!

(sorry for hyjacking the thread)

----------

## piotraf

 *genneth wrote:*   

> On my Celeron(Coppermine) at least, it is greatly beneficial to have -mfpmath=sse,387 instead of just sse.
> 
> Great work!

 

True  :Smile: 

Did the script show -mfpmath=sse,387 or -mfpmath=sse? Until now I used 

-mfpmath=sse,387 but the script shows -mfpmath=sse and so I'm not sure if I should live it or not

----------

## Frozenwings

Hey, nice stuff! This is gonna come in handy when I change my

computer, as I'll need to change the CFLAGS too.

This has inspired me to write a CFLAGS selector using bash and Xdialog...

----------

## Woody

Its not clear to me (the gcc manpage is a little terse) that

a good deal of these options aren't taken care of by specifying

--march. 

BTW, the script reports athlon-xp on my dual athlon-mp's

I wonder if there is much difference, but...

Could someon who really understands this stuff explain?

ta.

----------

## Gnufsh

-march=athlon-xp -mfpmath=sse -msse -mmmx -m3dnow

is what I get. Here is my /proc/cpuinfo:

processor       : 0

vendor_id       : AuthenticAMD

cpu family      : 6

model           : 8

model name      : mobile AMD Athlon(tm) XP 1800+ 

stepping        : 0

cpu MHz         : 1499.962

cache size      : 256 KB

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 1

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr sse syscall mmxext 3dnowext 3dnow

bogomips        : 2981.88

------

-msse -mmmx and -m3dnow are redundant because of -march=athlon-xp. And, the athlon's on board 387 floating point co-processor is better then the pentiums, and most FP math is faster using it, so -mfpmath=sse actually causes a performance hit (I tested this with several benchmarks).

----------

## fdavid

First of all, thanks for the nice script. I was always hasitating which flags to choose for my Celeron Tualatin. I have used simply i686 so far (family 6, model 11, stepping 1). The script though gave me a bit different result: -march=pentium3 -mfpmath=sse -msse -mmm

I've tried to find some info on the internet, but I haven't found the classification of my processor even on Intel's website. AFAIK it should be some p3. The best info what i could find is http://www.paradicesoftware.com/specs/cpuid/index.htm . But it also doesn't help me a lot.

I would be curious of the information source, on which this script is based. (It would be also interesting for the kernel configuration, where I use a secure avarege option, as well.)

Thanks,

fdavid

----------

## BradB

Does anybody know if Gentoo has an index of CPU : CFLAGS that give the best performance?  I know there have been many CFLAGS threads, but a webpage (or auto configure with this script at install) would help make the FLAGS choice easier.  

Brad

----------

## Ian

i get

```
-march=athlon-tbird -mmmx -m3dnow
```

as output.

does that mean i should have 

```
CFLAGS="-march=athlon-tbird -mmmx -m3dnow"
```

in make.conf?

what about Os/2/3 and -pipe?  i have currently

```
CFLAGS="-march=athlon -O3 -pipe"
```

but that's only because i took a guess :p.

any suggestions more than welcome  :Smile: 

----------

## lurid

The optimizations are basically your choice, so the script wouldn't deal with that.  O2 seems to be standard, though I've heard good things about Os as well.  Based on your output I'd do something like

```
CFLAGS="-march=athlon-tbird -O2 -pipe -mmmx -m3dnow"
```

----------

## axses

Have a look here for advanced cflags etc.  

http://www.freehackers.org/gentoo/gccflags/flag_gcc3opt.html

Happy gentoo-ing  :Smile: 

thx for the script

----------

## fdavid

 *Quote:*   

> Have a look here for advanced cflags etc. 
> 
> http://www.freehackers.org/gentoo/gccflags/flag_gcc3opt.html

 

I still haven't found what i was looking for. My Celeron is not in the list. Anyone else using this processor?

----------

## Gnufsh

A  Celeron (Coppermine, Tualatin) is a p3 with less cache on a slower bus. I think the Tualatin Cellys even have 256k L2 cache. -march=pentium3 is probably the best. As for the rest, maybe -O2 -pipe -fprefetch-loop-arrays -mfpmath=sse,387?

----------

## robbat2

I posted an annouce of this elsewhere before, but here it is again:

http://gentoo.slinky.surrey.sfu.ca/cflagcollect/

This is a gentoo mini-project to write a correct version of the script posted here, if everybody would please submit their cpuinfo data, it would help greatly.

----------

## Terminal

Well, the script works, although it is detecting my duron as being -march=athlon instead of being -march=athlon-tbird ... weird.

----------

## fdavid

 *Gnufsh wrote:*   

> A  Celeron (Coppermine, Tualatin) is a p3 with less cache on a slower bus. I think the Tualatin Cellys even have 256k L2 cache. -march=pentium3 is probably the best. As for the rest, maybe -O2 -pipe -fprefetch-loop-arrays -mfpmath=sse,387?

 

Thanks, pentium3 was my other tip beside i686, but i wasn't sure, although i knew it's somehow a p3. I didn't know exactly how the p3 differs. Does it mean that a p3, a coppermine, and a tualatin are the same excluding the bus frequency and cache? It would be important, because p3 or coppermine is often mentioned at selections (i.g. kernel config), but tualatin.

----------

## LosD

 *fdavid wrote:*   

>  *Quote:*   Have a look here for advanced cflags etc. 
> 
> http://www.freehackers.org/gentoo/gccflags/flag_gcc3opt.html 
> 
> I still haven't found what i was looking for. My Celeron is not in the list. Anyone else using this processor?

 

They have a link for "safe flags" on the page, many more processors there, including some Celerons...

Happy optimizing!  :Smile: 

Dennis

----------

## cromozon

Im going to use this in a script that one day should be able to configure the kernel automatic, it's GREAT   :Very Happy: 

CromoZon

----------

## BennyP

I have a Pentium 3 (coppermine) 800.

cat /proc/cpuinfo gives me: 

```
bennyp@stone bennyp $ cat /proc/cpuinfo 

processor       : 0

vendor_id       : GenuineIntel

cpu family      : 6

model           : 8

model name      : Pentium III (Coppermine)

stepping        : 6

cpu MHz         : 799.795

cache size      : 256 KB

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 2

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov    

pat pse36 mmx fxsr sse

bogomips        : 1592.52
```

this script gives me

```
root@stone bennyp # sh cflags.sh 

 -march=pentium3 -mfpmath=sse -msse -mmmx
```

and my current cflags are: 

```
CFLAGS="-march=pentium3 -O3 -pipe"

```

I have a very limited knowledge of what these all mean, so how shall i proceede?

----------

## pi-cubic

edit your /etc/make.conf and add the missing parameters...easy, huh?   :Very Happy: 

....thx 4 this very neat script!!!

but one question:

can you use the output also for your CXXFLAGS?

----------

## xunil

GCC 3.2 (the default GCC in Gentoo 1.4) generates bad SSE2 code. You should use -march=pentium3 for Pentium 4s and also omit -msse2 for GCC 3.2 and below, but GCC 3.3 fixes this.

----------

## ollie

 *Terminal wrote:*   

> Well, the script works, although it is detecting my duron as being -march=athlon instead of being -march=athlon-tbird ... weird.

 

a duron is in no way a tbird so why is it wierd?

----------

## bsolar

 *xunil wrote:*   

> GCC 3.2 (the default GCC in Gentoo 1.4) generates bad SSE2 code. You should use -march=pentium3 for Pentium 4s and also omit -msse2 for GCC 3.2 and below, but GCC 3.3 fixes this.

 

gcc-3.2.3 solves the issue too.

----------

## xunil

 *bsolar wrote:*   

>  *xunil wrote:*   GCC 3.2 (the default GCC in Gentoo 1.4) generates bad SSE2 code. You should use -march=pentium3 for Pentium 4s and also omit -msse2 for GCC 3.2 and below, but GCC 3.3 fixes this. 
> 
> gcc-3.2.3 solves the issue too.

 

Oh, then it's time to rebuild.  :Razz:  Still, the script should check for this b/c I've personally had some terrible experiences w/ crashing code using earlier versions of GCC 3.2 when I wasn't aware of this bug.

----------

## Arafaen

 *cromozon wrote:*   

> Im going to use this in a script that one day should be able to configure the kernel automatic, it's GREAT  
> 
> 

 

While I agree that this would be an absolutely fantastic script to have, I really don't think it's possible to make it general enough to work.  In particular, I think it will inevitably lead to chicken-and-egg problems.  If, for example, USB support is not already compiled into the kernel, then from within Linux no user application will be able to detect that the machine actually supports USB.  In essence, there would be a lot of situations where, in order to tell that support for a given type of device is needed in the kernel, that support would already have to be present in the kernel.

-chris

----------

## raid517

How about this for a total n00b...   :Embarassed:   How exactly do you get that script to work? I've seen executable scripts before, but runing those is easy. What do I do? Make a text file or something and paste the script into it? Also can that script be adapted so that it actually creates a unique make.conf file for each users individual systems? I know some guys are working on a Gentoo installer and would probably appreciate this.

Q

----------

## ChadRock!

I had the same thoughts Raid517.  I'm a nube.  How do you make scripts?

Good questions:

1. "What do I do? Make a text file or something and paste the script into it?"

2. "Can that script be adapted so that it actually creates a unique make.conf file for each users individual systems?"

----------

## s3ntient

Basically past it all into a file called say cflag_script , put that file into /usr/bin then do 

chmod +x /usr/bin/cflag_script

then you can just type cflag_script in a console and i'll execute giving you the output of the script.

----------

## gandalf2041

I've followed the instructions in this thread to get the script up and running; however, I get either:

RAND bin # ./cflags_script

:bad interpreter: No such file or directory OR

RAND bin #bash cflags_script

:command not found 2:

:command not found 4:

:command not found 7:

:command not found 10:

:command not found 12:

cflags_script: line 21: syntax error near unexpected token 'elif'

'flags_script: line 21: '    elif [ "$name" == "cpu family" ]; then

this is a BRAND new Gentoo 1.4 install on a Wintel P4 1.8 GHz (I haven't even installed X).  Any help would be greatly appreciated.

----------

## maxilion

 *gandalf2041 wrote:*   

> I've followed the instructions in this thread to get the script up and running; however, I get either:
> 
> RAND bin # ./cflags_script
> 
> :bad interpreter: No such file or directory OR
> ...

 

Edit the script and make sure you haven't got any spaces before the commands. By example copy & pasting from konqueror inserts one space in the beginnen of every line. This has to be deleted for the script to work.

Maxillion

----------

## gandalf2041

That did it.  Looks like I had an extra return at the end.  Thanks! 

BTW: Output --->  -march=pentium4 -mfpmath=sse -msse2 -mmmx  :Very Happy: 

----------

## ChadRock!

Thanks for the patience people.  I took a Redhat Linux course and learned some basics, like chmod and scipts, so I know how to make scripts now.

The class did not go into compiling yet, so I'm afraid Gentoo is a little over my head still.

I compiled Gentoo ok following the ix86 install instructions and got a bootable system.  The problem is, I understood what was going on up until compiling the kernel.  That was the point at which the instructions lose beginners like me.

It did not specify exactly what to do step by step, so I could understand, and thus I was lost from that point on.  I was not sure what to pick in the kernel.  Also, I was not sure that if I chose some options, whether or not the defaults apply along with what you change or if they don't apply at all if I make any changes.

I was following along fine until that point.  My system booted up but I did not have basic apps and commands working.  Maybe it was a pathing problem.  I did not know if I had all of the packages I wanted or needed.  I did not know what to chose from.  I guess that's the way it is huh?  It seems like the instructions were step by step dummy proof up until the kernel compile.

I just don't seem to be geek enough to figure it out like you guys do yet.  But hopefully in a year or two I will be.

----------

## rinnan

Cut-n-paste it into Kate, from Konqueror, which works but will preserve the HTML encoding as control characters.  To eliminate them, so that the script can be run, follow these instructions.  

First, choose "Select All" from the "Edit" menu in Kate.  Then, select "Clean Indentation" from Kate's "Tool" menu.  This eliminates the starting blank character on each line.  Next we have to change the indents to something that doesn't confuse /bin/sh.  On line #15 of the script is "unset IFS", if you cut-n-pasted it exactly from the first text line.  It's the middle line in the following list of lines:

 *Quote:*   

> IFS=":"
> 
> while read name value; do
> 
>     unset IFS
> ...

 

Carefully select the whitespace between the beginning of the line and the first character, the "u" on the line.  Don't select the "u" however, but be sure to get every blank character including the first one.  

Then choose the "Replace Text" from Kate's "Edit" pull-down menu.

The text you want to replace is the indentation itself.  It is already entered and highlighted for you, in the "Text to Find" box, so you don't need to do anything else there.  Click in the "Replacement Text" box and type four spaces.  Then, select the "Ok" button, which will do the work.  If you did exactly what I did you will get the message box, "224 replacements made".

Save it (as "cflags.sh" for example), then, in the shell, execute the following command to run it:

 *Quote:*   

> bash-2.05b$ . cflags.sh
> 
>  -march=pentium3 -mfpmath=sse -msse -mmmx
> 
> bash-2.05b$
> ...

 

Don't forget the little period and space before the "cflags.sh".  That will cause bash to execute a script without it having to be executable.

Alternatively you can make it executable such that it executes exactly like any other Linux script -- type this:

 *Quote:*   

> bash-2.05b$ chmod +x cflags.sh
> 
> bash-2.05b$
> 
> 

 

My machine is a Nehemiah M10000 from Via.  The /cpu/proc is:

 *Quote:*   

> 
> 
> bash-2.05b$ cat /proc/cpuinfo
> 
> processor       : 0
> ...

 

Erik

----------

## fastus eddius

(hope i got all the relevant keywords in there other than epia)

i successfully completed a stage3 install of gentoo 1.4. emerge -u world worked without a hitch and the system seems stable. audio and X work thanks to various members in this forum.

related cpu/compiler settings are as follows:

gcc version 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r1, propolice)

CHOST="i686-pc-linux-gnu"

CFLAGS="-march=pentium3 -mfpmath=sse -msse -mmmx -O3 -pipe -fomit-frame-pointer

-fprefetch-loop-arrays -fforce-addr -falign-functions=4"

Eden C3-2/Nehemiah (Via M10000)

$ cat /proc/cpuinfo

processor       : 0

vendor_id       : CentaurHauls

cpu family      : 6

model           : 9

model name      : VIA Nehemiah

stepping        : 1

cpu MHz         : 999.550

cache size      : 64 KB

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 1

wp              : yes

flags           : fpu de tsc msr mtrr pge cmov mmx fxsr sse

bogomips        : 1992.29

fwiw, the cflags script gave the following output for this cpu - i just added the rest to see if i could get away with it:

-march=pentium3 -mfpmath=sse -msse -mmmx

----------

## regeya

 *fastus eddius wrote:*   

> (hope i got all the relevant keywords in there other than epia)
> 
> i successfully completed a stage3 install of gentoo 1.4. emerge -u world worked without a hitch and the system seems stable. audio and X work thanks to various members in this forum.
> 
> related cpu/compiler settings are as follows:
> ...

 

I've got an Ezra, which doesn't have the same featureset.  The advice I got was to use flags much as one would for a K6-3.  If I ever have to emerge -e world, I'm changing one thing: -O3 to -Os.  Like your processor, mine has 64kb of cache.

```

bash-2.05b$ cat /proc/cpuinfo

processor       : 0

vendor_id       : CentaurHauls

cpu family      : 6

model           : 8

model name      : VIA C3 Ezra

stepping        : 9

cpu MHz         : 1003.866

cache size      : 64 KB

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 1

wp              : yes

flags           : fpu de tsc msr cx8 mtrr pge mmx 3dnow

bogomips        : 1966.08

```

----------

## Autie

i get errors after is set my echo from that script in my make.conf.

```

pentium4 -mfpmath=sse -msse2 -mmmx

```

That was my output from that script, so i set my CFLAG to:

```

CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer -mfpmath=sse -msse2 -mmmx"

```

So, i emerge -e world, and all go well, until i emerge libvorbis.

there i get errors, which i don't have with CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"

Any ideas why i get errors?

----------

## Autie

i get errors after is set my echo from that script in my make.conf.

```

pentium4 -mfpmath=sse -msse2 -mmmx

```

That was my output from that script, so i set my CFLAG to:

```

CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer -mfpmath=sse -msse2 -mmmx"

```

So, i emerge -e world, and all go well, until i emerge libvorbis.

there i get errors, which i don't have with CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"

Any ideas why i get errors?

----------

## Autie

i get errors after is set my echo from that script in my make.conf.

```

pentium4 -mfpmath=sse -msse2 -mmmx

```

That was my output from that script, so i set my CFLAG to:

```

CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer -mfpmath=sse -msse2 -mmmx"

```

So, i emerge -e world, and all go well, until i emerge libvorbis.

there i get errors, which i don't have with CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"

Any ideas why i get errors?

----------

## RikBlankestijn

If I've done emerge -e world with these new flags and everything has been successfully compiled does mean your system will be ok? Or are there other things to think of?

----------

## j11888

am i the only one who nano will indent (untill it gets off teh screen) everything thats copyed into it from gnome-terminal? 

anyways, i ran it on a celderon copermine and got:

-march=pentium3 -mfpmath=sse -msse -mmmx

im gonna use "-march=pentium3 -mfpmath=sse,387 -msse -mmmx -O3 -pipe -fomit-frame-pointer" unless anyone can think of a reason not to

being 2 lazy to recompile everything, ill just use the "emerge -Uu -v --oneshot `qpkg -I -nc`" from another topic and wind up recompiling everything sooner or later.

 *Quote:*   

> 
> 
> Thanks for the patience people. I took a Redhat Linux course and learned some basics, like chmod and scipts, so I know how to make scripts now.
> 
> The class did not go into compiling yet, so I'm afraid Gentoo is a little over my head still.
> ...

 

Tip: dont learn from classes, theres a world of books and howtos more useful then any teacher i no of

to install the kernel just choose wat source u want (gentoo-sources may b best if u dont no teh differances) and then emerge genkernel. 

the thing thats confusing me bout ur post is that u couldn't compile the kernel cuz u couldn't figure out how from the instruction, yet u could still boot it>? also, wat do u mean when u say that basic apps and commands dont work? u got to emerge stuff like gnome b4 u use it (this aint redhat w/ the rpm  :Wink:  )

BTW: Zyklon, thx for the great script

----------

## fincoop

I edited make.conf, and then emerged a new package (portage), and it didn't use the new settings. I copy/pasted the CFLAGS line from make.conf into my shell and then emerged another package and it worked. Do I need to have the CFLAGS variable loaded into memory for them to apply?

----------

## bravecobra

 *xunil wrote:*   

> GCC 3.2 (the default GCC in Gentoo 1.4) generates bad SSE2 code. You should use -march=pentium3 for Pentium 4s and also omit -msse2 for GCC 3.2 and below, but GCC 3.3 fixes this.

 

The script generates this:

```
-march=pentium4 -mfpmath=sse -msse2 -mmmx
```

Here is my /proc/cpuinfo

```
bash-2.05b$ cat /proc/cpuinfo

processor       : 0

vendor_id       : GenuineIntel

cpu family      : 15

model           : 2

model name      : Intel(R) Pentium(R) 4 CPU 2.40GHz

stepping        : 4

cpu MHz         : 2400.084

cache size      : 512 KB

physical id     : 0

siblings        : 1

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 2

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm

bogomips        : 4734.97

```

----------

## vdboor

Cool script! If this matures, I hope it will be in on the gentoo-install cd by default..  :Wink: 

I was wondering if there is any way to specify what kind of usage one has in mind for their system. Because I have an AMD Athlon XP, I used to compile with -O3. Unfortunately, this takes ages to compile, and programs load slow (execute fast). Because I have a desktop, I want programs to load fast, so I use -Os.

There is one thing though, korganizer (kdepim package) seams to give a problem with -Os, this has been reported at bugs.kde.org as well.. That's why I use -O2 today: stable and safe.

Conclusion: could there be three options?

"What would you like to optimize your system for:"

- Slow application startup, fast execution (-O3)

- Small binaries (-Os)

- Safe and stable (-O2)

----------

## dalek

I have a Athlon XP 2500+.  Here is what it gave me in case you need to make a adjustment.  Looks akay to me but what do I know??

```
root@smoker /proc # cat /proc/cpuinfo

processor       : 0

vendor_id       : AuthenticAMD

cpu family      : 6

model           : 10

model name      : AMD Athlon(tm) XP 2500+

stepping        : 0

cpu MHz         : 1829.934

cache size      : 512 KB

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 1

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr sse syscall mmxext 3dnowext 3dnow

bogomips        : 3620.86

root@smoker /proc # /home/dale/Desktop/CFLAGS-script

 -march=athlon-xp -mfpmath=sse -msse -mmmx -m3dnow

root@smoker /proc #
```

Oh, make.conf snippets:

```
CFLAGS="-O3 -march=athlon-xp -fmove-all-movables -fprefetch-loop-arrays -funroll-loops -fomit-frame-pointer -ffast-math -pipe"
```

Read that somewhere in the forum.  <shruggs shoulders>  It works.

Later

 :Shocked:   :Very Happy:   :Very Happy:   :Very Happy: 

----------

## moocha

In fact nobody should ever use the -mmmx, -msse etc etc flags. Just set -march and -mcpu (both, in case an ebuild filters -march out, then at leats you'll have -mcpu left) and let the compiler decide on the -m flags. It will usually make a better decision than you. Assuming you have at least GCC 3.3, of course.

-Os is useful for very old processors, without level 2 cache (or with a very small level 2 cache), and for SMP systems. For normal desktop usage it's slower than -O2 or -O3, and in most cases slower than -O1.

Avoid specifying -mfpmath. -mfpmath=sse always produces horrible code. -mfpmath=sse,387 produces marginally better but quite slow code (GCC's floating point optimizer can't yet make good use of a dual set of registers, SSE and the FP ones). Stick with -mfpmath=387, which is the default. In other words, don't fiddle with -mfpmath unless you're running the latest, bleeding edge CVS version of GCC (and if you do that you don't need anyone to tell you what to use  :Very Happy: )

Do NOT use -ffast-math. You're asking for it.

To summarize: Other than -march and -mcpu, stay away from the -m switches unless you know *exactly* what you're doing. Very few packages benefit from messing with them, and the corresponding ebuilds and/or configure scripts take care of them in those cases. You can fiddle with the -m flags, of course, but you'll usually end up with slower running code than if you'd just gone with the defaults.

----------

## vdboor

 *moocha wrote:*   

> In fact nobody should ever use the -mmmx, -msse etc etc flags. Just set -march and -mcpu (both, in case an ebuild filters -march out, then at leats you'll have -mcpu left) and let the compiler decide on the -m flags. It will usually make a better decision than you. Assuming you have at least GCC 3.3, of course.
> 
> -Os is useful for very old processors, without level 2 cache (or with a very small level 2 cache), and for SMP systems. For normal desktop usage it's slower than -O2 or -O3, and in most cases slower than -O1.
> 
> Avoid specifying -mfpmath. -mfpmath=sse always produces horrible code. -mfpmath=sse,387 produces marginally better but quite slow code (GCC's floating point optimizer can't yet make good use of a dual set of registers, SSE and the FP ones). Stick with -mfpmath=387, which is the default. In other words, don't fiddle with -mfpmath unless you're running the latest, bleeding edge CVS version of GCC (and if you do that you don't need anyone to tell you what to use )
> ...

 

Thanks for this useful info  :Smile:  I think this should be at the main page somewhere, because everyone seams to play _a lot_ with their flags.. Also, -fomit-framepointer and such are already used for -O2  :Wink: 

My CFLAGS seam to get cleaner and shorter each month  :Razz: 

----------

## moocha

 *vdboor wrote:*   

> Thanks for this useful info  I think this should be at the main page somewhere, because everyone seams to play _a lot_ with their flags.. Also, -fomit-framepointer and such are already used for -O2 
> 
> My CFLAGS seam to get cleaner and shorter each month 

 

Welcome  :Razz: 

But beware - -O2 implies -fomit-frame-pointer, but only on machines where it wouldn't interfere with debugging. x86 (and x86-64 IIRC) machines do not fall into this category, so for your typical system -O2 doesn't imply -fomit-frame-pointer. This one's a keeper  :Smile: 

----------

## moocha

 *moocha wrote:*   

> Do NOT use -ffast-math. You're asking for it.

 

I goofed badly on this one. I ran tests and it turns out -ffast-math is very good to use when also using optimization (i.e. for any Gentooer  :Very Happy: ).

See my post in this thread for details.

----------

## metalh34d

I get these results:-march=pentium4 -mfpmath=sse -msse2 -mmmx

CPU Info as follows: (note that repeat is from hyperthreading not a second proccessor)

```
$ cat /proc/cpuinfo 

processor       : 0

vendor_id       : GenuineIntel

cpu family      : 15

model           : 2

model name      : Intel(R) Pentium(R) 4 CPU 2.40GHz

stepping        : 9

cpu MHz         : 2406.115

cache size      : 512 KB

physical id     : 0

siblings        : 2

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 2

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid

bogomips        : 4751.36

processor       : 1

vendor_id       : GenuineIntel

cpu family      : 15

model           : 2

model name      : Intel(R) Pentium(R) 4 CPU 2.40GHz

stepping        : 9

cpu MHz         : 2406.115

cache size      : 512 KB

physical id     : 0

siblings        : 2

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 2

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid

bogomips        : 4800.51
```

CFLAGS="-O2 -march=pentium4 -pipe -fomit-frame-pointer -ffast-math -fforce-addr -mfpmath=sse -msse2 -mmmx" is what I currently have setup now after using this script. Anyone constructive criticism by chance? I used to have -Os setup because the word was programs would load much faster but now I'm starting to hear that my P4's cache is so large Os won't matter so much and O2 is the best bang for the buck when comparing loadtime and performance increase between O2 and O3?

----------

## dak1001

fincoop - the portage package, as well as others, do have some hard coded GCC flags as intended by the developers...  you can check this by looking at the associated   "$package-$version.ebuild"   file.  this is likely why some of the things (portage in particular) you emerge'd did not use your CFLAGS from the /etc/make.conf

until the Pentium M processor is incorporated into the mainline GCC, i would say that this is a case where you would indeed want to use a "-m" flag, i.e., the Pentium M has a core much more similar (but not the same as) the Pentium III architecture and yet also takes advantage of SSE2, so:

CFLAGS="-pipe -O2 -march=pentium3 -fomit-frame-pointer -msse2"

could be a suitable setting, and in fact is exactly what i use on my DELL CENTRINO laptop.

earlier, someone made mention of the "-mfpmath=" flag...  from my experience GENTOO'ing now, i have toyed with many different GCC flags and though i did witness some benefit in some apps, by and large, i saw a lot of problems going forward.  that is, they compiled fine and executed perfectly.  but when it came time to "emerge -u" the upgrade would fail.  luckily, i always keep a box around with generic optimizations where i would have to compile the updated package and then use to upgrade my system.  after too many times of messing with this, i now use a much safer combination, which is what i listed above.

but, your mileage will vary, so if you like to dabble and experiment, i suggest you do and find what works best for you. 

Here is the GCC link with explanations on all of the optimizations.

http://gcc.gnu.org/onlinedocs/gcc-3.4.0/gcc/Optimize-Options.html#Optimize%20Options/

----------

## TheCurse

Could anyone give me a link to the script? I can't get it to work per copy and paste...

cu

TheCurse

----------

