View previous topic :: View next topic |
Author |
Message |
s3ntient Guru


Joined: 13 Apr 2003 Posts: 304 Location: Lyon, France
|
Posted: Tue May 13, 2003 2:58 am Post subject: CFLAGS determination script |
|
|
Don;t know if this was posted before but here's a script that determines which CFLAGS are compatible with your PC:
Code: |
#!/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"
|
_________________ http://blog.chaostrophy.org |
|
Back to top |
|
 |
genneth Apprentice


Joined: 24 Mar 2003 Posts: 152 Location: UK
|
Posted: Tue May 13, 2003 9:38 am Post subject: -mfpmath=sse,387 |
|
|
On my Celeron(Coppermine) at least, it is greatly beneficial to have -mfpmath=sse,387 instead of just sse.
Great work! |
|
Back to top |
|
 |
lurid Guru


Joined: 12 Mar 2003 Posts: 595 Location: Florida
|
Posted: Tue May 13, 2003 11:56 am Post subject: |
|
|
My Duron reports that I should be using -march=athlon-xp 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. |
|
Back to top |
|
 |
floam Veteran

Joined: 27 Oct 2002 Posts: 1067 Location: Vancouver, WA USA
|
Posted: Tue May 13, 2003 1:22 pm Post subject: |
|
|
why would you use athlon-tbird for a morgan? didn't you know you have an athlon xp with less chache? |
|
Back to top |
|
 |
ixion l33t


Joined: 16 Dec 2002 Posts: 708
|
Posted: Tue May 13, 2003 2:37 pm Post subject: |
|
|
very cool stuff!! nice work! _________________ only the paranoid survive |
|
Back to top |
|
 |
lurid Guru


Joined: 12 Mar 2003 Posts: 595 Location: Florida
|
Posted: Tue May 13, 2003 3:30 pm Post subject: |
|
|
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. 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.
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) |
|
Back to top |
|
 |
piotraf n00b

Joined: 01 Apr 2003 Posts: 43 Location: Łódź - Poland
|
Posted: Tue May 13, 2003 6:32 pm Post subject: Re: -mfpmath=sse,387 |
|
|
genneth wrote: | On my Celeron(Coppermine) at least, it is greatly beneficial to have -mfpmath=sse,387 instead of just sse.
Great work! |
True
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 _________________ best regards/ pozdrawiam
PiotrAF |
|
Back to top |
|
 |
Frozenwings n00b

Joined: 02 Apr 2003 Posts: 47
|
Posted: Wed May 14, 2003 12:14 am Post subject: |
|
|
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... |
|
Back to top |
|
 |
Woody Guru


Joined: 30 Nov 2002 Posts: 592 Location: Milwaukee
|
Posted: Sat May 17, 2003 4:03 am Post subject: But does it matter? |
|
|
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. |
|
Back to top |
|
 |
Gnufsh Guru


Joined: 28 Dec 2002 Posts: 400 Location: Portland, OR
|
Posted: Sun May 18, 2003 10:39 pm Post subject: |
|
|
-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). |
|
Back to top |
|
 |
fdavid Tux's lil' helper


Joined: 27 Apr 2003 Posts: 82 Location: Graz, Austria, EU
|
Posted: Tue May 27, 2003 8:58 pm Post subject: Information source for the classification? |
|
|
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 |
|
Back to top |
|
 |
BradB Apprentice


Joined: 18 Jun 2002 Posts: 190 Location: Christchurch NZ
|
Posted: Tue May 27, 2003 9:43 pm Post subject: |
|
|
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 |
|
Back to top |
|
 |
Ian l33t

Joined: 28 Oct 2002 Posts: 834 Location: Somerville, MA
|
Posted: Wed May 28, 2003 12:05 am Post subject: |
|
|
i get
Code: | -march=athlon-tbird -mmmx -m3dnow |
as output.
does that mean i should have
Code: | CFLAGS="-march=athlon-tbird -mmmx -m3dnow" |
in make.conf?
what about Os/2/3 and -pipe? i have currently
Code: | CFLAGS="-march=athlon -O3 -pipe" |
but that's only because i took a guess :p.
any suggestions more than welcome  |
|
Back to top |
|
 |
lurid Guru


Joined: 12 Mar 2003 Posts: 595 Location: Florida
|
Posted: Wed May 28, 2003 12:54 am Post subject: |
|
|
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
Code: | CFLAGS="-march=athlon-tbird -O2 -pipe -mmmx -m3dnow" |
|
|
Back to top |
|
 |
axses Tux's lil' helper


Joined: 18 Mar 2003 Posts: 110
|
|
Back to top |
|
 |
fdavid Tux's lil' helper


Joined: 27 Apr 2003 Posts: 82 Location: Graz, Austria, EU
|
Posted: Wed May 28, 2003 8:13 am Post subject: |
|
|
I still haven't found what i was looking for. My Celeron is not in the list. Anyone else using this processor? |
|
Back to top |
|
 |
Gnufsh Guru


Joined: 28 Dec 2002 Posts: 400 Location: Portland, OR
|
Posted: Wed May 28, 2003 3:35 pm Post subject: |
|
|
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? |
|
Back to top |
|
 |
robbat2 Developer

Joined: 19 Feb 2003 Posts: 82
|
Posted: Wed May 28, 2003 8:14 pm Post subject: |
|
|
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. |
|
Back to top |
|
 |
Terminal n00b


Joined: 13 Mar 2003 Posts: 21 Location: Melbourne, Australia
|
Posted: Thu May 29, 2003 11:52 am Post subject: |
|
|
Well, the script works, although it is detecting my duron as being -march=athlon instead of being -march=athlon-tbird ... weird. _________________ I'm not lazy, I just take a minimalistic approach to work.
I'm not lazy, I'm just motivationally challenged. |
|
Back to top |
|
 |
fdavid Tux's lil' helper


Joined: 27 Apr 2003 Posts: 82 Location: Graz, Austria, EU
|
Posted: Mon Jun 02, 2003 2:57 pm Post subject: |
|
|
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. |
|
Back to top |
|
 |
LosD n00b


Joined: 12 Jun 2002 Posts: 61 Location: Taastrup, Denmark
|
Posted: Sun Jun 08, 2003 9:07 pm Post subject: |
|
|
fdavid wrote: |
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!
Dennis |
|
Back to top |
|
 |
cromozon n00b


Joined: 22 May 2003 Posts: 59 Location: Denmark - Ishøj
|
Posted: Wed Jun 11, 2003 2:30 pm Post subject: |
|
|
Im going to use this in a script that one day should be able to configure the kernel automatic, it's GREAT
CromoZon |
|
Back to top |
|
 |
BennyP Guru


Joined: 09 May 2003 Posts: 503 Location: Jerusalem, Israel
|
Posted: Tue Jun 17, 2003 8:14 pm Post subject: |
|
|
I have a Pentium 3 (coppermine) 800.
cat /proc/cpuinfo gives me: Code: | 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
Code: | root@stone bennyp # sh cflags.sh
-march=pentium3 -mfpmath=sse -msse -mmmx |
and my current cflags are: Code: | CFLAGS="-march=pentium3 -O3 -pipe"
|
I have a very limited knowledge of what these all mean, so how shall i proceede? _________________ Could it be? |
|
Back to top |
|
 |
pi-cubic Tux's lil' helper


Joined: 25 May 2003 Posts: 143
|
Posted: Tue Jun 17, 2003 9:45 pm Post subject: |
|
|
edit your /etc/make.conf and add the missing parameters...easy, huh?
....thx 4 this very neat script!!!
but one question:
can you use the output also for your CXXFLAGS? |
|
Back to top |
|
 |
xunil n00b


Joined: 18 Jun 2003 Posts: 36 Location: Blacksburg, VA, USA
|
Posted: Wed Jun 18, 2003 4:32 pm Post subject: GCC 3.2 problems w/ P4 and SSE2 |
|
|
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. |
|
Back to top |
|
 |
|